5
\$\begingroup\$

Whispers is February 2021's Language of the Month, so what tips do you have for golfing in it? Tips do not have to be specific to , so long as they apply to other types of challenges on the site. Tips should be at least somewhat specific to Whispers (e.g. "remove ignored code" is not an answer). Please post one tip per answer.

\$\endgroup\$
4
\$\begingroup\$

Order is important

Swap lines that are referenced more frequently than other lines with less referenced lines that are referenced by a small digit number.

Example:

> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> Input
>> #10
>> [10]
>> Output 11 12

The input is referenced twice and the line number is 10. If this line is moved up to line 1. Both 10s are replaced by 1s. In this example 2 bytes were saved.

> Input
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
>> #1
>> [1]
>> Output 11 12

Moving line 11 and 12 up saves another 2 bytes.

> Input
>> #1
>> [1]
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
>> Output 2 3

I wrote a script that takes a Whispers program as input and prints the optimized re-ordered program.

TIO | Github

\$\endgroup\$
2
\$\begingroup\$

Use Then to group values into an array

Then is a command which takes an indefinite number of arguments and puts them in an array:

> "hello"
> "world"
>> Then 1 2

The last line here returns ['hello', 'world'].

This can then be used with Each or Select to output things or modify them for something else.

\$\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.