Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions qi-lib/flow.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
racket/function
(only-in racket/list
make-list)
(only-in racket/string
string-prefix?
string-suffix?)
(for-syntax racket/base
syntax/parse
(only-in "private/util.rkt"
Expand All @@ -33,14 +36,26 @@ module, defined after the flow macro. They are all invoked as needed
in the flow macro.
|#

(define-syntax-parser flow
[(_ onex) ((compose compile-flow expand-flow) #'onex)]
;; a non-flow
[_ #'values]
;; error handling catch-all
[(_ expr0 expr ...+)
(report-syntax-error
'flow
(syntax->datum #'(expr0 expr ...))
"(flow flo)"
"flow expects a single flow specification, but it received many.")])
(define-syntax (flow stx)
(syntax-parse stx
[(_ onex)
#:with name (syntax-local-name)
(quasisyntax/loc stx
(let ([compiled-flow #,((compose compile-flow expand-flow) #'onex)])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it would be nice to add a comment here explaining the reason for this block of code, i.e. that it allows the name of the function to be inferred by the compiler and supports helpful error messages.

(cond
[(and 'name (procedure? compiled-flow)
(let ([fname (format "~a" (object-name compiled-flow))])
(or (member fname '("#f" "composed"))
(and (string-prefix? fname "compiled-")
(string-suffix? fname "-flow")))))
(procedure-rename compiled-flow 'name)]
[else compiled-flow])))]
;; a non-flow
[_ #'values]
;; error handling catch-all
[(_ expr0 expr ...+)
(report-syntax-error
'flow
(syntax->datum #'(expr0 expr ...))
"(flow flo)"
"flow expects a single flow specification, but it received many.")]))