Overcomer Man | 4 Jan 02:29 2012
Picon

ROS (Robot Operating System)

Recent posts on time measurement led to thinking the Willow Garage ROS project could be translated to Squeak / Cuis.  Here's the website http://www.ros.org/wiki/

Anyone interested in collaborating?  I'm for using Cuis with the latest VM.
_______________________________________________
Beginners mailing list
Beginners <at> lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Ben Coman | 4 Jan 12:21 2012

Enumeration type implementation

(Resending since it didn't show up on the list overnight)

What is the best way to implement "enumerations" in Smalltalk. For 
instance, for a UML definition of...
<<enumeration>> Currency
  <<enum>> USD   'US dollar'
  <<enum>> EUR   'Eueropean euro'
  <<enum>> AUD    'Australian dollar'

here is my guess, consisting of 2 instance side methods and 3 class side 
methods...
-------------------------
Object subclass: #EpcimCurrency
   instanceVariableNames: 'value'
   classVariableNames: ''
   poolDictionaries: ''
   category: 'IEC61970-Domain-Enumerations'

EpcimCurrency >> value: aCurrency
   ( (self class) validate: aCurrency) ifTrue:
       [ value := aCurrency
       ].

EpcimCurrency >> value
   ^value
-----------------------------------

EpcimCurrency class
   instanceVariableNames: 'enums'

EpcimCurrency class >> validate: aString
   enums ifNil: [ self initialize ].
   ^ enums includesKey: aString.

EpcimCurrency class >>  enums   "for displaying in pulldown menus"
   enums ifNil: [ self initialize ].
   ^enums copy

EpcimCurrency class >> initalize
   (enums := Dictionary new)
               add: 'USD'-> 'US dollar' ;
               add: 'EUR'-> 'European euro' ;
               add: 'AUD'-> 'Australian dollar' ;
               add: 'CAD'-> 'Canadian dollar' ;
               add: 'CHF'-> 'Swiss francs' ;
               add: 'CNY'-> 'Chinese yuan renminbi' ;
               add: 'DKK'-> 'Danish crown' ;
               add: 'GBP'-> 'British pound' ;
               add: 'JPY'-> 'Japanese yen' ;
               add: 'NOK'-> 'Norwegian crown' ;
               add: 'RUR'-> 'Russian ruble' ;
               add: 'SEK'-> 'Swedish crown' ;
               add: 'INR'-> 'India rupees' ;
               add: 'other'-> 'Another type of currency' .
----------------------
Examples
   " (EpcimCurrency new value: 'AUD' ) value inspect  "      ----> 'AUD'
   " (EpcimCurrency new value: 'XXX') value  inspect  "      ----> nil
   " EpcimCurrency initialize  "
   " EpcimCurrency enums inspect "   ---> aDictionary
------
The other way I thought might be like `Color blue`, but I'm not sure what is gained.

Your feedback would be appreciated.
Ralph Johnson | 4 Jan 12:33 2012
Picon

Re: Enumeration type implementation

That is not bad.   However, EpcimCurrency needs more behavior on the
instance side.   In particular, a currency should know both its name
and its description.   i think "value" is just the name.   The
dictionary should map names to currencies instead of names to strings
(or descriptions), and the instance should have instance variables
"name" and "description" instead of "value".   If you do it this way
then there will only be one instance of each currency and checking for
equality will be very easy.  But the overall design is on target.

On Wed, Jan 4, 2012 at 5:21 AM, Ben Coman <btc <at> openinworld.com> wrote:
> (Resending since it didn't show up on the list overnight)
>
> What is the best way to implement "enumerations" in Smalltalk. For instance,
> for a UML definition of...
> <<enumeration>> Currency
>  <<enum>> USD   'US dollar'
>  <<enum>> EUR   'Eueropean euro'
>  <<enum>> AUD    'Australian dollar'
>
> here is my guess, consisting of 2 instance side methods and 3 class side
> methods...
> -------------------------
> Object subclass: #EpcimCurrency
>  instanceVariableNames: 'value'
>  classVariableNames: ''
>  poolDictionaries: ''
>  category: 'IEC61970-Domain-Enumerations'
>
> EpcimCurrency >> value: aCurrency
>  ( (self class) validate: aCurrency) ifTrue:
>      [ value := aCurrency
>      ].
>
> EpcimCurrency >> value
>  ^value
> -----------------------------------
>
> EpcimCurrency class
>  instanceVariableNames: 'enums'
>
> EpcimCurrency class >> validate: aString
>  enums ifNil: [ self initialize ].
>  ^ enums includesKey: aString.
>
> EpcimCurrency class >>  enums   "for displaying in pulldown menus"
>  enums ifNil: [ self initialize ].
>  ^enums copy
>
> EpcimCurrency class >> initalize
>  (enums := Dictionary new)
>              add: 'USD'-> 'US dollar' ;
>              add: 'EUR'-> 'European euro' ;
>              add: 'AUD'-> 'Australian dollar' ;
>              add: 'CAD'-> 'Canadian dollar' ;
>              add: 'CHF'-> 'Swiss francs' ;
>              add: 'CNY'-> 'Chinese yuan renminbi' ;
>              add: 'DKK'-> 'Danish crown' ;
>              add: 'GBP'-> 'British pound' ;
>              add: 'JPY'-> 'Japanese yen' ;
>              add: 'NOK'-> 'Norwegian crown' ;
>              add: 'RUR'-> 'Russian ruble' ;
>              add: 'SEK'-> 'Swedish crown' ;
>              add: 'INR'-> 'India rupees' ;
>              add: 'other'-> 'Another type of currency' .
> ----------------------
> Examples
>  " (EpcimCurrency new value: 'AUD' ) value inspect  "      ----> 'AUD'
>  " (EpcimCurrency new value: 'XXX') value  inspect  "      ----> nil
>  " EpcimCurrency initialize  "
>  " EpcimCurrency enums inspect "   ---> aDictionary
> ------
> The other way I thought might be like `Color blue`, but I'm not sure what is
> gained.
>
> Your feedback would be appreciated.
>
>
> _______________________________________________
> Beginners mailing list
> Beginners <at> lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
Göran Krampe | 4 Jan 13:01 2012
Picon

Re: Enumeration type implementation

I would in this case use a so called SharedPool. If you are using Squeak 
then take for example a look at GZipConstants (inherits from SharedPool, 
has classVariablesNames for each key, initialize them in class side 
initialize method) and a use of it in GZipReadStream (it just lists it 
in the class definition under poolDictionaries: and then just use those 
keys directly as if they were globals.

regards, Göran
Göran Krampe | 4 Jan 13:04 2012
Picon

Re: Enumeration type implementation

On 01/04/2012 01:01 PM, Göran Krampe wrote:
> I would in this case use a so called SharedPool. If you are using Squeak
> then take for example a look at GZipConstants (inherits from SharedPool,
> has classVariablesNames for each key, initialize them in class side
> initialize method) and a use of it in GZipReadStream (it just lists it
> in the class definition under poolDictionaries: and then just use those
> keys directly as if they were globals.

And another idea is to extend Number with one method for each currency 
so that you can use them just like you can use "seconds" or "minutes" today:

5 minutes

10 USD

regards, Göran
Jan Teske | 4 Jan 16:44 2012
Picon

Changing the extent of an ImageMorph

Hey,

I'm currently developing a small game with Squeak. Part of it is a bunch 
of menus which should have background images. Therefore I have realized 
them as ImageMorphs with the respective images.
Now, there are menus which sizes are determined dynamically during the 
runtime of the game. That means I have to change the size of the menus. 
Since I cannot do this by manipulating 'menu extent: ...' directly, the 
only way I found until now is to manipulate the image form 'menu image: 
menu image scaledToSize: ...'. That works pretty well except for one 
thing: I cannot change the aspect ration of the original image with 
scaledToSize:. Since I do not know the extends of my menus before the 
game starts, I cannot say anything about the needed image ratio. Since 
my menus should be as applicable as possible I need to be able to resize 
also in a way which destroys the original scales.

Is there any easy workaround for my problem or a recommended way for 
creating resizable Morphs with background images?

Thanks in advance!
karl ramberg | 4 Jan 16:59 2012
Picon

Re: Changing the extent of an ImageMorph

A SketchMorph lets you set the extent directly


Karl

On Wed, Jan 4, 2012 at 4:44 PM, Jan Teske <jan.teske <at> student.hpi.uni-potsdam.de> wrote:
Hey,

I'm currently developing a small game with Squeak. Part of it is a bunch of menus which should have background images. Therefore I have realized them as ImageMorphs with the respective images.
Now, there are menus which sizes are determined dynamically during the runtime of the game. That means I have to change the size of the menus. Since I cannot do this by manipulating 'menu extent: ...' directly, the only way I found until now is to manipulate the image form 'menu image: menu image scaledToSize: ...'. That works pretty well except for one thing: I cannot change the aspect ration of the original image with scaledToSize:. Since I do not know the extends of my menus before the game starts, I cannot say anything about the needed image ratio. Since my menus should be as applicable as possible I need to be able to resize also in a way which destroys the original scales.

Is there any easy workaround for my problem or a recommended way for creating resizable Morphs with background images?

Thanks in advance!
_______________________________________________
Beginners mailing list
Beginners <at> lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
Beginners <at> lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Ben Coman | 3 Jan 18:08 2012

Float variableWordSubclass

When I define...
    Float subclass: MyPrefixFloat

why does it get changed to...
    Float variableWordSubclass: #MyPrefixFloat

and is that just what the Epsilon symbol next to the class is?

cheers, Ben

btw, the reason I am doing this is to simplify automating the import of 
a UML model with a standard prefix for all classes including this 
"primitive"
Ben Coman | 3 Jan 19:35 2012

Enumeration "type" implementation

What is the best way to implement "enumerations" in Smalltalk. For 
instance, for a UML definition of...
<<enumeration>> Currency
   <<enum>> USD   'US dollar'
   <<enum>> EUR   'Eueropean euro'
   <<enum>> AUD    'Australian dollar'

here is my guess, consisting of 2 instance side methods and 3 class side 
methods...
-------------------------
Object subclass: #EpcimCurrency
    instanceVariableNames: 'value'
    classVariableNames: ''
    poolDictionaries: ''
    category: 'IEC61970-Domain-Enumerations'

EpcimCurrency >> value: aCurrency
    ( (self class) validate: aCurrency) ifTrue:
        [ value := aCurrency
        ].

EpcimCurrency >> value
    ^value
-----------------------------------

EpcimCurrency class
    instanceVariableNames: 'enums'

EpcimCurrency class >> validate: aString
    enums ifNil: [ self initialize ].
    ^ enums includesKey: aString.

EpcimCurrency class >>  enums   "for displaying in pulldown menus"
    enums ifNil: [ self initialize ].
    ^enums copy

EpcimCurrency class >> initalize
    (enums := Dictionary new)
                add: 'USD'-> 'US dollar' ;
                add: 'EUR'-> 'European euro' ;
                add: 'AUD'-> 'Australian dollar' ;
                add: 'CAD'-> 'Canadian dollar' ;
                add: 'CHF'-> 'Swiss francs' ;
                add: 'CNY'-> 'Chinese yuan renminbi' ;
                add: 'DKK'-> 'Danish crown' ;
                add: 'GBP'-> 'British pound' ;
                add: 'JPY'-> 'Japanese yen' ;
                add: 'NOK'-> 'Norwegian crown' ;
                add: 'RUR'-> 'Russian ruble' ;
                add: 'SEK'-> 'Swedish crown' ;
                add: 'INR'-> 'India rupees' ;
                add: 'other'-> 'Another type of currency' .
----------------------
    " (EpcimCurrency new value: 'AUD' ) value inspect  "      ----> 'AUD'
    " (EpcimCurrency new value: 'XXX') value  inspect  "      ----> nil
    " EpcimCurrency initialize  "
    " EpcimCurrency enums inspect "   ---> aDictionary

Any suggestions
Edwin Castro | 4 Jan 19:50 2012
Picon

Re: Enumeration type implementation

In addition, you might consider using symbols for the name rather than strings.

On Wed, Jan 4, 2012 at 3:33 AM, Ralph Johnson <johnson <at> cs.uiuc.edu> wrote:
That is not bad.   However, EpcimCurrency needs more behavior on the
instance side.   In particular, a currency should know both its name
and its description.   i think "value" is just the name.   The
dictionary should map names to currencies instead of names to strings
(or descriptions), and the instance should have instance variables
"name" and "description" instead of "value".   If you do it this way
then there will only be one instance of each currency and checking for
equality will be very easy.  But the overall design is on target.

On Wed, Jan 4, 2012 at 5:21 AM, Ben Coman <btc <at> openinworld.com> wrote:
> (Resending since it didn't show up on the list overnight)
>
> What is the best way to implement "enumerations" in Smalltalk. For instance,
> for a UML definition of...
> <<enumeration>> Currency
>  <<enum>> USD   'US dollar'
>  <<enum>> EUR   'Eueropean euro'
>  <<enum>> AUD    'Australian dollar'
>
> here is my guess, consisting of 2 instance side methods and 3 class side
> methods...
> -------------------------
> Object subclass: #EpcimCurrency
>  instanceVariableNames: 'value'
>  classVariableNames: ''
>  poolDictionaries: ''
>  category: 'IEC61970-Domain-Enumerations'
>
> EpcimCurrency >> value: aCurrency
>  ( (self class) validate: aCurrency) ifTrue:
>      [ value := aCurrency
>      ].
>
> EpcimCurrency >> value
>  ^value
> -----------------------------------
>
> EpcimCurrency class
>  instanceVariableNames: 'enums'
>
> EpcimCurrency class >> validate: aString
>  enums ifNil: [ self initialize ].
>  ^ enums includesKey: aString.
>
> EpcimCurrency class >>  enums   "for displaying in pulldown menus"
>  enums ifNil: [ self initialize ].
>  ^enums copy
>
> EpcimCurrency class >> initalize
>  (enums := Dictionary new)
>              add: 'USD'-> 'US dollar' ;
>              add: 'EUR'-> 'European euro' ;
>              add: 'AUD'-> 'Australian dollar' ;
>              add: 'CAD'-> 'Canadian dollar' ;
>              add: 'CHF'-> 'Swiss francs' ;
>              add: 'CNY'-> 'Chinese yuan renminbi' ;
>              add: 'DKK'-> 'Danish crown' ;
>              add: 'GBP'-> 'British pound' ;
>              add: 'JPY'-> 'Japanese yen' ;
>              add: 'NOK'-> 'Norwegian crown' ;
>              add: 'RUR'-> 'Russian ruble' ;
>              add: 'SEK'-> 'Swedish crown' ;
>              add: 'INR'-> 'India rupees' ;
>              add: 'other'-> 'Another type of currency' .
> ----------------------
> Examples
>  " (EpcimCurrency new value: 'AUD' ) value inspect  "      ----> 'AUD'
>  " (EpcimCurrency new value: 'XXX') value  inspect  "      ----> nil
>  " EpcimCurrency initialize  "
>  " EpcimCurrency enums inspect "   ---> aDictionary
> ------
> The other way I thought might be like `Color blue`, but I'm not sure what is
> gained.
>
> Your feedback would be appreciated.
>
>
> _______________________________________________
> Beginners mailing list
> Beginners <at> lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
_______________________________________________
Beginners mailing list
Beginners <at> lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners



--
Edwin G. Castro

_______________________________________________
Beginners mailing list
Beginners <at> lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners

Gmane