Strange behavior of #printString method

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Strange behavior of #printString method

gerard alis
I don´t understand the behavior of printString method.

in a class I define a method #style , which returns an array...

style
       
        style notNil ifTrue:[ ^style ]
                                ifFalse:[ ^{ self borderColor . self borderWidth . self color . self gradientColor . (self cornerStyle = #rounded) . true  }].

That method returns many times an Array. If #printString of that array is called the result is...
'{Color black. 0. (Color r: 0.892 g: 0.887 b: 0.879). nil. false. true}'


Well i have another method with same name in another class

style
       
        ^{ self borderColor . self borderWidth . self color . self gradientColor . (self cornerStyle = #rounded) . true  }


but in that case when i call #printString of the Array result ...
'an Array(Color transparent 0 (Color r: 0.827 g: 0.827 b: 0.827) nil true true)'.

I don´t understand nothing :|  Both are instances of Array, and both is declared of same way.


Regards

Reply | Threaded
Open this post in threaded view
|

Re: Strange behavior of #printString method

Schwab,Wilhelm K
I am by no means the expert on such things, but you caught my attention and a quick look at Array>>printOn: reveals #isLiteral and #isSelfEvaluating.  The way an array prints itself changes if all of the arguments (and sometimes the receiver) fit the conditions.

One of your arguments is probably failing to meet a condition in one case.

Bill



-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of nullPointer
Sent: Tuesday, October 27, 2009 4:58 PM
To: [hidden email]
Subject: [Pharo-project] Strange behavior of #printString method


I don´t understand the behavior of printString method.

in a class I define a method #style , which returns an array...

style
       
        style notNil ifTrue:[ ^style ]
                                ifFalse:[ ^{ self borderColor . self borderWidth . self color . self gradientColor . (self cornerStyle = #rounded) . true  }].

That method returns many times an Array. If #printString of that array is called the result is...
'{Color black. 0. (Color r: 0.892 g: 0.887 b: 0.879). nil. false. true}'


Well i have another method with same name in another class

style
       
        ^{ self borderColor . self borderWidth . self color . self gradientColor .
(self cornerStyle = #rounded) . true  }


but in that case when i call #printString of the Array result ...
'an Array(Color transparent 0 (Color r: 0.827 g: 0.827 b: 0.827) nil true true)'.

I don´t understand nothing :|  Both are instances of Array, and both is declared of same way.


Regards


--
View this message in context: http://n2.nabble.com/Strange-behavior-of-printString-method-tp3902051p3902051.html
Sent from the Pharo Smalltalk mailing list archive at Nabble.com.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Strange behavior of #printString method

Stéphane Ducasse
In reply to this post by gerard alis
Apparently you find a problem in self evaluating on color or related.
Let me explain:

The idea of printing an object is that in some case
        anObject printString let you recreate the object
example

        1
        true
        #(1)
        #(1 2)
        10@50

this means that either you get the same object or when you executed  
its printed representation you get it back.
This is handy when playing with an inspector or in a workspace

now for array if you get an array of points in the past
printing it would return
        #(10 #@ 50 20 #@ 50)

which is different from what is was really
        {10@50 . 20@50}
        or Array new: 2 at:1 put: 10@50 ; at:2 put: 20@50

So when an object is selfevaluating it measn that its printed  
representation can be used to recreate it
When an array contains only self evaluating objects then it is printed  
with { } since it can also be recreated
now if you get an object inside an array taht is not self evaluating  
then your collection cannot be self evaluating.
so we say it anarray of ... instead of a #( 10 # @ 20....)

But in your case something went wrong because color and others are  
self evaluating.
could you provide with a snippet of code that we can check where the  
problem is coming from?

Stef


On Oct 27, 2009, at 10:58 PM, nullPointer wrote:

>
> I don´t understand the behavior of printString method.
>
> in a class I define a method #style , which returns an array...
>
> style
>
> style notNil ifTrue:[ ^style ]
> ifFalse:[ ^{ self borderColor . self borderWidth . self color .  
> self
> gradientColor . (self cornerStyle = #rounded) . true  }].
>
> That method returns many times an Array. If #printString of that  
> array is
> called the result is...
> '{Color black. 0. (Color r: 0.892 g: 0.887 b: 0.879). nil. false.  
> true}'
>
>
> Well i have another method with same name in another class
>
> style
>
> ^{ self borderColor . self borderWidth . self color . self  
> gradientColor .
> (self cornerStyle = #rounded) . true  }
>
>
> but in that case when i call #printString of the Array result ...
> 'an Array(Color transparent 0 (Color r: 0.827 g: 0.827 b: 0.827) nil  
> true
> true)'.
>
> I don´t understand nothing :|  Both are instances of Array, and both  
> is
> declared of same way.
>
>
> Regards
>
>
> --
> View this message in context: http://n2.nabble.com/Strange-behavior-of-printString-method-tp3902051p3902051.html
> Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-project] Strange behavior of #printString method

gerard alis
The problem is in the Transparent color element of the my bad array. Transparent color class implements #isSelfEvaluating of that way...

isSelfEvaluating
    ^ self class == Color

That condition dont works in the first element of my bad array.

Regards, and thanks for the help :|




2009/10/27 Stéphane Ducasse [via Smalltalk] <[hidden email]>
Apparently you find a problem in self evaluating on color or related.
Let me explain:

The idea of printing an object is that in some case
        anObject printString let you recreate the object
example

        1
        true
        #(1)
        #(1 2)
        10@50

this means that either you get the same object or when you executed  
its printed representation you get it back.
This is handy when playing with an inspector or in a workspace

now for array if you get an array of points in the past
printing it would return
        #(10 #@ 50 20 #@ 50)

which is different from what is was really
        {10@50 . 20@50}
        or Array new: 2 at:1 put: 10@50 ; at:2 put: 20@50

So when an object is selfevaluating it measn that its printed  
representation can be used to recreate it
When an array contains only self evaluating objects then it is printed  
with { } since it can also be recreated
now if you get an object inside an array taht is not self evaluating  
then your collection cannot be self evaluating.
so we say it anarray of ... instead of a #( 10 # @ 20....)

But in your case something went wrong because color and others are  
self evaluating.
could you provide with a snippet of code that we can check where the  
problem is coming from?

Stef


On Oct 27, 2009, at 10:58 PM, nullPointer wrote:

>
> I don´t understand the behavior of printString method.
>
> in a class I define a method #style , which returns an array...
>
> style
>
> style notNil ifTrue:[ ^style ]
> ifFalse:[ ^{ self borderColor . self borderWidth . self color .  
> self
> gradientColor . (self cornerStyle = #rounded) . true  }].
>
> That method returns many times an Array. If #printString of that  
> array is
> called the result is...
> '{Color black. 0. (Color r: 0.892 g: 0.887 b: 0.879). nil. false.  
> true}'
>
>
> Well i have another method with same name in another class
>
> style
>
> ^{ self borderColor . self borderWidth . self color . self  
> gradientColor .
> (self cornerStyle = #rounded) . true  }
>
>
> but in that case when i call #printString of the Array result ...
> 'an Array(Color transparent 0 (Color r: 0.827 g: 0.827 b: 0.827) nil  
> true
> true)'.
>
> I don´t understand nothing :|  Both are instances of Array, and both  
> is
> declared of same way.
>
>
> Regards
>
>
> --
> View this message in context: http://n2.nabble.com/Strange-behavior-of-printString-method-tp3902051p3902051.html
> Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project



View message @ http://n2.nabble.com/Strange-behavior-of-printString-method-tp3902051p3902115.html
To unsubscribe from Strange behavior of #printString method, click here.


Reply | Threaded
Open this post in threaded view
|

Re: Strange behavior of #printString method

Stéphane Ducasse
Ok can you open a ticket on the bugtracker with a description because  
this can be fixed easily

isSelf...
        ^ self isKindOf: Color?

> The problem is in the Transparent color element of the my bad array.  
> Transparent color class implements #isSelfEvaluating of that way...
>
> isSelfEvaluating
>     ^ self class == Color
>
> That condition dont works in the first element of my bad array.
>
> Regards, and thanks for the help :|
>
>
>
>
> 2009/10/27 Stéphane Ducasse [via Smalltalk] <[hidden email]>
> Apparently you find a problem in self evaluating on color or related.
> Let me explain:
>
> The idea of printing an object is that in some case
>         anObject printString let you recreate the object
> example
>
>         1
>         true
>         #(1)
>         #(1 2)
>         10@50
>
> this means that either you get the same object or when you executed
> its printed representation you get it back.
> This is handy when playing with an inspector or in a workspace
>
> now for array if you get an array of points in the past
> printing it would return
>         #(10 #@ 50 20 #@ 50)
>
> which is different from what is was really
>         {10@50 . 20@50}
>         or Array new: 2 at:1 put: 10@50 ; at:2 put: 20@50
>
> So when an object is selfevaluating it measn that its printed
> representation can be used to recreate it
> When an array contains only self evaluating objects then it is printed
> with { } since it can also be recreated
> now if you get an object inside an array taht is not self evaluating
> then your collection cannot be self evaluating.
> so we say it anarray of ... instead of a #( 10 # @ 20....)
>
> But in your case something went wrong because color and others are
> self evaluating.
> could you provide with a snippet of code that we can check where the
> problem is coming from?
>
> Stef
>
>
> On Oct 27, 2009, at 10:58 PM, nullPointer wrote:
>
> >
> > I don´t understand the behavior of printString method.
> >
> > in a class I define a method #style , which returns an array...
> >
> > style
> >
> > style notNil ifTrue:[ ^style ]
> > ifFalse:[ ^{ self borderColor . self borderWidth . self color .
> > self
> > gradientColor . (self cornerStyle = #rounded) . true  }].
> >
> > That method returns many times an Array. If #printString of that
> > array is
> > called the result is...
> > '{Color black. 0. (Color r: 0.892 g: 0.887 b: 0.879). nil. false.
> > true}'
> >
> >
> > Well i have another method with same name in another class
> >
> > style
> >
> > ^{ self borderColor . self borderWidth . self color . self
> > gradientColor .
> > (self cornerStyle = #rounded) . true  }
> >
> >
> > but in that case when i call #printString of the Array result ...
> > 'an Array(Color transparent 0 (Color r: 0.827 g: 0.827 b: 0.827) nil
> > true
> > true)'.
> >
> > I don´t understand nothing :|  Both are instances of Array, and both
> > is
> > declared of same way.
> >
> >
> > Regards
> >
> >
> > --
> > View this message in context: http://n2.nabble.com/Strange-behavior-of-printString-method-tp3902051p3902051.html
> > Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
> >
> > _______________________________________________
> > Pharo-project mailing list
> > [hidden email]
> > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
> View this message in context: Re: [Pharo-project] Strange behavior  
> of #printString method
> Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project