From 8faa51dd008e6526544fd0fbbc8c8a34ef8066ec Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 14 Jun 2017 23:53:21 -0700 Subject: [PATCH] touch --- pitfall/restructure/pointer.rkt | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/pitfall/restructure/pointer.rkt b/pitfall/restructure/pointer.rkt index e3fedb2f..7462a742 100644 --- a/pitfall/restructure/pointer.rkt +++ b/pitfall/restructure/pointer.rkt @@ -1,22 +1,21 @@ -#lang br +#lang restructure/racket (define pointer-ks (make-hash)) (define results (make-hash)) (define vals '(a b (h) d e f g h i j)) -(for ([(val i) (in-indexed vals)]) - (hash-ref! results i (λ () - (report* results i) - (let/cc pointer-k - (let ([v (cond - [(pair? val) (hash-set! pointer-ks (car val) pointer-k) (car val)] - [else val])]) - (define pointer (hash-ref pointer-ks v #f)) - (cond - [pointer (hash-remove! pointer-ks v) - (pointer (format "~a xref" v))] - [else v])))))) - -(for/list ([i (in-range (length (hash-keys results)))]) - (hash-ref results i)) \ No newline at end of file +(for ([(val i) (in-indexed vals)] + #:unless (hash-has-key? results val)) + (hash-set! results i (let/cc pointer-k + (cond + [(hash-ref pointer-ks val #f) => (λ (pk) + (hash-remove! pointer-ks val) + (pk (format "~a@~a" val i)))] + [(pair? val) (hash-set! pointer-ks (car val) pointer-k) 'tbd] + [else val])))) +(test-module + (check-equal? + (for/list ([i (in-range (length (hash-keys results)))]) + (hash-ref results i)) + '(a b "h@7" d e f g h i j))) \ No newline at end of file