Skip to content

Commit

Permalink
Support for multiple arguments to curry in producer syntax class.
Browse files Browse the repository at this point in the history
  • Loading branch information
dzoep committed Nov 5, 2023
1 parent 8f036e1 commit 47c23cd
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions qi-lib/flow/core/compiler.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,23 @@
(define (compile-flow stx)
(process-bindings (optimize-flow stx)))

;; TODO: define another syntax class, fusable-stream-producer,
;; to match e.g. `upto` (range) and `unfold`.
(define-syntax-class fusable-stream-producer
#:attributes (next args)
#:datum-literals (#%host-expression #%partial-application)
(pattern (~and ((~literal esc) (#%host-expression (~literal range)))
#:attributes (next prepare)
#:datum-literals (#%host-expression #%partial-application esc)
(pattern (~and (esc (#%host-expression (~literal range)))
stx)
#:attr next #'range->cstream-next
#:attr prepare #'range->cstream-args)
(pattern (~and ((#%partial-application
(#%host-expression (~literal range)))
(#%host-expression arg) ...)
stx)
#:do [(define chirality (syntax-property #'stx 'chirality))]
#:when (and chirality (eq? chirality 'right))
#:with vindaloo (if (and chirality (eq? chirality 'right))
#'curry
#'curryr)
#:attr next #'range->cstream-next
#:attr args #'range->cstream-args))
#:attr prepare #'(vindaloo range->cstream-args arg ...)))

(define-syntax-class fusable-stream-transformer
#:attributes (f next)
Expand Down Expand Up @@ -108,7 +114,7 @@
((#,@#'g.end
(inline-compose1 [op.next op.f] ...
p.next))
(apply p.args args))))]
(apply p.prepare args))))]
[(g:fusable-stream-consumer op:fusable-stream-transformer ...)
#`(esc (λ (lst)
((#,@#'g.end
Expand Down

0 comments on commit 47c23cd

Please sign in to comment.