-
-
Save cowboy/3332446 to your computer and use it in GitHub Desktop.
// Re. the LiveScript <-! operator (et al) | |
// http://gkz.github.com/LiveScript/ | |
function getLiveScriptOperator() { | |
var op = ''; | |
for (var i = 0; i < 3; i++) { | |
op += String.fromCharCode(33 + Math.floor(15 * Math.random())); | |
} | |
return op; | |
} |
Yes, much more readable.
Boom:
[String.fromCharCode 33 + floor 15 * Math.random! for i to 2] * ''
[String.fromCharCode 33 + floor 15 * Math.random! for i to 2] * ''
(You can't edit Gist comments? That's stupid.)
Can't honestly say whether this is a joke or not. In case it's not, there is no way in hell I can translate the original gist into either of the two.
Is -> do it
like function
? <|
ehr, the subject of what should be "done"? But then what is the ->
function like arrow doing there? And replicate
is "repeat"?
And what is the * ''
supposed to mean? From the original code I'd have to guess that's "concatenate this list". But I'd never have figured that out otherwise.
Also, to
in from x to y
is inclusve x
, exclusive y
. So assuming i
starts at 0
(would certainly confuse a Lua coder), you seem to be looping two times, not three as the original one.
Point is, I really don't mind all these new flavors. But if you're dead set on creating a new language, at least make sure people can read it. Ask your mom. If she can't make heads or tails from it, you're doing it wrong.
As you were! :)
Hey @qfox, yes it is a joke. It is an exercise in code golf to see what is the shortest definition.
An explanation of:
[String.fromCharCode 33 + floor 15 * Math.random! for i to 2] * ''
First,
[String.fromCharCode 33 + floor 15 * Math.random! for i to 2]
is a list comprehension. It is an expression which evaluate to a list. It is equivalent to:
result = []
for i to 2
result.push String.fromCharCode 33 + floor 15 * Math.random!
result
As the from
parameter is omitted in the for loop, it is assumed to be 0
. to
means to and including that number, use til
to mean up until (but not including) that number.
[...] * ''
simply means
[...].join('')
@michaelficarra (do)
works too, plus you can change your <|
with a ,
here.
My version also is shorter: '-!+'
You're doing it wrong.