RE: built in routine id's

new topic     » goto parent     » topic index » view thread      » older message » newer message

When I originally posted about this, it was just a question, because I 
had assumed that I would be able to do it, and was puzzled why it wasn't 
possible, or maybe it was and I was just doing something wrong.

Now that I have looked and experimented I have 4 things to point out. 

1. The inconvenince of wrapping the builtin routines.
   So what, I can live with that, the chance that I will have to wrap 
every routine is very slim. And then in that case, I would make an 
include file, and would never need to do it again.

2. The extra overhead needed to call the wrappers which call the 
builtins.
   Anything that helps to optimize my code is a good thing.

3. You can't wrap routine_id()
   If I wrap routine_id(), the wrapper must be found after any routines 
that I need the routine_id for.

4. You can't wrap the builtins with the same name.
   The MAIN reason that I would want to override the name of a function, 
would be to change the functionality of a particular routine. Not 
rewrite it. Even with routine_id() for builtins, this wouldn't be 
possible; see #5.

5. If someone overrides a builtin, how can I use the original?
   This would require a special case when calling routine_id(). Perhaps 
something like equal_rID = routine_id("!equal").


If the concept of #5 were implemented, I could do stuff like this:

function gets(integer fn)
 object ret
   ret = gets(fn)
   if fn = 0 then
      if atom(ret) then return ret end if
      return ret[1..length(ret)-1]
   end if
   return ret
end function

Chris

Rolf Schröder wrote:
> 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
>  
> include misc.e  -- PI
> 	       .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
> --
>     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)
> 
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu