3

I was poking around some of Core and Object using "getSlot("method name") to see how some foundational methods were implemented. I was curious about how the if method was written and tried

Io> Object getSlot("if")
==> Object_if()
Io> Object getSlot("Object_if()")
==> nil

Neither of these were informative. Is there a way to reflect/inspect/print this (and other Object_keywordishword() words)?

labyrinth
  • 13,397
  • 7
  • 35
  • 44

1 Answers1

9

I gave a talk to a group in New York a while back which included a cleanroom implementation of if if you're curious about the mechanics. You can see it here.

More directly, when you see:

==> Object_if()

In the REPL, what that's telling you is that if is a symbol bound to the object Object which is implemented in C. That is to say, the "method" is actually a CFunction object, and not a Block object. Only Block objects show their source in the REPL.

jer
  • 20,094
  • 5
  • 45
  • 69
  • 2
    Wow, I got a reply from the famous Jeremy Tregunna! I'm never again washing or changing the shirt I wore when I read this reply. It's pretty cool that you can see the inner workings of almost all methods right in the REPL--I'm glad to know I can look at the C code if I get really curious about the few that don't show in the REPL. – labyrinth Dec 02 '13 at 23:22