diff --git a/qi-doc/scribblings/forms.scrbl b/qi-doc/scribblings/forms.scrbl index 6e6098fdc..a74af067d 100644 --- a/qi-doc/scribblings/forms.scrbl +++ b/qi-doc/scribblings/forms.scrbl @@ -100,6 +100,20 @@ The core syntax of the Qi language. These forms may be used in any @tech{flow}. ] } +@deftogether[( + @defform[(lambda expr ...)] + @defform[(λ expr ...)] +)]{ + Shorthand for @racket[(esc (lambda ...))]. + +That is, this lambda is a @emph{Qi} form that expands to a use of @emph{Racket}'s lambda form, providing a shorthand for a common way to describe a flow using Racket. + +@examples[ + #:eval eval-for-docs + ((☯ (λ (x) (+ 2 x))) 3) + ] +} + @defform[(clos flo)]{ A @tech{flow} that generates a flow as a value. Any inputs to the @racket[clos] flow are available to @racket[flo] when it is applied to inputs, i.e. it is analogous to a @hyperlink["https://www.gnu.org/software/guile/manual/html_node/Closure.html"]{closure} in Racket. diff --git a/qi-lib/flow/core/private/form-property.rkt b/qi-lib/flow/core/private/form-property.rkt index 035e4eb7e..c8aba01cf 100644 --- a/qi-lib/flow/core/private/form-property.rkt +++ b/qi-lib/flow/core/private/form-property.rkt @@ -18,8 +18,7 @@ (provide form-position? attach-form-property - tag-form-syntax - get-form-property) + tag-form-syntax) (require (only-in racket/function curry)) @@ -43,9 +42,6 @@ (define (attach-form-property stx) (syntax-property stx 'nonterminal 'floe)) -(define (get-form-property stx) - (syntax-property stx 'nonterminal)) - ;; This traverses a syntax object and indiscriminately tags every node ;; as a form. If this operation were applied to syntax in the real ;; compiler, it would of course lead to the incorrect optimizations we diff --git a/qi-lib/flow/extended/expander.rkt b/qi-lib/flow/extended/expander.rkt index c40d1ae1c..7206ade51 100644 --- a/qi-lib/flow/extended/expander.rkt +++ b/qi-lib/flow/extended/expander.rkt @@ -182,6 +182,10 @@ core language's use of #%app, etc.). clos (clos onex:closed-floe) (esc ex:racket-expr) + (~> ((~literal lambda) e ...) + #'(esc (lambda e ...))) + (~> ((~literal λ) e ...) + #'(lambda e ...)) ;; core form to express deforestable operations (#%deforestable name:id info:id e:deforestable-clause ...) diff --git a/qi-test/tests/flow.rkt b/qi-test/tests/flow.rkt index f7e765380..46ed1e410 100644 --- a/qi-test/tests/flow.rkt +++ b/qi-test/tests/flow.rkt @@ -285,6 +285,11 @@ (check-equal? ((☯ (esc (first (list + *)))) 3 7) 10 "normal racket expressions")) + (test-suite + "lambda escape shortcut" + (check-equal? ((☯ (lambda (v) v)) 3) 3) + (check-equal? ((☯ (λ (v) v)) 3) 3) + (check-equal? ((☯ (λ () 3))) 3)) (test-suite "elementary boolean gates" (test-suite