10
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

You can stick methods onto the back of most literals

"text" print    # 12 bytes
"text"print     # 11 bytes

12 print        # 8 bytes
12print         # 7 bytes

(0<1,0,1) print # 15 bytes
(0<1,0,1)print  # 14 bytes

Not everything

0x12print # prints nothing
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

You can leave out the else part of the if function

This isn't in the documentation... I initially thought that you have to include the else part, like the elvis operator in other languages; turns out that I can leave out the else part. (Please add this to the tutorial/documentation!)

if("bug"size>2,"True",nil)

So, if you don't want the else part to return anything, you could just do

if("bug"size>2,"True")
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Higher-level function shorthand

This seems like a pretty interesting golfing point. E.g.

list(1,2,3)map(i,i+1)print

However, Io is pretty permissive on not specifying the counter; the map body can be used as a point-free function, as Io tries to fill in the operand of this expression. This can be golfed into

list(1,2,3)map(+1)print
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.