Skip to content
Browse files

[dist] 0.0.4

Fixed bug in algorithm;
  • Loading branch information...
1 parent 0179671 commit 997ea4505bffd006b21d3f670f589655df6682f9 @dscape committed Feb 19, 2012
Showing with 8 additions and 6 deletions.
  1. +1 −1 package.json
  2. +4 −3 pattern.js
  3. +1 −1 samples/hof.js
  4. +2 −1 samples/{zip_with.js → zip_with.test.js}
View
2 package.json
@@ -1,7 +1,7 @@
{ "name" : "p"
, "description" : "pattern matching in javascript for asyncronous iteration"
, "author" : "nuno job <nunojobpinto@gmail.com> (http://nunojob.com/)"
-, "version" : "0.0.3"
+, "version" : "0.0.4"
, "main" : "./pattern.js"
, "homepage" : "https://github.com/dscape/p"
, "repository" : { "type": "git", "url": "http://github.com/dscape/p.git" }
View
7 pattern.js
@@ -9,8 +9,8 @@
function p() {
if(!arity) { arity = arguments.length-1; } // set arity in first invok.
if(arity===arguments.length) { // # arguments match arity, execute
- var j = 0; // we need explicit control over j, cant be reset by :il
- ol: for(var i=0; i<arguments.length; i++) { // for each argument
+ var j = 0, i=0; // we need explicit control over vars
+ ol: for(; i<arguments.length; i++) { // for each argument
il: for(; j<stack.length; j++) { // for pattern in the stack
var s = stack[j]; // get the current pattern
log('α ', i, j);
@@ -23,8 +23,9 @@
if(arguments.length !== i+1) { log(''); continue ol; } }
else { // if it doesnt match try next pattern in stack
log('', s[i], '===', arguments[i]);
+ i=0;
// dont break and set ok to false if this is the last element
- if(stack.length!==j+1) { j=0; log(''); continue; } } }
+ if(stack.length!==j+1) { log(''); continue; } } }
var f = s[s.length-1];
log(' ' + (typeof f === 'function' ? 'ƒ' : 'λ'), f.name || f);
// execute whatever is the last argument on last pattern of stack
View
2 samples/hof.js
@@ -29,7 +29,7 @@ mapa(f, l, ac, cb,
zip_with(f, [], l2, ac, cb, function emptyl1(f, l1, l2, ac, cb) { cb(ac); });
zip_with(f, l1, [], ac, cb, function emptyl2(f, l1, l2, ac, cb) { cb(ac); });
zip_with(f, l1, l2, ac, cb, function all(f, l1, l2, ac, cb) {
- ac.push(f(l1.shift, l2.shift));
+ ac.push(f(l1.shift(), l2.shift()));
zip_with(f, l1, l2, ac, cb);
});
View
3 samples/zip_with.js → samples/zip_with.test.js
@@ -1,6 +1,7 @@
+/* [ '1:2', '3:4', '5:6' ] */
var zip = require('./hof').zip_with;
zip(function concat(a,b) { return a + ':' + b; },
[1,3,5], [2,4,6,8], [], function (ac) {
- console.log(ac);
+ console.error(ac);
});

0 comments on commit 997ea45

Please sign in to comment.
Something went wrong with that request. Please try again.