Utilize a library function to find list indices
This commit is contained in:
@@ -88,17 +88,13 @@
|
||||
(closed-environment closure-closed-environment))
|
||||
|
||||
;; Helpers
|
||||
(define (find-indexed pred lst)
|
||||
(find (lambda (kons) (pred (car kons)))
|
||||
(zip lst (iota (length lst)))))
|
||||
|
||||
(define (local-variable env ref)
|
||||
(let scan-env ([env env] [i 0])
|
||||
(if (null? env)
|
||||
#f
|
||||
(let ([the-match (find-indexed (lambda (name) (eq? name ref)) (car env))])
|
||||
(if the-match
|
||||
`(local ,i . ,(cadr the-match))
|
||||
(let ([j (list-index (lambda (name) (eq? name ref)) (car env))])
|
||||
(if j
|
||||
`(local ,i . ,j)
|
||||
(scan-env (cdr env) (+ i 1)))))))
|
||||
|
||||
(define (global-variable env ref)
|
||||
|
||||
@@ -95,17 +95,13 @@
|
||||
(closed-environment closure-closed-environment))
|
||||
|
||||
;; Helpers
|
||||
(define (find-indexed pred lst)
|
||||
(find (lambda (kons) (pred (car kons)))
|
||||
(zip lst (iota (length lst)))))
|
||||
|
||||
(define (local-variable env ref)
|
||||
(let scan-env ([env env] [i 0])
|
||||
(if (null? env)
|
||||
#f
|
||||
(let ([the-match (find-indexed (lambda (name) (eq? name ref)) (car env))])
|
||||
(if the-match
|
||||
`(local ,i . ,(cadr the-match))
|
||||
(let ([j (list-index (lambda (name) (eq? name ref)) (car env))])
|
||||
(if j
|
||||
`(local ,i . ,j)
|
||||
(scan-env (cdr env) (+ i 1)))))))
|
||||
|
||||
(define (global-variable env ref)
|
||||
@@ -151,6 +147,7 @@
|
||||
(if (zero? i)
|
||||
(activation-rec-ref r j)
|
||||
(activation-rec-ref (activation-record-next r) (1- i) j))]))
|
||||
|
||||
(define (activation-rec-length r)
|
||||
(vector-length (activation-record-vals r)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user