PasteRack.org
Paste # 2927
2017-01-17 02:42:09

Fork as a new paste.

Paste viewed 448 times.


Embed:

define-syntax with multiple parameters

#lang racket/base
; lambda-define.rkt
; GPL-3+

(struct λ-access (proc list)
  #:property prop:procedure
  (struct-field-index proc))

(define-syntax λ-define
  (syntax-rules ()
    ; no parameters
    [(_ (id) body0 ...)
     (begin
       (define id
         (λ-access (procedure-rename (λ () body0 ...) (quote id))
                   `(λ () body0 ...))))]
    ; one or more parameters
    [(_ (id arg0 ...) body0 ...)
     (begin
       (define id
         (λ-access (procedure-rename (λ (arg0 ...) body0 ...) (quote id))
                   `(λ ,(list (arg0 ...)) body0 ...))))]))

; x: unbound identifier in: x
(λ-define (foo x y z) (values x y z))
(λ-access-list foo) ; => '(λ (x y z) (values x y z))