From 96fe9f46e1c08fea3adf43f994544f6ce31c0ec2 Mon Sep 17 00:00:00 2001 From: Sam Caldwell Date: Fri, 19 Feb 2016 18:46:59 -0500 Subject: [PATCH] add an effectful trie comprehension --- prospect/comprehensions.rkt | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/prospect/comprehensions.rkt b/prospect/comprehensions.rkt index a7d7c14..86a4b75 100644 --- a/prospect/comprehensions.rkt +++ b/prospect/comprehensions.rkt @@ -3,7 +3,8 @@ (provide for-trie/list for-trie/set for-trie/patch - for-trie/fold) + for-trie/fold + for-trie) (require "core.rkt" (only-in "actor.rkt" analyze-pattern) @@ -96,6 +97,15 @@ (make-fold for-trie/patch patch-seq empty-patch) +(define (ret-second a b) b) + +(make-fold for-trie-inner ret-second #f) + +(define-syntax (for-trie stx) + (syntax-case stx () + [(_ more-stx ...) + #'(void (for-trie-inner more-stx ...))])) + (module+ test (require rackunit) @@ -184,5 +194,12 @@ ;; projecting something finite out is ok (check-equal? (for-trie/list ([1 (pattern->trie 'x (projection->pattern ?))]) 1) - (list 1))) + (list 1)) + (let ([a-set (mutable-set)]) + ;; for-trie results in (void) + (check-equal? (for-trie ([$x (make-trie 1 2 3 4)]) + (set-add! a-set x)) + (void)) + ;; for-trie runs body for effects + (check-equal? a-set (mutable-set 1 2 3 4))))