Re: built in routine id's

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

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

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

Search



Quick Links

User menu

Not signed in.

Misc Menu