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

Re: defining functions on-the-fly

Marshall Perrin wrote:
> I would like to be able to define some functions on-the-fly in IDL.
> In other words, my program does some stuff, and computes that the desired
> function is (some arbitrary function, not necessarily a polynomial).
> I would then like to define the equivalent of
> FUNCTION myfunction, x,y
>   return, <my arbitrary expression in (x,y)>
> and then be able to call myfunction(x,y).
> Is there any easier way to do this than actually writing out a
> myfunction.pro file to disk and compiling that? That way would certainly
> work, but it strikes me as inelegant... At first I thought I could do this
> with the EXECUTE statement, but you can't define functions using that.
>  - Marshall

try .comp:

IDL> .comp [ENTER]
- function f
- return,42
- end
% Compiled module: F.
IDL> print,f()

:-) marc