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

Home » Public Forums » archive » Re: call_method
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: call_method [message #26573 is a reply to message #26478] Thu, 06 September 2001 20:42 Go to previous message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
From: "Pavel A. Romashkin" <pavel.romashkin@noaa.gov>
> David Fanning wrote:
>
>> IDL doesn't have any trouble keeping straight the difference
>> between procedures and functions with the same name.
>
> Oh... This never occurred to me. I have never even attempted making a
> pro and a function with the same name. Duh...

There's no problem in *having* a procedure and a function with the same
name. The problem is in *compiling* them both. Or to be more exact, in
having them automatically complied.

To demonstrate, try the following:

* Save the following code...

pro myroutine
print, "Hello from MYROUTINE procedure"
end
function myroutine
print, "Hello from MYROUTINE function"
end

...into a file called myroutine.pro and put it somewhere on your path.

* At the IDL prompt type "myroutine". The following appears in the console
window:

% Compiled module: MYROUTINE.
Hello from MYROUTINE procedure

* Now type "help, myroutine()". This gives:

% Attempt to call undefined procedure/function: 'MYROUTINE'.
% Execution halted at: $MAIN$

* Reset the IDL session and call the function & procdure in the opposite
order. Same result: the procedure is compiled and the function is not.

* Reverse the order of the procedure and the function in the file, reset the
session and call them again. Now the function will be compiled and the
procedure will not.

* Reset again and compile myroutine.pro manually. Now you get them both

My interpretation: the first time IDL encounters either a function or a
procedure called MYROUTINE, it searches the path for myroutine.pro and then
compiles the file until it encounters EITHER a procedure OR a function
called myroutine. Having compiled that it does not read any more of the
file. Any code that up to & including the first occurrence of myroutine will
be complied; any code after that will not.

So you *can* have a procedure and function of the same name but you'll have
to find some way of ensuring that both are compiled.

Class methods follow the same rules, but normally methods are all gathered
in one file (myclass__define.pro) which is called when the first instance of
this class is created. All method definitions before myclass__define will be
compiled so it is OK to have a procedure method and a function method of the
same name. And I do it all the time.

---
Mark Hadfield
m.hadfield@niwa.cri.nz http://katipo.niwa.cri.nz/~hadfield
National Institute for Water and Atmospheric Research



--
Posted from clam.niwa.cri.nz [202.36.29.1]
via Mailgate.ORG Server - http://www.Mailgate.ORG
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: structure information
Next Topic: Re: Problem combining structures

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

Current Time: Fri Oct 10 03:16:30 PDT 2025

Total time taken to generate the page: 0.48041 seconds