Squeak Smalltalk- How to make to “Transcript show” print more things?

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

Squeak Smalltalk- How to make to “Transcript show” print more things?

RedTigerFish
I am using Smalltalk to type in Transcript window a 1-9 multiplication table
.

Here is my code:

*1 to: 9 do: [:i|
    1 to: i do: [:j|
        Transcript show: j.
        Transcript show: ' * '.
        Transcript show: i.
        Transcript show: ' = '.
        Transcript show: j * i.
        Transcript show: '  '.
        ].
    Transcript show: ' '; cr.
    ].*
As can be seen, the above code, although working fine, looks far from
beautiful and concise.

I had hoped to write something like :

*Transcript show: j '*' i '=' j * i.*
Unfortunately, they are wrong. I remember C has a very nice way to handle
that issue of mine.

Like, *printf("%d * %d = %d ", j, i, j * i);*

Is there a more elegant way to make Smalltalk codes elegant in this
situation ?



-----
Dig, dig where you are,
Down below's well.
Let those that walk in darkness shout,
Down below's hell.
--
Sent from: http://forum.world.st/Squeak-Beginners-f107673.html
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Dig, dig where you are,
Down below's well.
Let those that walk in darkness shout,
Down below's hell.
Reply | Threaded
Open this post in threaded view
|

Re: Squeak Smalltalk- How to make to “Transcript show” print more things?

marcel.taeumel
Hmm...

1 to: 9 do: [:i | 1 to: i do: [:j |
  Transcript showln: ('{1} * {2} = {3}' format: {i.j.i*j}) ]].

Best,
Marcel

Am 06.11.2017 08:28:00 schrieb RedTigerFish <[hidden email]>:

I am using Smalltalk to type in Transcript window a 1-9 multiplication table
.

Here is my code:

*1 to: 9 do: [:i|
1 to: i do: [:j|
Transcript show: j.
Transcript show: ' * '.
Transcript show: i.
Transcript show: ' = '.
Transcript show: j * i.
Transcript show: ' '.
].
Transcript show: ' '; cr.
].*
As can be seen, the above code, although working fine, looks far from
beautiful and concise.

I had hoped to write something like :

*Transcript show: j '*' i '=' j * i.*
Unfortunately, they are wrong. I remember C has a very nice way to handle
that issue of mine.

Like, *printf("%d * %d = %d ", j, i, j * i);*

Is there a more elegant way to make Smalltalk codes elegant in this
situation ?



-----
Dig, dig where you are,
Down below's well.
Let those that walk in darkness shout,
Down below's hell.
--
Sent from: http://forum.world.st/Squeak-Beginners-f107673.html
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Squeak Smalltalk- How to make to “Transcript show” print more things?

marcel.taeumel
Ooops, I messed with the layout. Here again:

1 to: 9 do: [:i |
1 to: i do: [:j | Transcript show: ('{1} * {2} = {3} ' format: {i.j.i*j}) ].
Transcript cr].

So, you can use #format: to format strings more concisely.

Best,
Marcel

Am 06.11.2017 09:20:45 schrieb Marcel Taeumel <[hidden email]>:

Hmm...

1 to: 9 do: [:i | 1 to: i do: [:j |
  Transcript showln: ('{1} * {2} = {3}' format: {i.j.i*j}) ]].

Best,
Marcel

Am 06.11.2017 08:28:00 schrieb RedTigerFish <[hidden email]>:

I am using Smalltalk to type in Transcript window a 1-9 multiplication table
.

Here is my code:

*1 to: 9 do: [:i|
1 to: i do: [:j|
Transcript show: j.
Transcript show: ' * '.
Transcript show: i.
Transcript show: ' = '.
Transcript show: j * i.
Transcript show: ' '.
].
Transcript show: ' '; cr.
].*
As can be seen, the above code, although working fine, looks far from
beautiful and concise.

I had hoped to write something like :

*Transcript show: j '*' i '=' j * i.*
Unfortunately, they are wrong. I remember C has a very nice way to handle
that issue of mine.

Like, *printf("%d * %d = %d ", j, i, j * i);*

Is there a more elegant way to make Smalltalk codes elegant in this
situation ?



-----
Dig, dig where you are,
Down below's well.
Let those that walk in darkness shout,
Down below's hell.
--
Sent from: http://forum.world.st/Squeak-Beginners-f107673.html
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Squeak Smalltalk- How to make to “Transcript show” print more things?

RedTigerFish
/Thanks. That is really concise. Its formatting style is very much like that
of C printf. Just wondering who copied who?/



-----
Dig, dig where you are,
Down below's well.
Let those that walk in darkness shout,
Down below's hell.
--
Sent from: http://forum.world.st/Squeak-Beginners-f107673.html
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Dig, dig where you are,
Down below's well.
Let those that walk in darkness shout,
Down below's hell.