Undocumented Matlab path search
John W. Eaton
jwe at bevo.che.wisc.edu
Mon Apr 14 15:40:24 CDT 2008
On 14-Apr-2008, Michael D. Godfrey wrote:
| I tried to use Octave on files with the following structure
|
| current directory: lev01
| contains: funct_l1.m @funct_l2/
|
| directory @funct_l2
| contains: funct_l2.m private/
|
| directory private
| contains: l3_1.m
|
| Thus, ls -lR gives:
| [qss:lev01] ls -lR
| .:
| total 8
| -rw-rw-r-- 1 godfrey godfrey 39 2008-04-14 12:55 funct_l1.m
| drwxrwxr-x 3 godfrey godfrey 4096 2008-04-14 12:55 @funct_l2/
|
| ./@funct_l2:
| total 8
| -rw-rw-r-- 1 godfrey godfrey 43 2008-04-14 12:55 funct_l2.m
| drwxrwxr-x 2 godfrey godfrey 4096 2008-04-14 12:55 private/
|
| ./@funct_l2/private:
| total 4
| -rw-rw-r-- 1 godfrey godfrey 31 2008-04-14 12:55 l3_1.m
| ====================================================
| The contents of the three .m files are:
| funct_l1.m
| function f1 = funct_l1
|
| f1 = funct_l2
| ===================
| funct_l2.m
| function f2 = funct_l2
|
| f2 = 23+l3_1();
| ====================
| l3_1.m
| function l3 = l3_1
|
| l3= 333;
| =========================================
| Octave interprets the @funct_l2 directory in the same way as Matlab, i.e.
| this directory is in the search path due to the @. This is not documented.
|
| But, Octave does not search the directory "private," whereas Matlab does
| search it from references in @funct_l2/ Thus, "private" is treated
| as private to the directory in which it is located.
|
| The Matlab result is:
| >> xx =funct_l1
|
| f1 =
|
| 356
|
|
| xx =
|
| 356
|
| >> x=l3_1
| ??? Undefined function or variable 'l3_1'.
|
| >>
| =======================================
| The Octave result is:
| octave:1> funct_l1
| error: `l3_1' undefined near line 3 column 11
| error: evaluating binary operator `+' near line 3, column 10
| error: evaluating assignment expression near line 3, column 6
| error: called from `funct_l2' in file
| `/home/godfrey/mdg/software/octave/paths/lev01/@funct_l2/funct_l2.m'
| error: evaluating assignment expression near line 3, column 4
| error: called from `funct_l1' in file
| `/home/godfrey/mdg/software/octave/paths/lev01/funct_l1.m'
| octave:1>
|
| ========================================
|
| I could find no description of this in the Matlab documentation, but it
| must be a "feature" known to some Matlab programmers. Note that
| this behavior is only true if directory name at level 2 is "private." If
| "private' is changed to another name Matlab and Octave produce the
| same search results.
|
| This Matlab behavior seems to me somewhere between tacky and
| nonsensical, but it is what they do. This is Matlab level 7.5 R2007b.
|
| Obviously, this can be fixed by including "private" in the search path,
| but then it is also searched from outside @funct_l2. A more general
| method for managing scope of directory names in search paths would
| be nice, and I understand that this is being given thought.
|
| This may test people's willingness to match Matlab right or wrong.
The @ directories are for classes.
Private directories are for "private" functions, only visible to the
functions in the parent of the private directory.
These features are documented Matlab features.
Neither is supported in Octave 3.0. The current Octave development
sources (main branch) has some support for both, and so both will be
supported (to some extent) in 3.1.
jwe
More information about the Bug-octave
mailing list