Re: passing functions as arguments in IDL? [message #18724] |
Tue, 01 February 2000 00:00 |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Rick Baer (baer@hpl.hp.com) writes:
> Is there any way to pass functions as arguments in IDL? I would
> like to be able to do something like this:
>
> function f1, x
> return, x*x
> end
>
>
> pro tf1, func, arg
> return, func(arg)
> end
>
> IDL> print, tf1, f1, 4
You can do this:
function f1, x
return, x*x
end
function tf1, func, arg
IF Size(func, /Type) NE 7 THEN BEGIN
Print, 'String argument required'
RETURN, -1
ENDIF
retVal = Call_Function(func, arg)
return, retVal
end
IDL> print, tf1('f1', 4)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|