comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » passing functions as arguments in IDL?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: passing functions as arguments in IDL? [message #19257 is a reply to message #18725] Tue, 29 February 2000 00:00 Go to previous messageGo to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Benno Puetz (puetz@mpipsykl.mpg.de) writes:

> David Fanning wrote:
>
>> 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:
>>> ...
>>> 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
>> --
>
> Would it also be possible to pass argument lists of variable length,
> depending on the function to be called?
>
> I've tried the _EXTRA keyword but to no avail ...

If those arguments are *keywords* I should imagine _Extra
will work: :-)

function f1, x, Multi=multi
if n_elements(multi) eq 0 then multi=2
return, x*multi
end

function tf1, func, arg, _Extra=extra
IF Size(func, /Type) NE 7 THEN BEGIN
Print, 'String argument required'
RETURN, -1
ENDIF
retVal = Call_Function(func, arg, _Extra=extra)
return, retVal
end

IDL> print, tf1('f1', 4, Multi=3)
12
IDL> print, tf1('f1', 4, Multi=6)
24

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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Output to dxf?
Next Topic: point_lun

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 22:35:02 PDT 2025

Total time taken to generate the page: 0.32071 seconds