Re: there is a subtle problem doing: mySlot := obj getSlot(slotname)

gatesphere <[email protected]>
Newsgroups gmane.comp.lang.io
Message-ID <[email protected]>
Try this:
checkObjectMessage := method(obj, slotname,
   slot := obj getSlot(slotname) asString;
   "name: " print; slotname print; "." println;
   "slot: " print; obj getSlot(slotname) print; "." println;
   "slot: " print; slot print; "." println;
    self
)

That works for me.

-->Jake

On 11/8/2011 7:30 AM, Mildred Ki'Lya wrote:
>
> Hi,
>
> I like static typing a lit, and I thought ... why not implement a 
> layer of static typing in Io directly. I could run a compilation stage 
> just before running the main program and check typing errors using the 
> wonderful Io introspection features. Note: this is my code that I 
> write in Io.
>
> At some point, I need to check a method implementation against an 
> interface. To do that, I need to find the method implementation in an 
> object. To do that, i'm using getSlot to do something like:
>
>   checkObjectMessage := method(obj, slotname, returnInterface, args,
>     # Find the message implementation
>     slot := obj getSlot(slotname)
>     "name: " print; slotname print; "." println
>     "slot: " print; obj getSlot(slotname) print; "." println
>     "slot: " print; slot print; "." println
>     # TODO: iterate over all instructions, and check each instruction 
> is legal
>     self
>   )
>
> You can see few print messages ... this is for debug. When I run this 
> code, I get a difference between the first "slot:" printed line, and 
> the second "slot:" printed line. The first displays the code of the 
> method, something like:
>
> slot:
> # /home/shanti/Perso/io/libs/iovm/io/A2_Object.io:461
> method(
>     getSlot("self") print; write("\n"); getSlot("self")
> )
> .
>
> This is expected. But then the second line shows:
>
> slot: Object_0x98778f8 do(
>   appendProto(Object_0x985c7a0)
>
> Object_0x98778f8 do(
>   appendProto(Object_0x985c7a0)
> .
>
> Apparently the local variable "slot" is being assigned to a method ... 
> and whel looking up this variable, the method is called. I suppose I 
> should do getSlot("slot") to do the trick. I was wondering if there 
> was a way to store a Block object in a variable, and be able to access 
> this variable in any other way than getSlot("varname").
>
> And, I think this should be added to the pitfalls page, unless I 
> missed something.
>
> Thank you,
>
> Mildred
>
> -- 
> Mildred Ki'Lya
> http://mildred.fr
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.