Skip to content

Instantly share code, notes, and snippets.

@grncdr
Last active January 3, 2016 02:08

Revisions

  1. grncdr revised this gist Jan 13, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions not-exactly-thread-first.js
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ macro thread {
    return #{
    (function () {
    var $$_ = arguments.length > 1 ? [].slice.call(arguments) : arguments[0];
    thread_body $body ...;
    thread_body $$_ $body ...;
    return $$_
    })($args (,) ...)
    }
    @@ -16,11 +16,11 @@ macro thread {

    macro thread_body {
    rule {
    $first ...;
    $_ $first ...;
    $rest ...
    } => {
    $_ = $first ...;
    thread_body $rest ...
    thread_body $_ $rest ...
    }
    rule {} => {}
    }
  2. grncdr revised this gist Jan 13, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion not-exactly-thread-first.js
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ macro thread_body {
    $rest ...
    } => {
    $_ = $first ...;
    seq_body $rest ...
    thread_body $rest ...
    }
    rule {} => {}
    }
  3. grncdr created this gist Jan 13, 2014.
    31 changes: 31 additions & 0 deletions not-exactly-thread-first.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    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 ...;
    seq_body $rest ...
    }
    rule {} => {}
    }

    var y = thread (1) {
    second(1, $_, 3);
    last(something, $_)
    }