1

In Io, there is a getSlot() method which allows you to convert a string to a slot reference, but is there something similar to get a reference to an Object? For example:

myObject := Object clone
myObject myMethod := method("Hello World!" println)

targetObject := "myObject"
a := getObject(targetObject) clone

getObject() doesn't exist, so what can go in its place such that "a" ends up being a clone of "myObject"?

MidnightLightning
  • 6,715
  • 5
  • 44
  • 68

1 Answers1

4

You actually answered yourself!

In Io you have objects which have slots, and these slots can be objects themselves.
So for your code to work properly you simply call getSlot on the current scope.

myObject := Object clone
myObject myMethod := method("Hello World!" println)

targetObject := "myObject"
a := getSlot(targetObject) clone
a myMethod
==> Hello World!
locks
  • 6,537
  • 32
  • 39
  • Well that works; now to understand why... "getSlot" is being called with no target, so it fails over to "Object", which does have a "getSlot" method, though a "slotNames" listing doesn't show "myObject" as a slot name. The Lobby object does, but it doesn't have a "getSlot" method. So, because this works, Io is sending the "getSlot" message to the Lobby object, which inherits the Object method and applies it to itself, returning the proper object? – MidnightLightning Dec 09 '11 at 14:31
  • Io operates with a system called differential inheritance. That means, objects are described in ways that they are different. For instance, think of Dumbo. Everyone knows what an Elephant looks like, so to describe Dumbo, you just have to describe the differences: He wears a pink bow, has giant ears, is very short and flies. You can get a pretty good idea what Dumbo looks like. No different in Io's inheritance system. If you only want to check the local object, and nothing up the inheritance tree, use `getLocalSlot` instead. – jer Dec 09 '11 at 22:01