octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: more import tests


From: Rik
Subject: Re: more import tests
Date: Mon, 14 Aug 2017 23:27:43 -0700

On 08/10/2017 01:29 PM, John W. Eaton wrote:
> Thanks for running the tests.
>
> Some things I noticed:
>
> ** The test of a user-defined import function shows that it is only
> executed if it is called with the function-style syntax, but not if
> called with command-style syntax.  For command-style syntax, it appears
> that the user-defined import function is ignored.  Does that happen for
> ANY other function name in Matlab?

My guess is that this is unique to import.  I think what Matlab may do is
check at parse time whether the function or command-style syntax is being
used.  If it is command-style, then the parser knows that whatever follows
should be interpreted as a static string.  Since the string is static it
can be substituted at parse time into the code.  However, if the function
syntax is used then what follows could be a variable and the value of that
can only be known at evaluation time.  There would be even one more slight
optimization which would be to have the parser try and check for static
strings ('...') even when the function syntax was used.  If strings were
detected it could still substitute the values at parse-time.

Although Matlab says that the syntax "import pkg.*" is deprecated because
it could pull too many symbols into the current namespace, another reason
might be that this sort of expression could be too difficult to handle at
parse time.  It looks like a static string, but it really isn't.

>
> ** If the command-style syntax is used, then it appears to affect all
> function calls, as Rik noted.  So when a command-style import statement
> is parsed, the import name is added to a list that will affect function
> lookup.  This can be done when the function that contains the import
> statement is parsed or when it is evaluated.  Doing it at parse time
> requires a lot more smarts for the parser because it must determine what
> is a variable vs. what is a function.  Octave is not quite there yet.

I already made my guess which is that command-style => parse time while
function-style => evaluation time.  If Matlab is really doing some sort of
pre-processing on the function code, then it may not be building an import
list for that function.  It would be useful to test

function tstfunc ()
  import containers.Map
  x = Map ();
  L = import ()
end

> Also, I need to test what happens when eval is used to give a symbol a
> value when that symbol also exists as a function.  For example:
>
>   import pkg.sin;
>   eval ('sin = pi');
>   sin (1)
>
> Is pkg.sin called, or does sin (1) index the variable sin?  Does the
> result change if sin is "declared" to be a variable?
>
>   sin = [];
>   import pkg.sin;
>   eval ('sin = pi')
>   sin (1)
>
> I suspect that in the former case, the variable sin is ignored, but in
> the latter case, sin is treated as a variable, not the pkg.sin function.
>

Yes, these two tests will be interesting.

--Rik

> ** If the function-style syntax is used, then import still has an effect,
> but it behaves more like a normal function, and only changes the lookup
> for symbols that appear after the call to import.
>
> ** If an import function isn't found, it's an error.
>
> jwe
>
>
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]