Set the value of an object from inside a method in Io -


i'm trying set value of object inside method. here's example:

myobject := list(1,2,3,4,5)  myobject drop := method(     self := list() )  myobject drop myobject println //returns original object 

what doing wrong?

what you've done create new slot inside method , named self. means goes away when method returns. in io self isn't keyword, there no keywords, , doesn't have special meaning.

what you're looking use method modifies self. since list written in c, you'd have interface directly written in c, or interfaces written in c, clear contents of list. consider:

myobject drop := method(     self empty ) 

what's going on here list has method named empty removes items , returns empty object. talks primitive list method called removeall accomplish this.

this bit cut , dry though. in general case, in other circumstances, may want save item want return before remove collection. i.e.,

mycollection drop := method(     result := self at(42)     self removeallthethings     result ) 

since not every type of collection exist, have removeall or empty method built in.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -