1. routine_id
- Posted by DonCole Aug 25, 2008
- 942 views
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
2. Re: routine_id
- Posted by DerekParnell (admin) Aug 25, 2008
- 859 views
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.
3. Re: routine_id
- Posted by gshingles Aug 25, 2008
- 835 views
-- 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
4. Re: routine_id
- Posted by mattlewis (admin) Aug 25, 2008
- 847 views
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()
5. Re: routine_id
- Posted by DerekParnell (admin) Aug 25, 2008
- 844 views
Which is actually broken, since you used r_MyProc before it was assigned:
picky ... picky ... picky
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...
6. Re: routine_id
- Posted by DonCole Aug 26, 2008
- 824 views
Which is actually broken, since you used r_MyProc before it was assigned:
picky ... picky ... picky
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...
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.
7. Re: routine_id
- Posted by ryanj Aug 26, 2008
- 813 views
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.
8. Re: routine_id
- Posted by DonCole Aug 26, 2008
- 809 views
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.
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.
9. Re: routine_id
- Posted by DerekParnell (admin) Aug 26, 2008
- 796 views
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()
10. Re: routine_id
- Posted by DonCole Aug 26, 2008
- 801 views
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.
11. Re: routine_id
- Posted by SDPringle Aug 26, 2008
- 814 views
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.
12. Re: routine_id
- Posted by mattlewis (admin) Aug 26, 2008
- 813 views
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
13. Re: routine_id
- Posted by bernie Aug 26, 2008
- 826 views
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 ????
14. Re: routine_id
- Posted by mattlewis (admin) Aug 26, 2008
- 807 views
You guys are confusing me ? Are you saying that ver 4.0 has forward reference ????
Yes.
Matt
15. Re: routine_id
- Posted by bernie Aug 26, 2008
- 790 views
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.
16. Re: routine_id
- Posted by mattlewis (admin) Aug 26, 2008
- 798 views
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
18. Re: routine_id
- Posted by euphoric (admin) Aug 26, 2008
- 806 views
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. )
19. Re: routine_id
- Posted by mattlewis (admin) Aug 26, 2008
- 792 views
- Last edited Aug 27, 2008
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. )
Sounds like Nocebo.
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
20. Re: routine_id
- Posted by euphoric (admin) Aug 26, 2008
- 793 views
- Last edited Aug 27, 2008
I thought last week the parse time was slower. That was only my "perception," and nothing based on hard numbers.
Sounds like Nocebo.
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!
21. Re: routine_id
- Posted by ChrisB (moderator) Aug 27, 2008
- 776 views
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
22. Re: routine_id
- Posted by mattlewis (admin) Aug 27, 2008
- 854 views
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