Skip to content

Commit

Permalink
change deforestable "spec" syntax
Browse files Browse the repository at this point in the history
Just `f` and `e` seem to make it hard to know which is the actual
binding position in, e.g., `[f f] [e e]`, so that we might be tempted
to write something like `[my-func f]`. Using the nonterminal names
`floe` and `expr` seem more explicit in indicating what kind of syntax
is expected while avoiding potential confusion with the binding
position.
  • Loading branch information
countvajhula committed Dec 28, 2024
1 parent 9dff1ae commit 576535e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions qi-lib/flow/core/compiler/1000-qi0.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ the DSL.

(define (deforestable-clause-parser c)
(syntax-parse c
[((~datum f) e) #'(qi0->racket e)]
[((~datum e) e) #'e]))
[((~datum floe) e) #'(qi0->racket e)]
[((~datum expr) e) #'e]))

(define (deforestable-parser e)
(syntax-parse e
Expand Down
20 changes: 10 additions & 10 deletions qi-lib/flow/core/compiler/deforest/syntax.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#:attributes (blanket? fine? arg pre-arg post-arg)
#:literal-sets (fs-literals)
#:datum-literals (range)
(pattern (#%deforestable range _info ((~datum e) the-arg) ...)
(pattern (#%deforestable range _info ((~datum expr) the-arg) ...)
#:attr arg #'(the-arg ...)
#:attr pre-arg #f
#:attr post-arg #f
Expand Down Expand Up @@ -79,28 +79,28 @@
#:attributes (f)
#:literal-sets (fs-literals)
#:datum-literals (filter)
(pattern (#%deforestable filter _info ((~datum f) f-uncompiled))
(pattern (#%deforestable filter _info ((~datum floe) f-uncompiled))
#:attr f (run-passes #'f-uncompiled)))

(define-syntax-class fst-map
#:attributes (f)
#:literal-sets (fs-literals)
#:datum-literals (map)
(pattern (#%deforestable map _info ((~datum f) f-uncompiled))
(pattern (#%deforestable map _info ((~datum floe) f-uncompiled))
#:attr f (run-passes #'f-uncompiled)))

(define-syntax-class fst-filter-map
#:attributes (f)
#:literal-sets (fs-literals)
#:datum-literals (filter-map)
(pattern (#%deforestable filter-map _info ((~datum f) f-uncompiled))
(pattern (#%deforestable filter-map _info ((~datum floe) f-uncompiled))
#:attr f (run-passes #'f-uncompiled)))

(define-syntax-class fst-take
#:attributes (n)
#:literal-sets (fs-literals)
#:datum-literals (take)
(pattern (#%deforestable take _info ((~datum e) n))))
(pattern (#%deforestable take _info ((~datum expr) n))))

(define-syntax-class fst-syntax0
(pattern (~or _:fst-filter
Expand All @@ -127,8 +127,8 @@
(pattern (#%deforestable
foldr
_info
((~datum f) op-uncompiled)
((~datum e) init))
((~datum floe) op-uncompiled)
((~datum expr) init))
#:attr op (run-passes #'op-uncompiled)))

(define-syntax-class fsc-foldl
Expand All @@ -138,8 +138,8 @@
(pattern (#%deforestable
foldl
_info
((~datum f) op-uncompiled)
((~datum e) init))
((~datum floe) op-uncompiled)
((~datum expr) init))
#:attr op (run-passes #'op-uncompiled)))

(define-syntax-class cad*r-datum
Expand All @@ -155,7 +155,7 @@
#:literal-sets (fs-literals)
#:datum-literals (list-ref)
;; TODO: need #%host-expression wrapping idx?
(pattern (#%deforestable list-ref _info ((~datum e) idx))
(pattern (#%deforestable list-ref _info ((~datum expr) idx))
#:attr pos #'idx
#:attr name #'list-ref)
;; TODO: bring wrapping #%deforestable out here?
Expand Down
4 changes: 2 additions & 2 deletions qi-lib/flow/extended/expander.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ core language's use of #%app, etc.).
#'(esc spaced-f)))

(nonterminal deforestable-clause
((~datum f) e:closed-floe)
((~datum e) g:racket-expr))
((~datum floe) e:closed-floe)
((~datum expr) g:racket-expr))

(nonterminal arg-stx
(~datum _)
Expand Down
16 changes: 8 additions & 8 deletions qi-lib/list.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@
(prefix-in r: racket/base)
(prefix-in r: racket/list))

(define-deforestable (map [f f])
(define-deforestable (map [floe f])
#'(lambda (vs) ; single list arg
(r:map f vs)))

(define-deforestable (filter [f f])
(define-deforestable (filter [floe f])
#'(λ (vs)
(r:filter f vs)))

(define-deforestable (filter-map [f f])
(define-deforestable (filter-map [floe f])
#'(λ (vs)
(r:filter-map f vs)))

(define-deforestable (foldl [f f] [e init])
(define-deforestable (foldl [floe f] [expr init])
#'(λ (vs)
(r:foldl f init vs)))

(define-deforestable (foldr [f f] [e init])
(define-deforestable (foldr [floe f] [expr init])
#'(λ (vs)
(r:foldr f init vs)))

(define-deforestable (range [e low] [e high] [e step])
(define-deforestable (range [expr low] [expr high] [expr step])
#'(λ ()
(r:range low high step)))

Expand All @@ -58,7 +58,7 @@
"(range arg ...)"
"range expects at least one argument")])

(define-deforestable (take [e n])
(define-deforestable (take [expr n])
#'(λ (vs)
(r:take vs n)))

Expand All @@ -74,7 +74,7 @@
(define-deforestable cadddr
#'r:cadddr)

(define-deforestable (list-ref [e n])
(define-deforestable (list-ref [expr n])
#'(λ (vs)
(r:list-ref vs n)))

Expand Down
2 changes: 1 addition & 1 deletion qi-lib/macro.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
(define-syntax define-deforestable
(syntax-parser
[(_ (name spec ...+) codegen)
#:with ([typ arg] ...) #'(spec ...)
#:with ([_typ arg] ...) #'(spec ...)
#:with codegen-f #'(lambda (arg ...)
;; var bindings vs pattern bindings
;; arg are syntax objects but we can't
Expand Down

0 comments on commit 576535e

Please sign in to comment.