1. built in routine id's
- Posted by bensler at mail.com Mar 22, 2002
- 629 views
Why can't I get the routine id of a built in? ? routine_id("sequence") BTW: Did anyone else know they could get the routine_id() of a type? It is just a function after all, but it doesn't seem to be documented. Chris
2. Re: built in routine id's
- Posted by "Carl R. White" <euphoria at carlw.legend.uk.com> Mar 22, 2002
- 576 views
Chris Bensler wrote: > Why can't I get the routine id of a built in? > > ? routine_id("sequence") I agree with you on this one, which I admit isn't really like me when it comes to adding things to Euphoria. :) There is a workaround: global function s_(object o) return sequence(o) end if global constant sequence_id = routine_id("s_") -- now use 'sequence_id' instead of 'routine_id("sequence")' ...but using this means that call_func()'s are slower than they could be. Also, you have to write your own wrapper func/procs for every built-in you want to get the routine_id of. > BTW: > Did anyone else know they could get the routine_id() of a type? It is > just a function after all, but it doesn't seem to be documented. I did know this. It's all down to experimentation (which, IMHO, too many people don't do). It's also when I discovered that the built-in types and functions don't have their own routine_id's. Try this for madness. There's a quiz at the end so pay attention :) : type natural(object o) if integer(o) then return o >= 0 end if return 0 end type with trace trace(1) integer beeble_id type bobble(object o) if not natural(o) then return 0 end if return call_func(beeble_id, {o-1}) end type type beeble(object o) if not natural(o) then return 0 end if if not o then return 1 end if return bobble(o-1) end type beeble_id = routine_id("beeble") beeble a bobble b a = 4 b = 5 b *= b a = (b-1)/a ? a POP QUIZ: Do it on paper first before running it. Do the same again starting with a = 8. What happens in each case, and did it do what you expected? What are better names for beeble and bobble? (Hint: The second letter of each is a clue). beeble-bobble-beeble-bobble, ;) Carl
3. Re: built in routine id's
- Posted by Rolf Schröder <r.schr at t-online.de> Mar 23, 2002
- 546 views
Bernie Ryan wrote: > > > Chris: > Why would you need a routine_id of a built-in function > when you can over-ride any built-in function and replace > it or change something before or after calling it. > Bernie > Bernie, suppose you have a routine which needs a functions as parameter, i.e., a general function for integration of functions. The parameter to pass for the function to be integrated is the func_id parameter. So, how could you use this kind of routine to integrate build in functions? Any idea? Have a nice day, Rolf
4. Re: built in routine id's
- Posted by Rolf Schröder <r.schr at t-online.de> Mar 23, 2002
- 558 views
Bernie Ryan wrote: > > Rolf: > I do not understand your question. > Can you give me a simple example then maybe I can come > up with an idea. Bernie, enclosed an example. Each in build function has to be called via an extra user defined function to make it for the function 'qgauss' callable, like SIN instead sin. If you replace SIN by sin in the MAIN section you will get an error. I think, the build in functions/procedures should also freely be usable for routine_id() and call_func()/call_proc(). Have a nice day, Rolf ---------------------------------------------------------------------- -- 10 point Gauss integration of 'func' over interval (a,b). -- (after 'Numerical Recipes (FORTRAN), W.H.Press et al., 1988, p122) ---------------------------------------------------------------------- include misc.e -- PI ---------------------------------------------------------------------- constant X = { .1488743389, .4333953941, .6794095682, .8650633666, .9739065285} constant W = { .2955242247, .2692667193, .2190863625, .1494513491, .0666713443} ---------------------------------------------------------------------- function SIN(atom x) -- equivalent of build in sin() -- *** return sin(x) end function ---------------------------------------------------------------------- function quad(atom x) -- x^2 -- **** return x*x end function ---------------------------------------------------------------------- function qgauss(sequence func, atom a, atom b) -- ****** atom xm, xr, ss, dx integer id id = routine_id(func) xm = (b+a)/2 xr = (b-a)/2 ss = 0.0 for j = 1 to 5 do dx = xr*X[j] ss += W[j]*(call_func(id,{xm+dx})+call_func(id,{xm-dx})) end for return xr*ss end function ---------------------------------------------------------------------- -- MAIN program area: examples for qgauss() function. -- **** -- Nunerical integration of sin(x) over (0,PI) and x*x over (0,3). -- printf(1,"I(sin)[0,PI] = %15.10f (2 exactly)\n\n", qgauss("SIN",0,PI)) printf(1,"I(x*x)[0,3] = %15.10f (9 exactly)\n", qgauss("quad",0,3)) abort(0) ----------------------------------------------------------------------