Skip to content

Commit

Permalink
Merge pull request #177 from countvajhula/lambda-core-form
Browse files Browse the repository at this point in the history
Lambda core form
  • Loading branch information
countvajhula authored Dec 7, 2024
2 parents 4d6ed0d + 72f8031 commit 4a45a19
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
14 changes: 14 additions & 0 deletions qi-doc/scribblings/forms.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 1 addition & 5 deletions qi-lib/flow/core/private/form-property.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions qi-lib/flow/extended/expander.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...)
Expand Down
5 changes: 5 additions & 0 deletions qi-test/tests/flow.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4a45a19

Please sign in to comment.