1. routine_id

In the docs for routine_id it says,

Some typical uses of routine_id() are:

1. Calling a routine that is defined later in a program.

I'm confused by this. How does this work?

               
               
              procedure pilchard() 
               
                 --do something 
                  
              end procedure 
              
               
              procedure spuds(integer self, integer event, sequence params) 
               
                 pilchard() 
                  
              end procedure 
               
              setHander(PushButton11,w32HClick,routine_id("spuds")) 
               
               
              

procedure spuds is defined before the

routine_id("spuds") .

the procedure pilchard() is defined before the

procedure spuds()

So where a we calling a procedure that is defined later

in the program?

Don Cole

new topic     » topic index » view message » categorize

2. Re: routine_id

DonCole said...

So where a we calling a procedure that is defined later in the program?

Ask yourself, in that program, where is the call statement? Your program isn't calling it. It's the Win32lib library that is calling your routine, and its call statement is before your routine's declaration.

However, here is a simpler example.


integer r_MyProc 
 
call_proc(r_MyProc, {})  --<<<< Here is the call. 
 
procedure MyProc() --<<<< Here is the routine. 
  puts(1, "MyProc called\n") 
end procedure 
r_MyProc = routine_id("MyProc") 

Just as a side note, in v4 Euphoria, you won't have to use routine_id for this sort of situation,


-- V4.0 -- 
MyProc()  --<<<< Here is the call. 
 
procedure MyProc() --<<<< Here is the routine. 
  puts(1, "MyProc called\n") 
end procedure 

However you will still need it for libraries like Win32lib, because another use of routine_id is to provide a routine to execute when the routine's name is not known by the caller.

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

3. Re: routine_id

DerekParnell said...
-- V4.0 -- 
MyProc()  --<<<< Here is the call. 
 
procedure MyProc() --<<<< Here is the routine. 
  puts(1, "MyProc called\n") 
end procedure 

Hey, the eucode came up in sytnax colour in my RSS feed (Safari). Cool.

</trivial>

Gary

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

4. Re: routine_id

DerekParnell said...

However, here is a simpler example.


integer r_MyProc 
 
call_proc(r_MyProc, {})  --<<<< Here is the call. 
 
procedure MyProc() --<<<< Here is the routine. 
  puts(1, "MyProc called\n") 
end procedure 
r_MyProc = routine_id("MyProc") 

Which is actually broken, since you used r_MyProc before it was assigned:

integer r_MyProc 
procedure main() 
  call_proc(r_MyProc, {})  --<<<< Here is the call. 
end procedure 
 
procedure MyProc() --<<<< Here is the routine. 
  puts(1, "MyProc called\n") 
end procedure 
r_MyProc = routine_id("MyProc") 
 
main() 
new topic     » goto parent     » topic index » view message » categorize

5. Re: routine_id

mattlewis said...

Which is actually broken, since you used r_MyProc before it was assigned:

picky ... picky ... picky blink

Actually in my fist attempt I had

integer r_MyProc = routine_id("MyProc") 

but then I realized you can't do that in v3.1... shocked

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

6. Re: routine_id

DerekParnell said...
mattlewis said...

Which is actually broken, since you used r_MyProc before it was assigned:

picky ... picky ... picky blink

Actually in my fist attempt I had

integer r_MyProc = routine_id("MyProc") 

but then I realized you can't do that in v3.1... shocked

Thank you Derek,

I see you must use call_proc() first.

I didn't know that.

And gShingles,

I type my post in TextPad first (because it has SpellCheck ; this forum does not.

In all fairness nether did the old forum.)

I copy then paste from TextPad to the forum.

This where I believe <eucode> and </eucode> get lost.

Don Cole A Bug is an un-documentedfeature. A Feature is a documented Bug.

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

7. Re: routine_id

DonCole said...

I type my post in TextPad first (because it has SpellCheck ; this forum does not.

In all fairness nether did the old forum.)

Well, Firefox has built-in spell checking. smile

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

8. Re: routine_id

ryanj said...
DonCole said...

I type my post in TextPad first (because it has SpellCheck ; this forum does not.

In all fairness nether did the old forum.)

Well, Firefox has built-in spell checking. smile

Sorry Derek,

When I run your program I get variable r_MyProc has not been assigned a value .

Don Cole A Bug is an un-documentedfeature. A Feature is a documented Bug.

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

9. Re: routine_id

DonCole said...

Sorry Derek, When I run your program I get variable r_MyProc has not been assigned a value .

I take it you didn't notice Matt's correction to my code. It should have read ...

integer r_MyProc  
procedure main()  
  call_proc(r_MyProc, {})  --<<<< Here is the call.  
end procedure  
  
procedure MyProc() --<<<< Here is the routine.  
  puts(1, "MyProc called\n")  
end procedure  
r_MyProc = routine_id("MyProc")  
  
main() 
new topic     » goto parent     » topic index » view message » categorize

10. Re: routine_id

DerekParnell said...
DonCole said...

Sorry Derek, When I run your program I get variable r_MyProc has not been assigned a value .

I take it you didn't notice Matt's correction to my code. It should have read ...

integer r_MyProc  
procedure main()  
  call_proc(r_MyProc, {})  --<<<< Here is the call.  
