octave-maintainers
[Top][All Lists]
Advanced

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

Re: Matlab test


From: Michael Goffioul
Subject: Re: Matlab test
Date: Thu, 16 May 2013 21:09:29 -0400

On Thu, May 16, 2013 at 8:34 PM, Ben Abbott <address@hidden> wrote:
On May 17, 2013, at 7:02 AM, Michael Goffioul wrote:

> Hi,
>
> Can I ask anybody to make a test for me under Matlab. I'm trying to determine when Matlab actually parses files that are contained in a package. The only thing I can think of is to put a parse error into one of the files.
>
> So the test would be to have a package, not initially in your path, and a file (e.g. a function file) in that package, which contains a parse error. Then use "addpath" to make the package visible, that is adding the parent of the package directory to the path.
>
> So let's say you have the following: a/+pack/invalid_fun.m (invalid_fun.m has a parse error). Then try the following commands (if any of the command produces an error, don't bother going further):
>
> addpath a
> p = meta.package.fromName('pack')
> fcn = p.Functions{1}
> fcn()
>
> Michael.

I used a trivial function

function a = invalid_fun (a)
  a = a .+ 1;
end

Then ...

addpath ('~/Documents/MATLAB/a')
matlab>p = meta.package.fromName('pack')

p =

  package with properties:

                 Name: 'pack'
            ClassList: [0x1 meta.class]
         FunctionList: [1x1 meta.method]
          PackageList: [0x1 meta.package]
    ContainingPackage: []

matlab>fcn = p.Functions{1}

fcn =

  method with properties:

                   Name: 'invalid_fun'
            Description: ''
    DetailedDescription: ''
                 Access: 'public'
                 Static: 0
               Abstract: 0
                 Sealed: 0
                 Hidden: 0
             InputNames: {'rhs1'}
            OutputNames: {'lhs1'}
          DefiningClass: []

matlab>fcn()

ans =

  method with properties:

                   Name: 'invalid_fun'
            Description: ''
    DetailedDescription: ''
                 Access: 'public'
                 Static: 0
               Abstract: 0
                 Sealed: 0
                 Hidden: 0
             InputNames: {'rhs1'}
            OutputNames: {'lhs1'}
          DefiningClass: []

And I get no error.  Have I done something wrong?  I'm not familiar with the meta.packages.  How may I actually call the function?

You actually call it with "pack.invalid_fun()". But the documentation says that the "Functions" property return a cell array of function handles. Apparently, there's some confusion about what "function handle" means. In this case, it looks like it is a meta.method object instead (and meta.method class inherits from handle class).

This makes me wonder what would be the result if
1) the parse error was in the function definition line instead
2) invalid_fun.m was an invalid classdef definition file instead: I would expect it to appear in p.Classes instead, though if the parse error is in the classdef line (for instance "classde invalid_class < handle"), what would it do?

Michael.


reply via email to

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