greghendershott / rackjure

Provide a few Clojure-inspired ideas in Racket. Where Racket and Clojure conflict, prefer Racket.
BSD 2-Clause "Simplified" License
236 stars 17 forks source link

add keyword arguments to reader function literals #38

Closed AlexKnauth closed 10 years ago

AlexKnauth commented 10 years ago

add keyword arguments to reader function literals and also allow an arbitrary number of arguments, and also handle skipped arguments, and both % and %1.
Examples:

#lang rackjure
(map #λ(+ % 1) '(1 2 3))                   ;=> '(2 3 4)
(map #λ(+ % %2) '(1 2 3) '(1 2 3))         ;=> '(2 4 6)
(#λ(apply list* % %&) 1 '(2 3))            ;=> '(1 2 3)
(#λ(* 1/2 %#:m (* %#:v %#:v)) #:m 2 #:v 1) ;=> 1        ; keyword-arguments
(define x (#λ"I am x"))
(#λx)                                      ;=> "I am x" ;the body doesn't have to be in parens
(#λ(begin (set! % "%") %1) "%1")           ;=> "%"      ;% means exactly the same as %1,
                                                        ;and you can even use both at the same time,
                                                        ;and even set!-ing one set!s the other.
(#λ%2 "ignored" "%2")                      ;=> "%2"     ;handles skipped arguments
(apply #λ%42 (build-list 42 add1))         ;=> 42       ;handles an arbitrary number of arguments
greghendershott commented 10 years ago

Very cool! Thanks!

It's nice that you extended it for arbitrary arguments. I like how you made % an alias for %1 using a rename transformer; great idea. And I really like that you extended it for #:keyword arguments, which hadn't occurred to me, and is awesome.

I'm going to update the Scribble docs, and reformat/refactor some of the code, then merge.