[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Matlab test
From: |
Ben Abbott |
Subject: |
Re: Matlab test |
Date: |
Fri, 17 May 2013 09:51:41 +0800 |
On May 17, 2013, at 9:09 AM, Michael Goffioul wrote:
> 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()".
Ok. That triggers the parser.
pack.invalid_fun(1)
Error using pack.invalid_fun
Error: File: invalid_fun.m Line: 2 Column: 10
Unexpected MATLAB operator.
> 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
I changed the function to ...
function a = invalid_fun (a++)
a = a;
end
matlab> clear all
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: []
>> pack.invalid_fun (1)
Error using pack.invalid_fun
Error: File: invalid_fun.m Line: 1 Column: 28
Unexpected MATLAB operator.
> 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?
You'd like the content of invalid_fun.m to be ...
classde invalid_class < handle
end
Using this I get ...
matlab> clear all
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> pack.invalid_fun (1)
Error using pack.invalid_fun
Error: File: invalid_fun.m Line: 2 Column: 1
Illegal use of reserved keyword "end".
Ben