[squeak-dev] satisfying:do:ifAbsent: (for msg 7 of Re: Squeak-dev Digest, Vol 197, Issue 25))

Jim Sawyer jas at cruzio.com
Tue May 21 01:32:46 UTC 2019


#findLast:  is a bit of a misnomer for this.

An intention revealing selector might be #satisfying:do:ifAbsent:

or (even longer) #elementsSatisfying:do:ifAbsent:.

with usage for your case

     last := collection elementsSatisfying: discriminator do: a1block 
ifAbsent: [nil].
     any := last notNil.

and implemented something like

     >>elementsSatisfying: discriminator do: a1block ifAbsent: exceptional
         | last |
         self do: [:each|
                        (discriminator value: each) ifTrue: [a1block 
value: (last := each)]
                       ].
         ^last orIfNil: [exceptional value]

-Jim

On 5/16/2019 8:13 AM, squeak-dev-request at lists.squeakfoundation.org wrote:
> Send Squeak-dev mailing list submissions to
> 	squeak-dev at lists.squeakfoundation.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/squeak-dev
> or, via email, send a message with subject or body 'help' to
> 	squeak-dev-request at lists.squeakfoundation.org
>
> You can reach the person managing the list at
> 	squeak-dev-owner at lists.squeakfoundation.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Squeak-dev digest..."
>
>
> Today's Topics:
>
>     1. Re:  The Inbox: Graphics-nice.407.mcz (Nicolas Cellier)
>     2. Re:  The Inbox: Graphics-nice.407.mcz (Marcel Taeumel)
>     3.  The Inbox: Graphics-nice.408.mcz (commits at source.squeak.org)
>     4. Re:  The Inbox: Graphics-nice.407.mcz (Nicolas Cellier)
>     5. Re:  The Inbox: Graphics-nice.407.mcz (Stéphane Rollandin)
>     6. Re:  The Inbox: Graphics-nice.407.mcz (Stéphane Rollandin)
>     7. Re:  Boolean whenTrue:whenFalse: (Torge Husfeldt)
>     8. Re:  Boolean whenTrue:whenFalse: (Nicolas Cellier)
>     9. Re:  Boolean whenTrue:whenFalse: (Torge Husfeldt)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 16 May 2019 14:19:16 +0200
> From: Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com>
> To: The general-purpose Squeak developers list
> 	<squeak-dev at lists.squeakfoundation.org>
> Subject: Re: [squeak-dev] The Inbox: Graphics-nice.407.mcz
> Message-ID:
> 	<CAKnRiT6r8T6YG3TOUmRdWru9aTje2zQJqd8W99qQ7vzi4FttBA at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Le jeu. 16 mai 2019 à 13:54, Marcel Taeumel <marcel.taeumel at hpi.de> a
> écrit :
>
>> Hi Nicolas,
>>
>> it would be nice to see more named colors in the image. The user-interface
>> themes introduce color names for Monokai and Solarized etc. I sneaked some
>> crayons into Color itself. I think that "Color crayon blueberry" would be
>> acceptable to hide a factory or something similar.
>>
>> However:
>>
>> [Color fromString: '#99FFFF'] bench '481,000 per second. 2.08 microseconds
>> per run.'
>> [Color r: 102/255 g: 1.0 b: 1.0] bench '2,520,000 per second. 397
>> nanoseconds per run.'
>>
>> ;-)
>>
>> Best,
>> Marcel
>>
> Yes,
> I also forgot two conflicts
>
> (Color colorNames reject: [:sym | (Color perform: sym) name = sym])
> collect: [:sym | sym -> (Color perform: sym) name].
>   {#cantaloupe->#lightOrange . #maraschino->#red}
>
> For having more colorNames, it's better to change ColorName>>#name strategy
> first
>
> Am 16.05.2019 13:02:44 schrieb commits at source.squeak.org <
>> commits at source.squeak.org>:
>> Nicolas Cellier uploaded a new version of Graphics to project The Inbox:
>> http://source.squeak.org/inbox/Graphics-nice.407.mcz
>>
>> ==================== Summary ====================
>>
>> Name: Graphics-nice.407
>> Author: nice
>> Time: 16 May 2019, 1:01:07.687487 pm
>> UUID: 0c370e95-c3cf-5e44-9eb5-b81fb1ebf424
>> Ancestors: Graphics-mt.406
>>
>> I see that Marcel used something like
>> https://gist.github.com/haggen/c91ed87700e5971f6fc6
>>
>> I propose to reduce crayon shades overlapping by adopting different
>> references
>>
>> blueberry
>> (Encycolorpedia) https://encycolorpedia.com/4f86f7
>> (Crayola) https://en.wikipedia.org/wiki/List_of_Crayola_crayon_colors
>> ice (Corel ice blue) https://en.wikipedia.org/wiki/Shades_of_blue#Ice_blue
>> lemon
>> (Encycolorpedia lemon) https://encycolorpedia.com/fff700
>> (Encycolorpedia lemon yellow)
>> https://en.wikipedia.org/wiki/Lemon_(color)#Lemon_yellow
>> (Crayola lemon) https://en.wikipedia.org/wiki/Shades_of_yellow#Lemon
>> licorice (Crayola-Encycolorpedia)
>> https://en.wikipedia.org/wiki/Shades_of_black#Licorice
>> snow
>> (Encycolorpedia) https://encycolorpedia.com/fffafa
>> (X11) https://en.wikipedia.org/wiki/Shades_of_white#Snow
>> spring (X11 spring green) https://en.wikipedia.org/wiki/Spring_green
>> turquoise (X11-Encycolorpedia)
>> https://en.wikipedia.org/wiki/Shades_of_cyan#Turquoise
>>
>> Or should we have sort of factories?
>> (Color x11 turquoise vs Color macCrayon turquoise)
>>
>> Of course, it opens some sort of big can:
>> https://encycolorpedia.com/named
>> https://en.wikipedia.org/wiki/X11_color_names
>> https://en.wikipedia.org/wiki/List_of_colors_(compact)
>>
>> =============== Diff against Graphics-mt.406 ===============
>>
>> Item was changed:
>> ----- Method: Color class>>blueberry (in category 'named colors -
>> crayons') -----
>> blueberry
>>
>> + ^ Color fromString: '#4F86F7'!
>> - ^ Color r: 0.0 g: 0.0 b: 1.0!
>>
>> Item was changed:
>> ----- Method: Color class>>ice (in category 'named colors - crayons') -----
>> ice
>>
>> + ^ Color fromString: '#99FFFF'!
>> - ^ Color r: 102/255 g: 1.0 b: 1.0!
>>
>> Item was changed:
>> ----- Method: Color class>>lemon (in category 'named colors - crayons')
>> -----
>> lemon
>>
>> + ^ Color fromString: '#FFF700'!
>> - ^ Color r: 1.0 g: 1.0 b: 0.0!
>>
>> Item was changed:
>> ----- Method: Color class>>licorice (in category 'named colors - crayons')
>> -----
>> licorice
>>
>> + ^ Color fromString: '#1A1110'!
>> - ^ Color r: 0.0 g: 0.0 b: 0.0!
>>
>> Item was changed:
>> ----- Method: Color class>>snow (in category 'named colors - crayons')
>> -----
>> snow
>>
>> + ^ self fromString: '#FFFAFA'!
>> - ^ Color r: 1.0 g: 1.0 b: 1.0!
>>
>> Item was changed:
>> ----- Method: Color class>>spring (in category 'named colors - crayons')
>> -----
>> spring
>>
>> + ^ self fromString: '#00FF7F'!
>> - ^ Color r: 0.0 g: 1.0 b: 0.0!
>>
>> Item was changed:
>> ----- Method: Color class>>turquoise (in category 'named colors -
>> crayons') -----
>> turquoise
>>
>> + ^ self fromString: '#40E0D0'!
>> - ^ Color r: 0.0 g: 1.0 b: 1.0!
>>
>>
>>
>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190516/c17506b7/attachment-0001.html>
>
> ------------------------------
>
> Message: 2
> Date: Thu, 16 May 2019 14:49:51 +0200
> From: Marcel Taeumel <marcel.taeumel at hpi.de>
> To: John Pfersich via Squeak-dev
> 	<squeak-dev at lists.squeakfoundation.org>
> Subject: Re: [squeak-dev] The Inbox: Graphics-nice.407.mcz
> Message-ID: <5c96a487-cedb-419c-a137-6b92bef5a828 at getmailbird.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hi Nicolas,
>
> considering the factory approach (e.g., "Color crayon blueberry"), you could easily produce NamedColor (as subclass of Color with a name). Not sure about adding a name directly to Color, though....
>
> Best,
> Marcel
> Am 16.05.2019 14:20:24 schrieb Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com>:
>
>
> Le jeu. 16 mai 2019 à 13:54, Marcel Taeumel <marcel.taeumel at hpi.de [mailto:marcel.taeumel at hpi.de]> a écrit :
>
> Hi Nicolas,
>
> it would be nice to see more named colors in the image. The user-interface themes introduce color names for Monokai and Solarized etc. I sneaked some crayons into Color itself. I think that "Color crayon blueberry" would be acceptable to hide a factory or something similar.
>
> However:
>
> [Color fromString: '#99FFFF'] bench '481,000 per second. 2.08 microseconds per run.'
> [Color r: 102/255 g: 1.0 b: 1.0] bench '2,520,000 per second. 397 nanoseconds per run.'
>
> ;-)
>
> Best,
> Marcel
>
> Yes,
>
> I also forgot two conflicts
>
> (Color colorNames reject: [:sym | (Color perform: sym) name = sym])
> collect: [:sym | sym -> (Color perform: sym) name].
>   {#cantaloupe->#lightOrange . #maraschino->#red}
>
> For having more colorNames, it's better to change ColorName>>#name strategy first
>
>
> Am 16.05.2019 13:02:44 schrieb commits at source.squeak.org [mailto:commits at source.squeak.org] <commits at source.squeak.org [mailto:commits at source.squeak.org]>:
> Nicolas Cellier uploaded a new version of Graphics to project The Inbox:
> http://source.squeak.org/inbox/Graphics-nice.407.mcz [http://source.squeak.org/inbox/Graphics-nice.407.mcz]
>
> ==================== Summary ====================
>
> Name: Graphics-nice.407
> Author: nice
> Time: 16 May 2019, 1:01:07.687487 pm
> UUID: 0c370e95-c3cf-5e44-9eb5-b81fb1ebf424
> Ancestors: Graphics-mt.406
>
> I see that Marcel used something like
> https://gist.github.com/haggen/c91ed87700e5971f6fc6 [https://gist.github.com/haggen/c91ed87700e5971f6fc6]
>
> I propose to reduce crayon shades overlapping by adopting different references
>
> blueberry
> (Encycolorpedia) https://encycolorpedia.com/4f86f7 [https://encycolorpedia.com/4f86f7]
> (Crayola) https://en.wikipedia.org/wiki/List_of_Crayola_crayon_colors [https://en.wikipedia.org/wiki/List_of_Crayola_crayon_colors]
> ice (Corel ice blue) https://en.wikipedia.org/wiki/Shades_of_blue#Ice_blue [https://en.wikipedia.org/wiki/Shades_of_blue#Ice_blue]
> lemon
> (Encycolorpedia lemon) https://encycolorpedia.com/fff700 [https://encycolorpedia.com/fff700]
> (Encycolorpedia lemon yellow) https://en.wikipedia.org/wiki/Lemon_(color)#Lemon_yellow [https://en.wikipedia.org/wiki/Lemon_(color)#Lemon_yellow]
> (Crayola lemon) https://en.wikipedia.org/wiki/Shades_of_yellow#Lemon [https://en.wikipedia.org/wiki/Shades_of_yellow#Lemon]
> licorice (Crayola-Encycolorpedia) https://en.wikipedia.org/wiki/Shades_of_black#Licorice [https://en.wikipedia.org/wiki/Shades_of_black#Licorice]
> snow
> (Encycolorpedia) https://encycolorpedia.com/fffafa [https://encycolorpedia.com/fffafa]
> (X11) https://en.wikipedia.org/wiki/Shades_of_white#Snow [https://en.wikipedia.org/wiki/Shades_of_white#Snow]
> spring (X11 spring green) https://en.wikipedia.org/wiki/Spring_green [https://en.wikipedia.org/wiki/Spring_green]
> turquoise (X11-Encycolorpedia) https://en.wikipedia.org/wiki/Shades_of_cyan#Turquoise [https://en.wikipedia.org/wiki/Shades_of_cyan#Turquoise]
>
> Or should we have sort of factories?
> (Color x11 turquoise vs Color macCrayon turquoise)
>
> Of course, it opens some sort of big can:
> https://encycolorpedia.com/named [https://encycolorpedia.com/named]
> https://en.wikipedia.org/wiki/X11_color_names [https://en.wikipedia.org/wiki/X11_color_names]
> https://en.wikipedia.org/wiki/List_of_colors_(compact) [https://en.wikipedia.org/wiki/List_of_colors_(compact)]
>
> =============== Diff against Graphics-mt.406 ===============
>
> Item was changed:
> ----- Method: Color class>>blueberry (in category 'named colors - crayons') -----
> blueberry
>
> + ^ Color fromString: '#4F86F7'!
> - ^ Color r: 0.0 g: 0.0 b: 1.0!
>
> Item was changed:
> ----- Method: Color class>>ice (in category 'named colors - crayons') -----
> ice
>
> + ^ Color fromString: '#99FFFF'!
> - ^ Color r: 102/255 g: 1.0 b: 1.0!
>
> Item was changed:
> ----- Method: Color class>>lemon (in category 'named colors - crayons') -----
> lemon
>
> + ^ Color fromString: '#FFF700'!
> - ^ Color r: 1.0 g: 1.0 b: 0.0!
>
> Item was changed:
> ----- Method: Color class>>licorice (in category 'named colors - crayons') -----
> licorice
>
> + ^ Color fromString: '#1A1110'!
> - ^ Color r: 0.0 g: 0.0 b: 0.0!
>
> Item was changed:
> ----- Method: Color class>>snow (in category 'named colors - crayons') -----
> snow
>
> + ^ self fromString: '#FFFAFA'!
> - ^ Color r: 1.0 g: 1.0 b: 1.0!
>
> Item was changed:
> ----- Method: Color class>>spring (in category 'named colors - crayons') -----
> spring
>
> + ^ self fromString: '#00FF7F'!
> - ^ Color r: 0.0 g: 1.0 b: 0.0!
>
> Item was changed:
> ----- Method: Color class>>turquoise (in category 'named colors - crayons') -----
> turquoise
>
> + ^ self fromString: '#40E0D0'!
> - ^ Color r: 0.0 g: 1.0 b: 1.0!
>
>
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190516/f50e7f05/attachment-0001.html>
>
> ------------------------------
>
> Message: 3
> Date: Thu, 16 May 2019 13:14:48 0000
> From: commits at source.squeak.org
> To: squeak-dev at lists.squeakfoundation.org
> Subject: [squeak-dev] The Inbox: Graphics-nice.408.mcz
> Message-ID: <E1hRGDj-0002G9-Nj at andreas>
>
> Nicolas Cellier uploaded a new version of Graphics to project The Inbox:
> http://source.squeak.org/inbox/Graphics-nice.408.mcz
>
> ==================== Summary ====================
>
> Name: Graphics-nice.408
> Author: nice
> Time: 16 May 2019, 3:12:54.000487 pm
> UUID: cc271e8f-330d-d649-a848-128e2d849f03
> Ancestors: Graphics-mt.406
>
> Use a map rgb->#names rather than iterating thru/performing all known colorNames.
>
> This is especially useful if we intend to add more color names.
> Note that names do not need to be unique.
> The first appearing name in colorNames will be used.
>
> Color colorNames collect: [:sym | Color perform: sym].
>
> (Color colorNames reject: [:sym | (Color perform: sym) name = sym])
> 	collect: [:sym | sym -> (Color perform: sym) name].
> 	
> The new class variable is initialized in postscript.
> It must be re-initialized each time we change the definition of a named Color.
>
> The rgb code has been used as key rather than the Color itself.
> This is because it is unique and cheap (SmallInteger).
>
> =============== Diff against Graphics-mt.406 ===============
>
> Item was changed:
>    Object subclass: #Color
>    	instanceVariableNames: 'rgb cachedDepth cachedBitPattern'
> + 	classVariableNames: 'Black Blue BlueShift Brown CachedColormaps ColorChart ColorNames ComponentMask ComponentMax Cyan DarkGray Gray GrayToIndexMap Green GreenShift HalfComponentMask HighLightBitmaps IndexedColors LightBlue LightBrown LightCyan LightGray LightGreen LightMagenta LightOrange LightRed LightYellow Magenta MaskingMap Orange PaleBlue PaleBuff PaleGreen PaleMagenta PaleOrange PalePeach PaleRed PaleTan PaleYellow PantonePurpleU PureBlue PureCyan PureGreen PureMagenta PureRed PureYellow RGBToNames RandomStream Red RedShift TranslucentPatterns Transparent VeryDarkGray VeryLightGray VeryPaleRed VeryVeryDarkGray VeryVeryLightGray White Yellow'
> - 	classVariableNames: 'Black Blue BlueShift Brown CachedColormaps ColorChart ColorNames ComponentMask ComponentMax Cyan DarkGray Gray GrayToIndexMap Green GreenShift HalfComponentMask HighLightBitmaps IndexedColors LightBlue LightBrown LightCyan LightGray LightGreen LightMagenta LightOrange LightRed LightYellow Magenta MaskingMap Orange PaleBlue PaleBuff PaleGreen PaleMagenta PaleOrange PalePeach PaleRed PaleTan PaleYellow PantonePurpleU PureBlue PureCyan PureGreen PureMagenta PureRed PureYellow RandomStream Red RedShift TranslucentPatterns Transparent VeryDarkGray VeryLightGray VeryPaleRed VeryVeryDarkGray VeryVeryLightGray White Yellow'
>    	poolDictionaries: ''
>    	category: 'Graphics-Primitives'!
>    
>    !Color commentStamp: '<historical>' prior: 0!
>    This class represents abstract color, regardless of the depth of bitmap it will be shown in.  At the very last moment a Color is converted to a pixelValue that depends on the depth of the actual Bitmap inside the Form it will be used with.  The supported depths (in bits) are 1, 2, 4, 8, 16, and 32.  The number of actual colors at these depths are: 2, 4, 16, 256, 32768, and 16 million.  (See comment in BitBlt.)  To change the depth of the Display and set how many colors you can see, execute: (Display newDepth: 8).  (See comment in DisplayMedium)
>    	Color is represented as the amount of light in red, green, and blue.  White is (1.0, 1.0, 1.0) and black is (0, 0, 0).  Pure red is (1.0, 0, 0).  These colors are "additive".  Think of Color's instance variables as:
>    	r	amount of red, a Float between 0.0 and 1.0.
>    	g	amount of green, a Float between 0.0 and 1.0.
>    	b	amount of blue, a Float between 0.0 and 1.0.
>    (But, in fact, the three are encoded as values from 0 to 1023 and combined in a single integer, rgb.  The user does not need to know this.)
>    	Many colors are named.  You find a color by name by sending a message to class Color, for example (Color lightBlue).  Also, (Color red: 0.2 green: 0.6 blue: 1.0) or (Color r: 0.2 g: 0.6 b: 1.0) creates a color. (see below)
>    	A color is essentially immutable.  Once you set red, green, and blue, you cannot change them.  Instead, create a new Color and use it.
>    	Applications such as contour maps and bar graphs will want to display one of a set of shades based on a number.  Convert the range of this number to an integer from 1 to N.  Then call (Color green lightShades: N) to get an Array of colors from white to green.  Use the Array messages at:, atPin:, or atWrap: to pull out the correct color from the array.  atPin: gives the first (or last) color if the index is out of range.  atWrap: wraps around to the other end if the index is out of range.
>    	Here are some fun things to run in when your screen has color:
>    		Pen new mandala: 30 diameter: Display height-100.
>    		Pen new web  "Draw with the mouse, opt-click to end"
>    		Display fillWhite.  Pen new hilberts: 5.
>    		Form toothpaste: 30  "Draw with mouse, opt-click to end"
>    You might also want to try the comment in
>    	Form>class>examples>tinyText...
>    
>    
>    Messages:
>    	mixed: proportion with: aColor	Answer this color mixed with the given color additively. The proportion, a number between 0.0 and 1.0, determines what what fraction of the receiver to use in the mix.
>    
>    	+ 	add two colors
>    	- 	subtract two colors
>    	*	multiply the values of r, g, b by a number or an Array of factors.  ((Color named: #white) * 0.3) gives a darkish gray.  (aColor * #(0 0 0.9)) gives a color with slightly less blue.
>    	/	divide a color by a factor or an array of three factors.
>    
>    	errorForDepth: d     How close the nearest color at this depth is to this abstract color.  Sum of the squares of the RGB differences, square rooted and normalized to 1.0.  Multiply by 100 to get percent.
>    
>    	hue			Returns the hue of the color. On a wheel from 0 to 360 with pure red at 0 and again at 360.
>    	saturation	Returns the saturation of the color.  0.0 to 1.0
>    	brightness	Returns the brightness of the color.  0.0 to 1.0
>    
>    	name    Look to see if this Color has a name.
>    	display	Show a swatch of this color tracking the cursor.
>    
>    	lightShades: thisMany		An array of thisMany colors from white to the receiver.
>    	darkShades: thisMany		An array of thisMany colors from black to the receiver.  Array is of length num.
>    	mix: color2 shades: thisMany		An array of thisMany colors from the receiver to color2.
>    	wheel: thisMany			An array of thisMany colors around the color wheel starting and ending at the receiver.
>    
>    	pixelValueForDepth: d    Returns the bits that appear be in a Bitmap of this depth for this color.  Represents the nearest available color at this depth.  Normal users do not need to know which pixelValue is used for which color.
>    
>    Messages to Class Color.
>    	red: r green: g blue: b		Return a color with the given r, g, and b components.
>    	r: g: b:		Same as above, for fast typing.
>    
>     	hue: h saturation: s brightness: b		Create a color with the given hue, saturation, and brightness.
>    
>    	pink
>     	blue
>    	red ...	Many colors have messages that return an instance of Color.
>    	canUnderstand: #brown	  Returns true if #brown is a defined color.
>    	names		An OrderedCollection of the names of the colors.
>    	named: #notAllThatGray put: aColor    Add a new color to the list and create an access message and a class variable for it.
>    	fromUser	Shows the palette of colors available at this display depth.  Click anywhere to return the color you clicked on.
>    
>    	hotColdShades: thisMany	An array of thisMany colors showing temperature from blue to red to white hot.
>    
>        stdColorsForDepth: d        An Array of colors available at this depth.  For 16 bit and 32 bits, returns a ColorGenerator.  It responds to at: with a Color for that index, simulating a very big Array.
>    
>       colorFromPixelValue: value depth: d    Returns a Color whose bit pattern (inside a Bitmap) at this depth is the number specified.  Normal users do not need to use this.
>    
>    (See also comments in these classes: Form, Bitmap, BitBlt, Pattern, MaskedForm.)!
>
> Item was changed:
>    ----- Method: Color class>>initializeNames (in category 'class initialization') -----
>    initializeNames
>    	"Name some colors."
>    	"Color initializeNames"
>    
>    	ColorNames := Set new.
>    	self named: #black put: (Color r: 0 g: 0 b: 0).
>    	self named: #veryVeryDarkGray put: (Color r: 0.125 g: 0.125 b: 0.125).
>    	self named: #veryDarkGray put: (Color r: 0.25 g: 0.25 b: 0.25).
>    	self named: #darkGray put: (Color r: 0.375 g: 0.375 b: 0.375).
>    	self named: #gray put: (Color r: 0.5 g: 0.5 b: 0.5).
>    	self named: #lightGray put: (Color r: 0.625 g: 0.625 b: 0.625).
>    	self named: #veryLightGray put: (Color r: 0.75 g: 0.75 b: 0.75).
>    	self named: #veryVeryLightGray put: (Color r: 0.875 g: 0.875 b: 0.875).
>    	self named: #white put: (Color r: 1.0 g: 1.0 b: 1.0).
>    	self named: #red put: (Color r: 1.0 g: 0 b: 0).
>    	self named: #yellow put: (Color r: 1.0 g: 1.0 b: 0).
>    	self named: #green put: (Color r: 0 g: 1.0 b: 0).
>    	self named: #cyan put: (Color r: 0 g: 1.0 b: 1.0).
>    	self named: #blue put: (Color r: 0 g: 0 b: 1.0).
>    	self named: #magenta put: (Color r: 1.0 g: 0 b: 1.0).
>    	self named: #brown put: (Color r: 0.6 g: 0.2 b: 0).
>    	self named: #orange put: (Color r: 1.0 g: 0.6 b: 0).
>    	self named: #lightRed put: (Color r: 1.0 g: 0.8 b: 0.8).
>    	self named: #lightYellow put: (Color r: 1.0 g: 1.0 b: 0.8).
>    	self named: #lightGreen put: (Color r: 0.8 g: 1.0 b: 0.6).
>    	self named: #lightCyan put: (Color r: 0.4 g: 1.0 b: 1.0).
>    	self named: #lightBlue put: (Color r: 0.8 g: 1.0 b: 1.0).
>    	self named: #lightMagenta put: (Color r: 1.0 g: 0.8 b: 1.0).
>    	self named: #lightBrown put: (Color r: 1.0 g: 0.6 b: 0.2).
>    	self named: #lightOrange put: (Color r: 1.0 g: 0.8 b: 0.4).
>    	self named: #transparent put: (TranslucentColor new alpha: 0.0).
>    	self named: #paleBuff put: (Color r: 254 g: 250 b: 235 range: 255).
>    	self named: #paleBlue put: (Color r: 222 g: 249 b: 254 range: 255).
>    	self named: #paleYellow put: (Color r: 255 g: 255 b: 217 range: 255).
>    	self named: #paleGreen put: (Color r: 223 g: 255 b: 213 range: 255).
>    	self named: #paleRed put: (Color r: 255 g: 230 b: 230 range: 255).
>    	self named: #veryPaleRed put: (Color r: 255 g: 242 b: 242 range: 255).
>    	self named: #paleTan put: (Color r: 235 g: 224 b: 199 range: 255).
>    	self named: #paleMagenta put: (Color r: 255 g: 230 b: 255 range: 255).
>    	self named: #paleOrange put: (Color r: 253 g: 237 b: 215 range: 255).
>    	self named: #palePeach put: (Color r: 255 g: 237 b: 213 range: 255).
>    	self named: #pantonePurpleU put: (Color r: 193 g: 81 b: 184 range: 255).
> + 	self initializeNamesMap
>    
>    !
>
> Item was added:
> + ----- Method: Color class>>initializeNamesMap (in category 'class initialization') -----
> + initializeNamesMap
> + 	"enable mapping a color to its name"
> + 	"Color initializeNamesMap"
> +
> + 	RGBToNames := Dictionary new.
> + 	self colorNames do: [:sym | (self perform: sym) addName: sym]!
>
> Item was added:
> + ----- Method: Color>>addName: (in category 'other') -----
> + addName: aSymbol
> + 	"private - associate a name to this color."
> + 	
> + 	| knownNames |
> + 	[(self class respondsTo: aSymbol) and: [(self class perform: aSymbol) = self]] assert.
> + 	knownNames := RGBToNames at: rgb ifAbsent: [#()].
> + 	(knownNames includes: aSymbol)
> + 		ifFalse: [ RGBToNames at: rgb put: (knownNames copyWith: aSymbol)]!
>
> Item was changed:
>    ----- Method: Color>>name (in category 'other') -----
>    name
> + 	"Return this color's name, or nil if it has no name."
> - 	"Return this color's name, or nil if it has no name. Only returns a name if it exactly matches the named color."
>    
> + 	^ (RGBToNames at: rgb ifAbsent: [nil]) ifNotNil: [:names | names at: 1 ifAbsent: [nil]]!
> - 	^ self class colorNames detect: [ :name | (Color perform: name) = self ] ifNone: [ nil ]!
>
> Item was added:
> + ----- Method: TranslucentColor>>addName: (in category 'other') -----
> + addName: aSymbol
> + 	"private - associate a name to this color.
> + 	Don't do it, Translucent colors are not uniquely identified by their rgb components"
> + 	
> + 	^self!
>
> Item was added:
> + ----- Method: TranslucentColor>>name (in category 'other') -----
> + name
> + 	self = Color transparent ifTrue: [^#transparent].
> + 	^nil!
>
> Item was changed:
>    (PackageInfo named: 'Graphics') postscript: '
> + "Initialize RGBToName dictionary"
> + Color initializeNamesMap.'!
> - " Reset DejaVu to current version "
> - StrikeFont initialize.'!
>
>
>
> ------------------------------
>
> Message: 4
> Date: Thu, 16 May 2019 15:44:05 +0200
> From: Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com>
> To: The general-purpose Squeak developers list
> 	<squeak-dev at lists.squeakfoundation.org>
> Subject: Re: [squeak-dev] The Inbox: Graphics-nice.407.mcz
> Message-ID:
> 	<CAKnRiT7q2NOV-gnsVv0N6K4nObVNC-dNzgjXZm8XjP9_cV-J9Q at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hi Marcel,
> I prefer to use a map (Dictionary)
> http://source.squeak.org/inbox/Graphics-nice.408.diff
>
> Le jeu. 16 mai 2019 à 14:50, Marcel Taeumel <marcel.taeumel at hpi.de> a
> écrit :
>
>> Hi Nicolas,
>>
>> considering the factory approach (e.g., "Color crayon blueberry"), you
>> could easily produce NamedColor (as subclass of Color with a name). Not
>> sure about adding a name directly to Color, though....
>>
>> Best,
>> Marcel
>>
>> Am 16.05.2019 14:20:24 schrieb Nicolas Cellier <
>> nicolas.cellier.aka.nice at gmail.com>:
>>
>>
>> Le jeu. 16 mai 2019 à 13:54, Marcel Taeumel <marcel.taeumel at hpi.de> a
>> écrit :
>>
>>> Hi Nicolas,
>>>
>>> it would be nice to see more named colors in the image. The
>>> user-interface themes introduce color names for Monokai and Solarized etc.
>>> I sneaked some crayons into Color itself. I think that "Color crayon
>>> blueberry" would be acceptable to hide a factory or something similar.
>>>
>>> However:
>>>
>>> [Color fromString: '#99FFFF'] bench '481,000 per second. 2.08
>>> microseconds per run.'
>>> [Color r: 102/255 g: 1.0 b: 1.0] bench '2,520,000 per second. 397
>>> nanoseconds per run.'
>>>
>>> ;-)
>>>
>>> Best,
>>> Marcel
>>>
>> Yes,
>> I also forgot two conflicts
>>
>> (Color colorNames reject: [:sym | (Color perform: sym) name = sym])
>> collect: [:sym | sym -> (Color perform: sym) name].
>>   {#cantaloupe->#lightOrange . #maraschino->#red}
>>
>> For having more colorNames, it's better to change ColorName>>#name
>> strategy first
>>
>> Am 16.05.2019 13:02:44 schrieb commits at source.squeak.org <
>>> commits at source.squeak.org>:
>>> Nicolas Cellier uploaded a new version of Graphics to project The Inbox:
>>> http://source.squeak.org/inbox/Graphics-nice.407.mcz
>>>
>>> ==================== Summary ====================
>>>
>>> Name: Graphics-nice.407
>>> Author: nice
>>> Time: 16 May 2019, 1:01:07.687487 pm
>>> UUID: 0c370e95-c3cf-5e44-9eb5-b81fb1ebf424
>>> Ancestors: Graphics-mt.406
>>>
>>> I see that Marcel used something like
>>> https://gist.github.com/haggen/c91ed87700e5971f6fc6
>>>
>>> I propose to reduce crayon shades overlapping by adopting different
>>> references
>>>
>>> blueberry
>>> (Encycolorpedia) https://encycolorpedia.com/4f86f7
>>> (Crayola) https://en.wikipedia.org/wiki/List_of_Crayola_crayon_colors
>>> ice (Corel ice blue)
>>> https://en.wikipedia.org/wiki/Shades_of_blue#Ice_blue
>>> lemon
>>> (Encycolorpedia lemon) https://encycolorpedia.com/fff700
>>> (Encycolorpedia lemon yellow)
>>> https://en.wikipedia.org/wiki/Lemon_(color)#Lemon_yellow
>>> (Crayola lemon) https://en.wikipedia.org/wiki/Shades_of_yellow#Lemon
>>> licorice (Crayola-Encycolorpedia)
>>> https://en.wikipedia.org/wiki/Shades_of_black#Licorice
>>> snow
>>> (Encycolorpedia) https://encycolorpedia.com/fffafa
>>> (X11) https://en.wikipedia.org/wiki/Shades_of_white#Snow
>>> spring (X11 spring green) https://en.wikipedia.org/wiki/Spring_green
>>> turquoise (X11-Encycolorpedia)
>>> https://en.wikipedia.org/wiki/Shades_of_cyan#Turquoise
>>>
>>> Or should we have sort of factories?
>>> (Color x11 turquoise vs Color macCrayon turquoise)
>>>
>>> Of course, it opens some sort of big can:
>>> https://encycolorpedia.com/named
>>> https://en.wikipedia.org/wiki/X11_color_names
>>> https://en.wikipedia.org/wiki/List_of_colors_(compact)
>>>
>>> =============== Diff against Graphics-mt.406 ===============
>>>
>>> Item was changed:
>>> ----- Method: Color class>>blueberry (in category 'named colors -
>>> crayons') -----
>>> blueberry
>>>
>>> + ^ Color fromString: '#4F86F7'!
>>> - ^ Color r: 0.0 g: 0.0 b: 1.0!
>>>
>>> Item was changed:
>>> ----- Method: Color class>>ice (in category 'named colors - crayons')
>>> -----
>>> ice
>>>
>>> + ^ Color fromString: '#99FFFF'!
>>> - ^ Color r: 102/255 g: 1.0 b: 1.0!
>>>
>>> Item was changed:
>>> ----- Method: Color class>>lemon (in category 'named colors - crayons')
>>> -----
>>> lemon
>>>
>>> + ^ Color fromString: '#FFF700'!
>>> - ^ Color r: 1.0 g: 1.0 b: 0.0!
>>>
>>> Item was changed:
>>> ----- Method: Color class>>licorice (in category 'named colors -
>>> crayons') -----
>>> licorice
>>>
>>> + ^ Color fromString: '#1A1110'!
>>> - ^ Color r: 0.0 g: 0.0 b: 0.0!
>>>
>>> Item was changed:
>>> ----- Method: Color class>>snow (in category 'named colors - crayons')
>>> -----
>>> snow
>>>
>>> + ^ self fromString: '#FFFAFA'!
>>> - ^ Color r: 1.0 g: 1.0 b: 1.0!
>>>
>>> Item was changed:
>>> ----- Method: Color class>>spring (in category 'named colors - crayons')
>>> -----
>>> spring
>>>
>>> + ^ self fromString: '#00FF7F'!
>>> - ^ Color r: 0.0 g: 1.0 b: 0.0!
>>>
>>> Item was changed:
>>> ----- Method: Color class>>turquoise (in category 'named colors -
>>> crayons') -----
>>> turquoise
>>>
>>> + ^ self fromString: '#40E0D0'!
>>> - ^ Color r: 0.0 g: 1.0 b: 1.0!
>>>
>>>
>>>
>>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190516/0a40b388/attachment-0001.html>
>
> ------------------------------
>
> Message: 5
> Date: Thu, 16 May 2019 16:29:17 +0200
> From: Stéphane Rollandin <lecteur at zogotounga.net>
> To: squeak-dev at lists.squeakfoundation.org
> Subject: Re: [squeak-dev] The Inbox: Graphics-nice.407.mcz
> Message-ID: <f4f8ee38-c8c3-2835-5ff1-abf5b8df994e at zogotounga.net>
> Content-Type: text/plain; charset=utf-8; format=flowed
>
>> it would be nice to see more named colors in the image.
> I have provided a package adding about 150 color names for ages (circa
> 2010). It is there:
>
> http://map.squeak.org/account/package/4fcb1d4d-ff16-46e2-bfa8-a7410f0cd5a3
>
> Stef
>
>
> ------------------------------
>
> Message: 6
> Date: Thu, 16 May 2019 16:31:45 +0200
> From: Stéphane Rollandin <lecteur at zogotounga.net>
> To: squeak-dev at lists.squeakfoundation.org
> Subject: Re: [squeak-dev] The Inbox: Graphics-nice.407.mcz
> Message-ID: <63b0eacc-5585-7323-f6e7-fcb76915d9af at zogotounga.net>
> Content-Type: text/plain; charset=utf-8; format=flowed
>
>
>> I have provided a package adding about 150 color names
> ... I meant *1500* color names
>
> Stef
>
>
> ------------------------------
>
> Message: 7
> Date: Thu, 16 May 2019 16:51:58 +0200
> From: Torge Husfeldt <torge.husfeldt at gmx.de>
> To: squeak-dev at lists.squeakfoundation.org
> Subject: Re: [squeak-dev] Boolean whenTrue:whenFalse:
> Message-ID: <88161f0e-2a1c-6338-162c-42b77d5fca41 at husfeldt.info>
> Content-Type: text/plain; charset="utf-8"; Format="flowed"
>
> Salut Nico,
>
> please excuse if my squeak knowlege is a bit rusty, but wouldn't this do
> the job:
>
> self findlast: [:each |
>
> [self testSomeConditionFor: each] value ifTrue:[self
> performSomeAction:each]; yourself.
>
> ].
>
> Just an idea. And very sad that I have to wrap the condition in a block,
> but I guess othewise the recipient for "yourself" would be "self"
>
> On 14.05.19 17:02, Nicolas Cellier wrote:
>> Oups, my example was a bit stupid because findLast: loop stops at
>> first true, but you get my intention...
>> Replace with select:/reject: or provide a whenFalse: side effect...
>>
>> Le mar. 14 mai 2019 à 16:23, Nicolas Cellier
>> <nicolas.cellier.aka.nice at gmail.com
>> <mailto:nicolas.cellier.aka.nice at gmail.com>> a écrit :
>>
>>      Hi,
>>      From time to time, I need to perform some additional action (side
>>      effect) when a boolean is true, but preserve that boolean as
>>      return value.
>>
>>      Here is a pseudo example:
>>
>>          self findLast: [:each |
>>              | conforming |
>>              conforming := self testSomeConditionFor: each.
>>              conforming
>>                  ifTrue:
>>                      [ "found one, do some side effect before searching
>>      next"
>>                      self performSomeAction: each ].
>>               conforming ].
>>
>>      Or shorter, but I dislike the redundant true:
>>
>>          self findLast: [:each |
>>              (self testSomeConditionFor: each)
>>                  and:
>>                      [ "found one, do some side effect before searching
>>      next"
>>                      self performSomeAction: each.
>>                      true ]].
>>
>>      What i seek is even shorter:
>>
>>          self findLast: [:each |
>>              (self testSomeConditionFor: each)
>>                  whenTrue:
>>                      [ "found one, do some side effect before searching
>>      next"
>>                      self performSomeAction: each ]].
>>
>>      Of course, we would have companions whenFalse:, whenTrue:whenFalse:...
>>      Would you buy it?
>>
>>
>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190516/4dbc05c7/attachment-0001.html>
>
> ------------------------------
>
> Message: 8
> Date: Thu, 16 May 2019 17:08:48 +0200
> From: Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com>
> To: The general-purpose Squeak developers list
> 	<squeak-dev at lists.squeakfoundation.org>
> Subject: Re: [squeak-dev] Boolean whenTrue:whenFalse:
> Message-ID:
> 	<CAKnRiT7dr4RSPB7SDZW8CdvYnY+zQ47Zk8_Ede3EM610ekJbPQ at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hi,
> Ah yes, it works, no need for extra [] value
>
>      (3 > 2) ifTrue: [Transcript cr; show: 'bingo!']; yourself
>
> The code is not optimized, but it works.
>
> Le jeu. 16 mai 2019 à 16:52, Torge Husfeldt <torge.husfeldt at gmx.de> a
> écrit :
>
>> Salut Nico,
>>
>> please excuse if my squeak knowlege is a bit rusty, but wouldn't this do
>> the job:
>>
>> self findlast: [:each |
>>
>> [self testSomeConditionFor: each] value ifTrue:[self
>> performSomeAction:each]; yourself.
>>
>> ].
>>
>> Just an idea. And very sad that I have to wrap the condition in a block,
>> but I guess othewise the recipient for "yourself" would be "self"
>> On 14.05.19 17:02, Nicolas Cellier wrote:
>>
>> Oups, my example was a bit stupid because findLast: loop stops at first
>> true, but you get my intention...
>> Replace with select:/reject: or provide a whenFalse: side effect...
>>
>> Le mar. 14 mai 2019 à 16:23, Nicolas Cellier <
>> nicolas.cellier.aka.nice at gmail.com> a écrit :
>>
>>> Hi,
>>>  From time to time, I need to perform some additional action (side effect)
>>> when a boolean is true, but preserve that boolean as return value.
>>>
>>> Here is a pseudo example:
>>>
>>>      self findLast: [:each |
>>>          | conforming |
>>>          conforming := self testSomeConditionFor: each.
>>>          conforming
>>>              ifTrue:
>>>                  [ "found one, do some side effect before searching next"
>>>                  self performSomeAction: each ].
>>>           conforming ].
>>>
>>> Or shorter, but I dislike the redundant true:
>>>
>>>      self findLast: [:each |
>>>          (self testSomeConditionFor: each)
>>>              and:
>>>                  [ "found one, do some side effect before searching next"
>>>                  self performSomeAction: each.
>>>                  true ]].
>>>
>>> What i seek is even shorter:
>>>
>>>      self findLast: [:each |
>>>          (self testSomeConditionFor: each)
>>>              whenTrue:
>>>                  [ "found one, do some side effect before searching next"
>>>                  self performSomeAction: each ]].
>>>
>>> Of course, we would have companions whenFalse:, whenTrue:whenFalse:...
>>> Would you buy it?
>>>
>>>
>>>
>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190516/3a87173e/attachment-0001.html>
>
> ------------------------------
>
> Message: 9
> Date: Thu, 16 May 2019 17:13:36 +0200
> From: Torge Husfeldt <torge.husfeldt at gmx.de>
> To: squeak-dev at lists.squeakfoundation.org
> Subject: Re: [squeak-dev] Boolean whenTrue:whenFalse:
> Message-ID: <6b580a60-373f-b8d5-2a15-eaa5574e100f at husfeldt.info>
> Content-Type: text/plain; charset="utf-8"; Format="flowed"
>
> Hi Nico,
>
> I'm convinced this only works without the extra [] value because you
> chose a special selector. For keyword-selector it should go to "self".
>
> Which part exactly is not optimized? The "ifTrue:" has a special
> handling in the bytecode complier, and iirc yourself is also not
> "actually sent".
>
> Cdlt
>
> Torge
>
> On 16.05.19 17:08, Nicolas Cellier wrote:
>> Hi,
>> Ah yes, it works, no need for extra [] value
>>
>>      (3 > 2) ifTrue: [Transcript cr; show: 'bingo!']; yourself
>>
>> The code is not optimized, but it works.
>>
>> Le jeu. 16 mai 2019 à 16:52, Torge Husfeldt <torge.husfeldt at gmx.de
>> <mailto:torge.husfeldt at gmx.de>> a écrit :
>>
>>      Salut Nico,
>>
>>      please excuse if my squeak knowlege is a bit rusty, but wouldn't
>>      this do the job:
>>
>>      self findlast: [:each |
>>
>>      [self testSomeConditionFor: each] value ifTrue:[self
>>      performSomeAction:each]; yourself.
>>
>>      ].
>>
>>      Just an idea. And very sad that I have to wrap the condition in a
>>      block, but I guess othewise the recipient for "yourself" would be
>>      "self"
>>
>>      On 14.05.19 17:02, Nicolas Cellier wrote:
>>>      Oups, my example was a bit stupid because findLast: loop stops at
>>>      first true, but you get my intention...
>>>      Replace with select:/reject: or provide a whenFalse: side effect...
>>>
>>>      Le mar. 14 mai 2019 à 16:23, Nicolas Cellier
>>>      <nicolas.cellier.aka.nice at gmail.com
>>>      <mailto:nicolas.cellier.aka.nice at gmail.com>> a écrit :
>>>
>>>          Hi,
>>>          From time to time, I need to perform some additional action
>>>          (side effect) when a boolean is true, but preserve that
>>>          boolean as return value.
>>>
>>>          Here is a pseudo example:
>>>
>>>              self findLast: [:each |
>>>                  | conforming |
>>>                  conforming := self testSomeConditionFor: each.
>>>                  conforming
>>>                      ifTrue:
>>>                          [ "found one, do some side effect before
>>>          searching next"
>>>                          self performSomeAction: each ].
>>>                   conforming ].
>>>
>>>          Or shorter, but I dislike the redundant true:
>>>
>>>              self findLast: [:each |
>>>                  (self testSomeConditionFor: each)
>>>                      and:
>>>                          [ "found one, do some side effect before
>>>          searching next"
>>>                          self performSomeAction: each.
>>>                          true ]].
>>>
>>>          What i seek is even shorter:
>>>
>>>              self findLast: [:each |
>>>                  (self testSomeConditionFor: each)
>>>                      whenTrue:
>>>                          [ "found one, do some side effect before
>>>          searching next"
>>>                          self performSomeAction: each ]].
>>>
>>>          Of course, we would have companions whenFalse:,
>>>          whenTrue:whenFalse:...
>>>          Would you buy it?
>>>
>>>
>>>
>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190516/59374090/attachment.html>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Squeak-dev mailing list
> Squeak-dev at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/squeak-dev
>
> ------------------------------
>
> End of Squeak-dev Digest, Vol 197, Issue 25
> *******************************************

---
This email has been checked for viruses by AVG.
https://www.avg.com




More information about the Squeak-dev mailing list