help understanding package/class/function references

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

help understanding package/class/function references

John W. Eaton
Administrator
Could someone run the following test in a recent version of Matlab?

Unpack the attached tar file.  It will create a directory called tst
containing a package directory +apkg and two files, one classdef
definition and one ordinary function.  Then cd to that directory in
Matlab and execute the commands

   apkg.cls.smeth
   apkg.cls.smeth.f
   apkg.fcn
   apkg.fcn.f

and reply to this message with the results.  I'm expecting that the
expressions indexing the function calls with .f will be errors.

Thanks,

jwe

tst.tar.gz (368 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: help understanding package/class/function references

nrjank


On Fri, Feb 15, 2019 at 12:41 PM John W. Eaton <[hidden email]> wrote:
Could someone run the following test in a recent version of Matlab?


Matlab 2018b:

>> apkg.cls.smeth
ans =
  struct with fields:
    f: 'cls'
>> apkg.cls.smeth.f
ans =
    'cls'
>> apkg.fcn
ans =
  struct with fields:
    f: 'fcn'
>> apkg.fcn.f
Undefined variable "apkg" or class "apkg.fcn.f".
 
Reply | Threaded
Open this post in threaded view
|

Re: help understanding package/class/function references

John W. Eaton
Administrator
On 2/15/19 1:11 PM, Nicholas Jankowski wrote:

>
>
> On Fri, Feb 15, 2019 at 12:41 PM John W. Eaton <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Could someone run the following test in a recent version of Matlab?
>
>
> Matlab 2018b:
>
>  >> apkg.cls.smeth
> ans =
>    struct with fields:
>      f: 'cls'
>  >> apkg.cls.smeth.f
> ans =
>      'cls'

So the result of calling a static method may be further indexed?  That's
a bit of a surprise.

>  >> apkg.fcn
> ans =
>    struct with fields:
>      f: 'fcn'
>  >> apkg.fcn.f
> Undefined variable "apkg" or class "apkg.fcn.f".

I'm not sure I understand how this error happens.  Is it because the
package "apkg" is found but since "fcn" is not the last element of the
"." index chain Matlab doesn't even look for a function called "fcn"?
Instead, the only valid things would be for "apkg" to be a variable or
"fcn" to name another package or a class?  In that case, we have to
examine fcn.m to determine whether it defines a classdef object.

jwe