From 7fc1554230ce603b3f7fe22466741e13ed1cbe24 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Mon, 29 Feb 2016 09:20:21 -0500 Subject: [PATCH] Support internal definitions in comprehension macros. --- prospect/comprehensions.rkt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/prospect/comprehensions.rkt b/prospect/comprehensions.rkt index 140bd54..63eca1b 100644 --- a/prospect/comprehensions.rkt +++ b/prospect/comprehensions.rkt @@ -37,7 +37,7 @@ [(_ ([acc-id acc-init] ...) () body ...) - #'(begin body ...)] + #'(let () body ...)] [(_ ([acc-id acc-init] ...) ((pat_0 trie_0) clauses ...) @@ -78,7 +78,7 @@ [(_ (clauses (... ...)) body (... ...)) (with-syntax ([loop #'(for-trie/fold ([acc initial]) (clauses (... ...)) - (folder (begin body (... ...)) acc))]) + (folder (let () body (... ...)) acc))]) (build-fold #'loop stx))]))])) (make-fold for-trie/list cons empty) @@ -99,7 +99,7 @@ [(_ (clauses ...) body ...) (with-syntax ([loop #'(for-trie/fold ([acc (void)]) (clauses ...) - (begin body ... acc))]) + (begin (let () body ...) acc))]) (build-fold #'loop stx))])) (module+ test @@ -123,6 +123,14 @@ bar) (set 1 2 3)) + ;; We should support internal definitions. + (check-equal? (for-trie/set ([(foo $bar $zot) (make-trie (foo 1 2) + (foo 3 4) + (foo 5 6))]) + (define sum (+ bar zot)) + sum) + (set 3 7 11)) + (check-equal? (for-trie/list ([$x (make-trie 1 2 3 4)] #:where (even? x)) (+ x 1)) @@ -213,4 +221,4 @@ (set-add! a-set x)) (void)) ;; for-trie runs body for effects - (check-equal? a-set (mutable-set 1 2 3 4)))) \ No newline at end of file + (check-equal? a-set (mutable-set 1 2 3 4))))