Created
August 12, 2012 15:55
-
-
Save cowboy/3332446 to your computer and use it in GitHub Desktop.
LiveScript: language design?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
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: '-!+'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
likefunction
?<|
ehr, the subject of what should be "done"? But then what is the->
function like arrow doing there? Andreplicate
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
infrom x to y
is inclusvex
, exclusivey
. So assumingi
starts at0
(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! :)