1. routine_id
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> Nov 24, 1998
- 513 views
Oops, I have a problem (again namespace). When I have two include files, that both contain a routine named: "bot_run" and "bot_init" and they both use routine_id ("bot_run") and routine_id ("bot_init"), therefore binding nor shrouding will be possible. Ahh!! The whole namespace thingie should be handled differently, instead of these 'hacks'.. Robert ? ... Ralf. PS Why do I only get see half of my own messages from the list-server.. sometimes it does and sometimes it doesnt send them to me as well.. i'm confused.
2. Re: routine_id
- Posted by Irv Mullins <irv at ELLIJAY.COM> Nov 24, 1998
- 472 views
On Tue, 24 Nov 1998 10:47:05 +0100, Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> wrote: >Oops, I have a problem (again namespace). >When I have two include files, that both contain a routine named: "bot_run" >and "bot_init" and they both use routine_id ("bot_run") and routine_id >("bot_init"), therefore binding nor shrouding will be possible. Ahh!! > >The whole namespace thingie should be handled differently, instead of these >'hacks'.. > >Robert ? > It's not just 'bots' - almost any program of worthwhile length runs into this namespace thingy. If we use other people's includes; Jiri's fonts, for example, we have to tread carefully. It even becomes a challenge to create meaningful but non-conflicting names for our own routines in multiple files. I hereby re-submit for further discussion my versions of how it might be handled: with fonts do -- where fonts.e is an include set_background(BLUE) ..bla.. end with with mywin do -- and mywin is another include set_background(BLACK) end with or, less verbosely (in some cases, more in others) fonts.set_background(BLUE) mywin.set_background(BLACK) Irv
3. Re: routine_id
- Posted by "Bown, John" <John.Bown at UK.ORIGIN-IT.COM> Nov 24, 1998
- 450 views
> >On Tue, 24 Nov 1998 10:47:05 +0100, Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> >wrote: > >>Oops, I have a problem (again namespace). >>When I have two include files, that both contain a routine named: "bot_run" >>and "bot_init" and they both use routine_id ("bot_run") and routine_id >>("bot_init"), therefore binding nor shrouding will be possible. Ahh!! Are we saying that the following won't work if BIND is done on it ? I thought I'd got it to work; it did require a -switch but can't remember what it was ( no euphoria installed on this PC so cannot test it ). Or have I misunderstood the problem. MAIN.EX ======= global integer CallA global integer CallB include A.E include B.E call_proc( CallA , {} ) call_proc( CallB , {} ) A.E === procedure MyProc() puts(1,"I am A\n") end procedure CallA = routine_id("MyProc") B.E === procedure MyProc() puts(1,"I am B\n") end procedure CallB = routine_id("MyProc")
4. Re: routine_id
- Posted by Daniel Berstein <daber at PAIR.COM> Nov 24, 1998
- 456 views
>Are we saying that the following won't work if BIND is done on it ? I >thought I'd got it to work; it did require a -switch but can't remember >what it was ( no euphoria installed on this PC so cannot test it ). Or >have I misunderstood the problem. BIND automatically "renames" collading identifiers. The problem is that routine_id() uses a string... that is NOT renamed (can't be, you can build that string programatically). If you use routine_id() in your code BIND oblies you to use the -clear_routines to preserve function/ procedure names (by default they get obfuscated) because of the same reason. I wish Euphoria 2.1 has a better namespace mechanism or a smarter routine_id() interface (or a ultra-inteligent bind utility). Regards, Daniel Berstein daber at pair.com
5. Re: routine_id
- Posted by JJProg at CYBERBURY.NET Nov 24, 1998
- 495 views
- Last edited Nov 25, 1998
EU>It's not just 'bots' - almost any program of worthwhile EU>length runs into this namespace thingy. If we use other EU>people's includes; Jiri's fonts, for example, we have EU>to tread carefully. It even becomes a challenge to create EU>meaningful but non-conflicting names for our own routines EU>in multiple files. EU>I hereby re-submit for further discussion my versions of EU>how it might be handled: EU>with fonts do -- where fonts.e is an include EU> set_background(BLUE) EU> ..bla.. EU>end with EU>with mywin do -- and mywin is another include EU> set_background(BLACK) EU>end with EU>or, less verbosely (in some cases, more in others) EU>fonts.set_background(BLUE) EU>mywin.set_background(BLACK) EU>Irv Good idea. I'll try to add that to EPP. I think Euphoria could use Java like object orientation. Jeffrey Fielding JJProg at cyberbury.net http://members.tripod.com/~JJProg/
6. Re: routine_id
- Posted by Jiri Babor <J.Babor at GNS.CRI.NZ> Nov 25, 1998
- 496 views
Thanks, Irv, your note is my first tangible reward... In a self-destructive mood I decided to try and force the name space issue, in a small way, with my latest version of font.e. I deliberately chose the most common identifier names I could think of, write, height, width, CLEAR, LEFT, RIGHT, etc to get as many clashes as possible for my unfortunate victims... I was perhaps very inconsiderate and probably very foolish, but I really think something has to be done about it. It's already pretty late. jiri
7. Re: routine_id
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> Nov 25, 1998
- 472 views
John Bown wrote: >>>Oops, I have a problem (again namespace). >>>When I have two include files, that both contain a routine named: "bot_run" >>>and "bot_init" and they both use routine_id ("bot_run") and routine_id >>>("bot_init"), therefore binding nor shrouding will be possible. Ahh!! > >Are we saying that the following won't work if BIND is done on it ? I >thought I'd got it to work; it did require a -switch but can't remember >what it was ( no euphoria installed on this PC so cannot test it ). Or >have I misunderstood the problem. <code snipped> No, your code *would* work. The problem for my code is *this* .. ===MAIN.EX=== function bot_run () return 1 end function constant player1 = routine_id ("bot_run") ===PlayerBOT=== function bot_run () return 1 end function constant player2 = routine_id ("bot_run") ============= Binded, both constants will point to the *first* bot_run () Why ? Because -clear_routines will preserver the names of routines, however the name is used twice, and they cannot exist twice in the same file. (binded/shrouded it makes it all one file, and renames all identifers so they won't conflict) If I would rename the second bot to bot2_run () it would all work, but come on, this is silly. Of all problems and bad structure a language would allow, this is the most silly one. Euphoria is very strong on certain points, but what is *this* ?
8. Re: routine_id
- Posted by "M. Ter Haseborg" <M.S.ter.Haseborg at FWN.RUG.NL> Sep 19, 2000
- 465 views
Hai Glen The routine_id gives the (start)position of the routine . In the compiler it may be give a adress of a hash table where in the adres of the routine is or they give back the routine adres . This depends on how the do it . Greatings Menno Date sent: Tue, 19 Sep 2000 10:59:52 +0300 Send reply to: Euphoria Programming for MS-DOS <EUPHORIA at LISTSERV.MUOHIO.EDU> From: Glen Brown <gbrown7777 at YAHOO.COM> Subject: routine_id To: EUPHORIA at LISTSERV.MUOHIO.EDU > Hello all, > > Just one quick question. > > > What EXACTLY does 'routine_id' do? > > > And please don't tell me to RTM. I have RTM an it says: > > Syntax: i = routine_id(st) > Description: Return an integer id number, known as a routine id, for a > user-defined Euphoria procedure or function. The name of the procedure or > function is given by the string sequence st. -1 is returned if the named > routine can't be found. > Comments: The id number can be passed to call_proc() or call_func(), to > indirectly call the routine named by st. > > That doesn't really tell me what it does. It tells me what I get when I use > it. > > As an example: > > onClick[Button2] = routine_id( "onClick_Button2" ) > > I know that 'onClick_Button2' is a procedure that is previously defined. > > Apparently 'onClick' is a sequence and I am making some subscript of that > sequence equal to whatever number 'routine_id' spits out. > > I think that 'onClick' is probably defined in win32lib. Don't know for > sure. > > Shoot, for all I know I really want to know what "onClick[Whatever]" does or > perhaps "onKeyPress[Whatever]" I really don't know. > > But for now. > > > What EXACTLY does 'routine_id' do? > > Thank in advance for the several dozen answers I am sure to get from this. > > Glen > > > _________________________________________________________ > Do You Yahoo!? > Get your free @yahoo.com address at http://mail.yahoo.com >
9. Re: routine_id
- Posted by Derek Parnell <dparnell at BIGPOND.NET.AU> Sep 19, 2000
- 467 views
- Last edited Sep 20, 2000
Hi Glen, just got home from work an see that no-one has responded yet, so I'll have a go. "routine_id" takes the name of a previously defined function or procedure, and returns an integer. This integer represents an index into some hidden internal list that Euphoria keeps. This list has all the memory addresses (or something that can equate to an address) of the function/procedures you have defined. The purpose of routine_id(), is so that you can call a function or procedure, without knowing its name. To do this, you use the integer returned by routine_id as a parameter to call_func() or call_proc() as the case may be. These two routines, call your original routine indirectly. Ok, now for an example... integer theFunc function ABC( integer a, integer b) return a * b end function theFunc = routine_id("ABC") -- Calculate 5 times 6 = 30 result = call_func(theFunc, {5,6}) ---------- Now why is this a good idea? Seeing you can do the same without routine_id()! Well, consider this example... sequence theFunc theFunc = {0,0,0,0} function doMaths(integer type, integer first, integer second) -- Perform some math operation on 'first' and 'second' return (call_func(theFunc[type], {first,second})) end function function Mult( integer a, integer b) return a * b end function function Divn( integer a, integer b) return a / b end function function Add( integer a, integer b) return a + b end function function Sub( integer a, integer b) return a - b end function theFunc[1] = routine_id("Add") theFunc[2] = routine_id("Sub") theFunc[3] = routine_id("Divn") theFunc[4] = routine_id("Mult") -- Calculate 5 times 6 = 30 result = doMath( 4, 5, 6) -- Calculate 5 - 6 = -1 result = doMath( 2, 5, 6) -- Calculate 5 / 6 = 0.833333333 result = doMath( 3, 5, 6) -- Calculate 5 + 6 = 11 result = doMath( 1, 5, 6) ------------------- The difference between the examples is that in the second, the function doMath() was defined before the Add,Sub,Divn,Mult functions, but could still run them indirectly via the "theFunc" value. Without using routine_id, this would be impossble in Euphoria (though not in a lot of other languages). Among other things, this technique allows you to write generic routines whose behaviour is determined at runtime, and not compile time. It's also a workaround for Euphoria's "define before use" philosophy. In Win32lib, each of the permissible event handler type, such as onClick, onClose, etc... is represented as a list of routine_ids. Each list, onClick for example, has one entry for each control or window created. To start with, these are set to -1, but when you set one via a call to routine_id(), it tells Win32lib where your specific handler is. Win32lb then uses call_proc() to invoke your handler at the appropriate times. Thus your example, > onClick[Button2] = routine_id( "onClick_Button2" ) is telling Win32lib, that the control Button2 has a handler routine that your have written. Win32lib doesn't know what your routine is called, but it can still access it via the routine_id value. Another major use of routine_id is to enable you to pass the address of your routine to some external 'C' code so that the 'C' code can call your routine. This is used in Window callback processing. All the OO variants of Euphoria take advantage of routine_id. Also, the custom_sort() routine, supplied by RDS, uses a routine_id to allow you to define your own comparision routine. ------- cheers, Derek. ----- Original Message ----- From: "Glen Brown" <gbrown7777 at YAHOO.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Tuesday, September 19, 2000 6:59 PM Subject: routine_id > Hello all, > > Just one quick question. > > > What EXACTLY does 'routine_id' do? > > > And please don't tell me to RTM. I have RTM an it says: > > Syntax: i = routine_id(st) > Description: Return an integer id number, known as a routine id, for a > user-defined Euphoria procedure or function. The name of the procedure or > function is given by the string sequence st. -1 is returned if the named > routine can't be found. > Comments: The id number can be passed to call_proc() or call_func(), to > indirectly call the routine named by st. > > That doesn't really tell me what it does. It tells me what I get when I use > it. > > As an example: > > onClick[Button2] = routine_id( "onClick_Button2" ) > > I know that 'onClick_Button2' is a procedure that is previously defined. > > Apparently 'onClick' is a sequence and I am making some subscript of that > sequence equal to whatever number 'routine_id' spits out. > > I think that 'onClick' is probably defined in win32lib. Don't know for > sure. > > Shoot, for all I know I really want to know what "onClick[Whatever]" does or > perhaps "onKeyPress[Whatever]" I really don't know. > > But for now. > > > What EXACTLY does 'routine_id' do? > > Thank in advance for the several dozen answers I am sure to get from this. > > Glen > > > _________________________________________________________ > Do You Yahoo!? > Get your free @yahoo.com address at http://mail.yahoo.com >
10. routine_id
- Posted by Glen Brown <gbrown7777 at yahoo.com> Sep 19, 2000
- 476 views
Hello all, Just one quick question. What EXACTLY does 'routine_id' do? And please don't tell me to RTM. I have RTM an it says: Syntax: i = routine_id(st) Description: Return an integer id number, known as a routine id, for a user-defined Euphoria procedure or function. The name of the procedure or function is given by the string sequence st. -1 is returned if the named routine can't be found. Comments: The id number can be passed to call_proc() or call_func(), to indirectly call the routine named by st. That doesn't really tell me what it does. It tells me what I get when I use it. As an example: onClick[Button2] = routine_id( "onClick_Button2" ) I know that 'onClick_Button2' is a procedure that is previously defined. Apparently 'onClick' is a sequence and I am making some subscript of that sequence equal to whatever number 'routine_id' spits out. I think that 'onClick' is probably defined in win32lib. Don't know for sure. Shoot, for all I know I really want to know what "onClick[Whatever]" does or perhaps "onKeyPress[Whatever]" I really don't know. But for now. What EXACTLY does 'routine_id' do? Thank in advance for the several dozen answers I am sure to get from this. Glen _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com
11. Re: routine_id
- Posted by Glen Brown <gbrown7777 at YAHOO.COM> Sep 23, 2000
- 470 views
- Last edited Sep 24, 2000
Thanks Derek, <Snip> Hi Glen, just got home from work an see that no-one has responded yet, so I'll have a go. </Snip> Sorry this is not a prompt response. I have been a bit behind on reading the digests lately. I have read throug you response once and it looks very concise but I will have to read it again to really absorb what you are saying and see if I have any more questions. Thanks again. Glen _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com
12. Re: routine_id
- Posted by Jeffrey Fielding <JJProg at CYBERBURY.NET> Sep 10, 1998
- 521 views
You could use call_back, but you can only use it for one procedure ant it must tale 4 arguments (see library.doc). You could also write an assembly routine and poke it into memory, and make it change a variable (at some area of memory) when it is called. Then you just write a while loop, and check the variable until it changes (I guess).