9
\$\begingroup\$

What general tips do you have for golfing in Smalltalk? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Smalltalk (e.g. "remove comments" is not an answer).

Smalltalk is a purely object-oriented language created by Alan Kay. The two links are GNU Smalltalk and a general Smalltalk page respectively. You do not have to pay attention on this "spoiler".

hyperneutrino
42.8k5 gold badges72 silver badges227 bronze badges
asked Aug 28, 2019 at 10:21
\$\endgroup\$
0

1 Answer 1

8
\$\begingroup\$

Use the ; operator to refer to the previous object

There is a convenient shorthand in Smalltalk used to refer to the previous object. Say we want to add 3 items to the set x.

x:=Set new
x add:5.x add:7.x add:'foo'

However, we can save a few bytes by using the ; operator:

x:=Set new
x add:5;add:7;add:'foo'
answered Aug 28, 2019 at 10:29
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.