end procedure  
  
procedure MyProc() --<<<< Here is the routine.  
  puts(1, "MyProc called\n")  
end procedure  
r_MyProc = routine_id("MyProc")  
  
main() 

Yes I see that now.

But it looks like all this is being called from main() at the bottom of the code. I have to study this awhile.

Thanks again Derek.

Don Cole A Bug is an un-documented feature. A Feature is a documented Bug.

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

11. Re: routine_id

The documentation should read that routine_id can be used to call a routine before it is defined. With 4.0 declare and define you really could say 'declared' here.

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

12. Re: routine_id

SDPringle said...

The documentation should read that routine_id can be used to call a routine before it is defined. With 4.0 declare and define you really could say 'declared' here.

Actually, you don't even need 'declared' or anything like that in 4.0:

MyProc()  --<<<< Here is the call.   
   
procedure MyProc() --<<<< Here is the routine.   
  puts(1, "MyProc called\n")   
end procedure   

Matt

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

13. Re: routine_id

mattlewis said...
SDPringle said...

The documentation should read that routine_id can be used to call a routine before it is defined. With 4.0 declare and define you really could say 'declared' here.

Actually, you don't even need 'declared' or anything like that in 4.0:

MyProc()  --<<<< Here is the call.   
   
procedure MyProc() --<<<< Here is the routine.   
  puts(1, "MyProc called\n")   
end procedure   

Matt

Matt: 
  You guys are confusing me ? 
Are you saying that ver 4.0 has forward reference ???? 
 

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

14. Re: routine_id

bernie said...

You guys are confusing me ? Are you saying that ver 4.0 has forward reference ????

Yes.

Matt

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

15. Re: routine_id

mattlewis said...
bernie said...

You guys are confusing me ? Are you saying that ver 4.0 has forward reference ????

Yes.

Matt

How does ver 4.0 know what the parameters are ? 
 
Are you doing a 2 pass parse ? 
 
I noticed that the startup parse seems to be quite slow on my 900MHz machine. 
 

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

16. Re: routine_id

bernie said...

How does ver 4.0 know what the parameters are ? 
 
Are you doing a 2 pass parse ? 
 
I noticed that the startup parse seems to be quite slow on my 900MHz machine. 
 

It doesn't. What it does is leave some extra space in case of extra default parameters, and also remembers the fact that there was something that looked like a forward reference. It then checks (at the end of each file) to see if it can resolve any of the references that weren't previously resolved.

At the very end, if there are still any outstanding calls that have yet to be resolved, they are listed as an error.

So each forward reference takes a little bit more room in the IL than a normal call would, and there's a slight performance difference, since there's an extra goto in the IL to jump from the end of the actual call to the beginning of the next instruction. This is pretty minor (and you'd probably have to really work at it to tell the difference). It is definitely faster than a call_proc/func though.

Matt

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

17. Re: routine_id

That is very cool. Euphoria rocks!

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

18. Re: routine_id

mattlewis said...
bernie said...

I noticed that the startup parse seems to be quite slow on my 900MHz machine. 

It is definitely faster than a call_proc/func though.

I thought last week the parse time was slower. That was only my "perception," and nothing based on hard numbers. What is the speed of the parser pre-FR compared to now? (Just curious and to make sure I'm perceiving things accurately. smile )

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

19. Re: routine_id

euphoric said...
mattlewis said...
bernie said...

I noticed that the startup parse seems to be quite slow on my 900MHz machine. 

It is definitely faster than a call_proc/func though.

I thought last week the parse time was slower. That was only my "perception," and nothing based on hard numbers. What is the speed of the parser pre-FR compared to now? (Just curious and to make sure I'm perceiving things accurately. smile )

Sounds like Nocebo. smile

I was talking about execution time, which is far more important. If you don't use any forward references, then I doubt you could tell. If you use lots, then it's possible that you might notice something, especially if you have many files, because the check is done whenever it finishes reading a file.

The checks themselves shouldn't have much more overhead than parsing an extra call somewhere in your code. I'd be really surprised if there were a noticeable difference.

I think that there are some optimizations we can do for the parser in general, like changing from big if-else blocks to switches. But I doubt it will make a huge difference.

Matt

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

20. Re: routine_id

mattlewis said...
euphoric said...

I thought last week the parse time was slower. That was only my "perception," and nothing based on hard numbers.

Sounds like Nocebo. smile

Uh oh. That sounds bad.

Jeremy, you remember when I brought that up in chat last week, about the parser being slower? Maybe it was a different change to the interpreter (nothing to do with FR). I shoulda posted it to the dev list. Drat!

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

21. Re: routine_id

Hi

I know I've been a great proponent of forward referencing, and I'm really pleased to here this news.

But, will call_proc/func calls still work as before, or will there have to be a re write of existing code to remove those?

Chris

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

22. Re: routine_id

ChrisB said...

Hi

I know I've been a great proponent of forward referencing, and I'm really pleased to here this news.

But, will call_proc/func calls still work as before, or will there have to be a re write of existing code to remove those?

No, nothing has changed there. There are still times when they are the best solution.

Matt

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

Search



Quick Links

User menu

Not signed in.

Misc Menu