1. routine_id scope

Forked from Re: Is there a good Windows or cross-platform Euphoria IDE?

dcuny said...

This also confuses me:

public function Icallback( sequence name, atom rid = routine_id(name) ) 
    return call_back( rid ) 
end function 

From your example, it looks like you can not only do an assignment to a non-constant value, but you can pass one of the parameter values.

Where is this in the manual defined? The manual says:

PROCDECLARE ==: [SCOPETYPE] 'procedure' IDENTIFIER '(' [PARMLIST] ')' [STMTBLK] 'end' 'procedure' 
PARMLIST ==: PARAMETER [',' PARMLIST] 
PARAMETER ==: DATATYPE IDENTIFER 

Maybe it's just that my Google-fu skills are lacking, but I can't find any mention default parameter values in the on-line manual.

There are some examples where they are used, but that's not quite the same.

- David

I found some discussion on scope for routine_id but nothing that calls attention to Greg's trick.

-xecronix

new topic     » topic index » view message » categorize

2. Re: routine_id scope

dcuny said...

Where is this in the manual defined?

It's in 4.2 Declarations, under 4.2.1.1 procedures.

docs said...

For a number of procedures or functions--see below--some parameters may have the same value in many cases. The most expected value for any parameter may be given a default value. Omitting the value of such a parameter on a given call will cause its default value to be passed.

procedure foo(sequence s, integer n=1) 
    ? n + length(s) 
end procedure 
 
foo("abc")    -- prints out 4 = 3 + 1. n was not specified, so was set to 1. 
foo("abc", 3) -- prints out 6 = 3 + 3 

(emphasis mine)

-Greg

new topic     » goto parent     » topic index » view message » categorize

3. Re: routine_id scope

xecronix said...

I found some discussion on scope for routine_id but nothing that calls attention to Greg's trick.

It was in this thread: init.e - standard library candidate.

jimcbrown said...

However, routine_id() is unique in that, like repeat() or it(), routine_id() relies on scoping to interpret the value of its parameter. So, what should routine_id() do? Should it use the scope where the routine is called, or the scope where the routine is defined? This only applies to routine_id(), since no other routine cares about scope in the same way when it is called.

-Greg

new topic     » goto parent     » topic index » view message » categorize

4. Re: routine_id scope

ghaberek said...

Yep. smile

Could this be given a heading? It's easy to miss, even when looking for it. It's not in the index, and it's not in any list. I literally skipped over it multiple times, even knowing what I was looking for.

It's a great feature.

Thanks!

- David

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu