www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

keyword-lambda.rkt (1225B)


      1 #lang racket/base
      2 
      3 (provide keyword-lambda)
      4 
      5 (require "kw-lists-lambda.rkt")
      6 (module+ test
      7   (require rackunit
      8            racket/local))
      9 
     10 (define-syntax-rule (keyword-lambda (kws kw-args . rest-args) body ...)
     11   (kw-lists-lambda kws kw-args rest-args body ...))
     12 
     13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     14 
     15 (module+ test
     16   (local [(define proc
     17             (keyword-lambda (kws kw-args . rest-args)
     18               (list kws kw-args rest-args)))]
     19     (check-equal? (proc #:a 'a #:b 'b 0 1 2)
     20                   (list '(#:a #:b) '(a b) '(0 1 2)))
     21     (check-equal? (object-name proc) 'proc)
     22     )
     23   (local [(define proc0
     24             (keyword-lambda (kws kw-args)
     25               (list kws kw-args)))
     26           (define proc1
     27             (keyword-lambda (kws kw-args x)
     28               (list kws kw-args x)))]
     29     (check-equal? (proc0 #:a 'a #:b 'b)
     30                   (list '(#:a #:b) '(a b)))
     31     (check-equal? (proc1 #:a 'a 'x #:b 'b)
     32                   (list '(#:a #:b) '(a b) 'x))
     33     (check-equal? (object-name proc0) 'proc0)
     34     (check-equal? (object-name proc1) 'proc1)
     35     (check-equal? (procedure-arity proc0) 0)
     36     (check-equal? (procedure-arity proc1) 1)
     37     )
     38   )