;;; $Id: targets-mod.scm,v 1.2 2006/01/05 22:24:09 leavens Exp $ ;;; AUTHOR: Gary T. Leavens (module targets-mod (lib "typedscm.ss" "typedscm") (provide targets targets-exp) (require (lib "statement-expression.scm" "lib342") ;; you could use your own set-ops (lib "set-ops-as-vector.scm" "lib342")) ;; Examples for this problem: ;; ;; (targets (parse-statement 'x)) ;; = (set ) ;; (targets (parse-statement '(set! x 3))) ;; = (set 'x) ;;(targets ;; (parse-statement ;; '(set! x (begin (set! y 4) y)))) ;; = (set 'x 'y) ;; ;; See targets.tst for more examples. (deftype targets (-> (statement) (set-of symbol))) (define targets (lambda (stmt) ;; ENSURES: result is a set containing all ;; identifiers that are targets of set! statements ;; in stmt. (cond ((exp-stmt? stmt) (targets-exp (exp-stmt->exp stmt))) (else ;; set-stmt case (set-add (set-stmt->id stmt) (targets-exp (set-stmt->exp stmt))))))) (deftype targets-exp (-> (expression) (set-of symbol))) (define targets-exp (lambda (exp) ;; ENSURES: result is a set containing all ;; identifiers that are targets of set! statements ;; in exp. (cond ((begin-exp? exp) (set-union (set-union-list (map targets (begin-exp->stmts exp))) (targets-exp (begin-exp->exp exp)))) (else ;; the same answer for both numbers and identifiers the-empty-set)))) ) ;; end module