Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created August 12, 2012 15:55
Show Gist options
  • Save cowboy/3332446 to your computer and use it in GitHub Desktop.
Save cowboy/3332446 to your computer and use it in GitHub Desktop.
LiveScript: language design?
// 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;
}
@gkz
Copy link

gkz commented Aug 13, 2012

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('')

@vendethiel
Copy link

@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