Use underscores
This is probably the most important tip. Nearly every golfed Röda program uses underscores.
The underscore syntax is syntactic sugar for for
loops. The following lines of code are equivalent:
ls""|fileLength x for x|sort|pull
ls""|fileLength _|sort|pull
Each underscore adds a new variable to an invisible for
loop that is around the statement. The loop pulls one value from the stream for each variable/underscore and then repeats, until no values are left.
Underscores can be used anywhere in statements:
a[x:y+1]=[1]*(1+y-x) /* Sets range x..y (inclusive) */
seq x,y|a[_]=1 /* 6 bytes less */
If you must refer to the same underscore value more than once, or use the values in reverse order, you can put a number after the underscore:
a|[_^_1] /* maps x to x^x */
a|[_2-_1] /* maps each pair (x,y) to y-x, eg. [1,2,4,8] -> [1, 4] */
Are you trying to get tips to beat me in the golf? :P (I should probably look at the tips for Python page) – HyperNeutrino – 2017-03-28T13:49:31.507
Wow, a question from PCG.SE that got into the Hot Network Questions and is not a programming puzzle / challenge! :) – Pedro A – 2017-03-28T17:22:09.907
1@HyperNeutrino Shhh.... :) – user41805 – 2017-03-29T08:00:54.367