Last active
August 29, 2015 14:17
-
-
Save rjgotten/20b0451bb1d5751b3240 to your computer and use it in GitHub Desktop.
This file contains 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
.each(@list, @ruleset) { | |
@plugin "plugins/lambda"; | |
@length : length(@list); | |
._iterate(1); | |
._iterate(@index) when (@index =< @length) { | |
@item : extract(@list, @index); | |
@lambda : lambda(@item, @index, item index, @ruleset); | |
@lambda(); | |
._iterate(@index + 1); | |
} | |
} |
This file contains 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
function getItemsFromNode( node ) { | |
return Array.isArray( node.value ) ? node.value : [ node ]; | |
}; | |
functions.add("lambda", function() { | |
var | |
values = [].slice.call( arguments ), | |
ruleset = values.pop(), | |
names = values.pop(); | |
if ( !( ruleset instanceof tree.DetachedRuleset )) { | |
throw { | |
type : "Argument", | |
message : "missing the required ruleset argument to lambda." | |
}; | |
} | |
names = names ? getItemsFromNode( names ) : []; | |
if ( names.length != values.length ) { | |
throw { | |
type : "Argument", | |
message : "mismatch in the number of arguments named for and passed into lambda." | |
} | |
} | |
params = [ new tree.Rule( "@arguments", new tree.Expression( values ))]; | |
params = params.concat( names.map( function( name, index ) { | |
return new tree.Rule( "@" + name.value, values[ index ]); | |
})); | |
params = new tree.Ruleset( null, params ); | |
return new tree.DetachedRuleset( ruleset.ruleset, [ params ].concat( ruleset.frames )); | |
}); |
This file contains 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
.test { | |
-test-1 : foo; | |
-test-2 : bar; | |
-test-3 : baz; | |
} |
This file contains 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
.test { | |
// Just to illustrate that declaration scope does not | |
// bind stronger than caller scope here... | |
@index : -1; | |
@item : FAIL; | |
.each(foo bar baz, { | |
-test-@{index} : @item; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment