[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to check for availability of functions in core octave
From: |
Ben Abbott |
Subject: |
Re: How to check for availability of functions in core octave |
Date: |
Sat, 30 Jul 2011 13:08:25 -0400 |
On Jul 29, 2011, at 7:39 PM, Ben Abbott wrote:
> On Jul 29, 2011, at 5:44 PM, Philip Nienhuis wrote:
>
>> John W. Eaton wrote:
>>> On 29-Jul-2011, PhilipNienhuis wrote:
>>>
>>> | Almost, Ben, a good first try, thanks.
>>> |
>>> | But... your example also picks up functions in octave-forge:
>>> |
>>> | octave.exe:4> isimplemented = @(fun) exist (strcat(fun,".m")) == 2 ||
>>> exist
>>> | (fun)> 2
>>> | isimplemented =
>>> |
>>> | @(fun) exist (strcat (fun, ".m")) == 2 || exist (fun)> 2
>>> |
>>> | octave.exe:5> isimplemented ("residue")
>>> | ans = 1
>>> | octave.exe:6> isimplemented ("xls2oct")
>>> | ans = 1
>>> |
>>> | (xls2oct.m is in the OF io package)
>>> |
>>> | Even worse, it picks up OF functions shadowing core functions:
>>> |
>>> | GNU Octave, version 3.4.2
>>> | Copyright (C) 2011 John W. Eaton and others.
>>> | This is free software; see the source code for copying conditions.
>>> | There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
>>> | FITNESS FOR A PARTICULAR PURPOSE. For details, type `warranty'.
>>> |<snip>
>>> | warning: function
>>> | C:\Programs\Octave\3.4.2\share\octave\packages\specfun-1.0.9\erfcx.m sha
>>> | dows a built-in function
>>> | :
>>> |<further down>
>>> | :
>>> | octave.exe:7> isimplemented ("erfcx")
>>> | ans = 1
>>> | octave.exe:8>
>>> |
>>> |
>>> | My question is really aimed at detecting stuff in core Octave, regardless
>>> of
>>> | whether it is shadowed or not (yes an extra requirement coming out of the
>>> | blue, now that there's something I could try).
>>>
>>> The shadow warning comes from a function in load-path.cc, when the
>>> contents of a directory are being added to the internal map that
>>> allows for function lookups.
>>>
>>> You could use the results of __builtins__, __keywords__, and
>>> __list_functions__, but you would need to be sure that the load path
>>> contains only the default set of directories. Maybe
>>> __list_functions__ could be modified to accept a parameter telling it
>>> to list only the "system" functions?
>>
>> Such a parameter would be a good option.
>>
>> An alternative is excluding all paths in .../share/octave/packages/ ? (as
>> that is where most of the shadowing I'm after comes from) and then
>> re-running __list_functions__
>>
>> Trying something along these lines:
>>
>> pkg unload all
>> __list_functions__
>>
>> reveals that __list_functions__ appears to read from cached info. All
>> octave-forge functions are still listed.
>>
>> Can __list_functions__'s base info be reinitialized? If so I would be almost
>> there.
>>
>> Philip
>
> If functions in the current working directory aren't a problem, then you can
> do something like ...
>
> function [ ret ] = isimplemented (fun)
> path_orig = path ();
> unwind_protect
> restoredefaultpath ();
> ret = exist (strcat(fun,".m")) == 2 || exist (fun) > 2;
> unwind_protect_cleanup
> path (path_orig)
> end_unwind_protect
> endfunction
>
> Ben
I used John's suggestion to use the results of __builtins__, __keywords__, and
__list_functions__ and removed those functions not in the default path and
those in the pwd. The result is attached.
Ben
isimplemented.m
Description: Binary data