Last active
January 3, 2016 02:08
-
-
Save grncdr/8393328 to your computer and use it in GitHub Desktop.
This acts sort of like a thread first. Instead of actually modifying the arguments list, I implicitly assign the result of each line in the body to `$_` then you can use `$_` in the body to refer to the result of the last line.
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
macro thread { | |
case { $name ($args (,) ...) { $body ... } } => { | |
var result = makeIdent('$_', #{$name}) | |
return withSyntax($$_ = [result]) { | |
console.log('here') | |
return #{ | |
(function () { | |
var $$_ = arguments.length > 1 ? [].slice.call(arguments) : arguments[0]; | |
thread_body $$_ $body ...; | |
return $$_ | |
})($args (,) ...) | |
} | |
} | |
} | |
} | |
macro thread_body { | |
rule { | |
$_ $first ...; | |
$rest ... | |
} => { | |
$_ = $first ...; | |
thread_body $_ $rest ... | |
} | |
rule {} => {} | |
} | |
var y = thread (1) { | |
second(1, $_, 3); | |
last(something, $_) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment