Lambdaheads: Unterschied zwischen den Versionen
Daxim (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
|||
Zeile 21: | Zeile 21: | ||
== nächster regulärer Termin == | == nächster regulärer Termin == | ||
Termin: Mo, '''2013- | Termin: Mo, '''2013-07-16''' ab 20:00 Uhr in der Bibliothek [[Lage|im Metalab]] | ||
=== Programm === | === Programm === | ||
generators in future ECMAscript | |||
=== Teilnehmer === | === Teilnehmer === | ||
Zeile 35: | Zeile 31: | ||
* [[Benutzer:Daxim]] | * [[Benutzer:Daxim]] | ||
* [[Benutzer:Epsilon.halbe|ε/2]] | * [[Benutzer:Epsilon.halbe|ε/2]] | ||
* http://www.meetup.com/viennajs/events/126593272/ | |||
<!-- | <!-- | ||
Zeile 73: | Zeile 70: | ||
= Frühere Events = | = Frühere Events = | ||
== 2013-06-18 == | |||
comb, one of the opposites of join (the other one is split) | |||
<pre> | |||
String.prototype.comb = function(re) { | |||
// lol type conversion the hacky way | |||
re = ('' + re) // now it's a string | |||
.replace(/^\//, '') // hack off leading | |||
.replace(/\/$/, ''); // trailing delimiter | |||
// no interpolation, no sigils, no sprintf | |||
return eval('this.match(/(' + re + ')+/g)'); | |||
} | |||
</pre> | |||
gather/take construct reimplemented for JS - a replacement for the idiom of declaring a collecting variable and pushing into it occasionally http://perl6.wikia.com/wiki/Gather | |||
<pre> | |||
function gather(fn) { | |||
var guard = new Array; | |||
var take = function (items) { | |||
guard = guard.concat(items); | |||
}; | |||
fn(take); | |||
return guard; | |||
}; | |||
console.log( | |||
gather(function(take) { | |||
for (var i = 0; i <= 10; i++) { | |||
if (i % 2) { | |||
take(i); | |||
} | |||
} | |||
}) | |||
) | |||
var arr = []; | |||
for (var i = 0; i <= 10; i++) { | |||
if (i % 2) { | |||
arr.push(i); | |||
} | |||
} | |||
</pre> | |||
Haskell example is incomplete | |||
<pre> | |||
gather x = foldr (:) [] x | |||
main = print $ gather [0..10] | |||
</pre> | |||
reimplementation of List::Gen::by http://p3rl.org/List::Gen#by-NUM-LIST (no generators, just list transformation) | |||
<pre> | |||
function by(n, a) { | |||
var r = new Array; | |||
while(a.length) { | |||
r.push(a.splice(0, n)); | |||
}; | |||
console.log(a); | |||
return r; | |||
}; | |||
function by2(n, a) { | |||
return a.length ? [a.slice(0, n)].concat(by2(n, a.slice(n))) : []; | |||
} | |||
console.log( by2(5, [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]) ); | |||
console.log( by2(5, [1,2,3,4,5,6,7,8,9,10,11,12,13,14]) ); | |||
console.log( by2(5, [1,2,3,4]) ); | |||
console.log( by2(5, []) ); | |||
</pre> | |||
<pre> | |||
// contrib by intval | |||
// divides array into equal arrays, each of size n | |||
function by(n, arr) { | |||
function byby(n, arr, accum) { | |||
if(arr.length < 1) { | |||
return accum; | |||
} | |||
var head = [arr.slice(0,n)]; | |||
var tail = arr.slice(n); | |||
return byby(n, tail, accum.concat(head)); | |||
} | |||
return byby(n, arr, []); | |||
} | |||
console.log( by(5, [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]) ); | |||
console.log( by(5, [1,2,3,4,5,6,7,8,9,10,11,12,13,14]) ); | |||
console.log( by(5, [1,2,3,4]) ); | |||
console.log( by(25, []) ); | |||
</pre> | |||
== 2013-05-21 == | == 2013-05-21 == |