Skip to content

Instantly share code, notes, and snippets.

@soegaard
Created January 22, 2014 21:44
Show Gist options
  • Select an option

  • Save soegaard/8567959 to your computer and use it in GitHub Desktop.

Select an option

Save soegaard/8567959 to your computer and use it in GitHub Desktop.
(define-syntax (myapply stx)
(define (is-underscore? x) (equal? '_ (syntax->datum x)))
(syntax-case stx ()
[(_ fun . args)
(let* ([missing-ids (dar (filter is-underscore? (syntax->list #'args)))]
[new-ids (dar (take (length missing-ids) (generate-temporaries #'args)))]
[new-args (dar (replace-if is-underscore? (syntax->list #'args) new-ids))])
(with-syntax ([(new-arg ...) new-args]
[(new-id ...) new-ids])
#'(lambda (new-id ...) (fun new-arg ...))))]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment