Concatenating Smalltalk Pharo String instead of Threads

why do you need the following code:

| list types |
list := Heap new.
types := #('a' 'b' 'c').
types do:[ :t |
    1 to:9 do:[ :i |
        list add:(t, i asString).
        ].
    ].
^ list

issue a warning String concatenation instead of streamsin a method in Pharo? Pressing the [ ? ] shows:

Concatenating strings instead of threads
Check the code using string concatenation inside some iteration message.

Am I doing what could be simpler with threads? What I want to achieve is to create a list of all the values a1 to a9 , b1 to b9 and c1 to c9 .

+4
source share
2 answers

- t, i asString, ( RBStringConcatenationRule.

, (IIRC ).

, ( ), : printOn: , .

, , . - ... , - - .

, Smalltalk (select:, collect:,...) do:,

| list types |
types := #('a' 'b' 'c').
list := types flatCollect: [ :t | (1 to: 9) collect: [ :i | t , i asString ].
^ Heap withAll: list

( Heap, list tempvar.

+8

, :

| list types digits |

list := Heap new.
types := #($a $b $c).
digits := (1 to: 9) collect: #asCharacterDigit.

types do: [ :t | 
    digits do: [ :d |
        list 
            add: ((String new: 2)
                at: 1 put: t;
                at: 2 put: d;
                yourself)
          ] ].
^ list

, . .

+1

Source: https://habr.com/ru/post/1659840/


All Articles