Re: Strange instance variable behaviour

  • From: "T W" <twellman@gmail.com>
  • To: users@ioke.kenai.com
  • Subject: Re: Strange instance variable behaviour
  • Date: Thu, 1 Jan 2009 20:44:48 -0800
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=h5kKvw9/L65cCevaI65ODWmjfSjrjO6OBK0sAALvKPf4w6Zfv8a9OxPkcun/QG7DlH LMuGDXLIi2DZ/lQHLPhWYGoPakIUNlBKbu8Xt40UY2voJPU95qpRPnwKnvm6qh+AVzNM KhPfy60aV4qFYQc7CNOgddCQ6BT97TPIL9kAg=

Accidentally did not hit "reply all" on the following message.



How would one achieve this?

That is, if the desired behavior is to have your Dog mimic set its
name separately, regardless of whether the cell("name") on Dog is set.

Just taking a stab at it, I'd override mimic on Dog to make mimics use
a different cell (like _name) for name.

iik> Dog cell("mimic") = method(newdog = Origin mimic
mimic!(surroundingContext Dog) . newdog cell("name=") =
method(new_name, self _name = new_name) . newdog cell("name") =
method(self _name) . newdog )
+> method(=(newdog, Origin mimic mimic!(surroundingContext Dog)) .
newdog =(cell("name="), method(new_name, self =(_name, new_name))) .
newdog =(cell("name"), method(self _name)) .
newdog)

iik> fluffy = Dog mimic

       +>  Origin_0x23D278:
 name                         = method(...)
 name=                        = method(...)


iik> Dog name
*** - couldn't find cell 'name' on 'Ground Dog_0x1CF4A2C' (Condition
Error NoSuchCell)

iik> Dog name = "woggy"
+> "woggy"

iik> fluffy name = "Fluffy"
+> "Fluffy"

iik> Dog name
+> "woggy"

iik> fluffy name
+> "Fluffy"


I'm unsure about this solution though. Is overriding mimic a good
idea, or is there a better way to do this kind of thing?


On Thu, Jan 1, 2009 at 7:39 AM, Ola Bini <ola.bini@gmail.com> wrote:
> Hendrik Volkmer wrote:
>>
>> Hi there,
>>
>> I've been playing around with ioke a little bit and came across this
>> behaviour which I don't quite understand:
>>
>> ---- start code ---
>> use("ispec")
>>
>> Dog = Origin mimic
>> Dog food = []
>> Dog name = ""
>>
>> Dog set_name = method(name,
>>  self name = name
>> )
>>
>> Dog feed = method("feeds the dog", food_item,
>>  self food << food_item
>>  )
>>
> Hi,
>
> The behavior you're seeing is because the name is set above. That will set
> the name of the dog on the new instance. The feeding process in contrast
> just adds an element to an existing list - this list comes from the Dog
> mimic, and is thus global for all of them.
>
> Cheers
>
> --
> Ola Bini (http://olabini.com) JRuby Core Developer
> Developer, ThoughtWorks Studios (http://studios.thoughtworks.com)
> Practical JRuby on Rails (http://apress.com/book/view/9781590598818)
>
> "Yields falsehood when quined" yields falsehood when quined.
>
>
>


Strange instance variable behaviour

Hendrik Volkmer 01/01/2009

Re: Strange instance variable behaviour

Ola Bini 01/01/2009

Message not available

Re: Strange instance variable behaviour

T W 01/02/2009

Re: Strange instance variable behaviour

Ola Bini 01/02/2009
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close