Get rid of unnecessary lambdas in `hash-ref` calls

remotes/jackfirth/master
Jack Firth 3 years ago
parent d1c41aece2
commit 138c11b908

@ -199,7 +199,7 @@
;; Reports an answer to a waiting thread:
(define (report-answer answer-key max-depth ts val)
(define v (hash-ref (tasks-waits ts) answer-key (λ () #f)))
(define v (hash-ref (tasks-waits ts) answer-key #f))
(if v
(let ([ts (tasks (cons (v val) (tasks-active ts))
(tasks-active-back ts)
@ -218,7 +218,7 @@
;; Reports an answer to multiple waiting threads:
(define (report-answer-all answer-key max-depth ts val k)
(define v (hash-ref (tasks-multi-waits ts) answer-key (λ () '())))
(define v (hash-ref (tasks-multi-waits ts) answer-key '()))
(hash-remove! (tasks-multi-waits ts) answer-key)
(let ([ts (tasks (append (map (λ (a) (a val)) v)
(tasks-active ts))
@ -244,7 +244,7 @@
(if multi?
(hash-set! (tasks-multi-waits ts) answer-key
(cons wait (hash-ref (tasks-multi-waits ts) answer-key
(λ () '()))))
'())))
(hash-set! (tasks-waits ts) answer-key wait))
(let ([ts (tasks (tasks-active ts)
(tasks-active-back ts)
@ -407,7 +407,7 @@
;; Check whether we already have a result that consumed the same amount:
(define result-key (vector #f key old-depth depth))
(cond
[(hash-ref (tasks-cache tasks) result-key (λ () #f))
[(hash-ref (tasks-cache tasks) result-key #f)
;; Go for the next-result
(result-loop max-depth
tasks

@ -63,7 +63,7 @@
[(exp) $1])
(exp [(NUM) $1]
[(VAR) (hash-ref vars $1 (lambda () 0))]
[(VAR) (hash-ref vars $1 0)]
[(VAR = exp) (begin (hash-set! vars $1 $3)
$3)]
[(FNCT OP exp CP) ($1 $3)]

@ -267,7 +267,7 @@
s
(cons (cons c new-state)
(hash-ref transitions s
(λ () '()))))
'())))
(cond
[new-state?
(loop old-states (cons new-state new-states) new-all-states (cdr cs))]

@ -71,7 +71,7 @@
(for/list ([term-sym (in-list term-list)])
(term term-sym
#f
(hash-ref prec-table term-sym (λ () #f)))))
(hash-ref prec-table term-sym #f))))
;; Retrieves the terminal symbols from a terminals-def (See terminal-syntax.rkt)
;; get-terms-from-def: identifier? -> (listof identifier?)

@ -186,7 +186,7 @@
(define gs (trans-key-gs tk))
(hash-ref (vector-ref map (kernel-index st))
(gram-sym-symbol gs)
(λ () 0)))
0))
;; add-tk-map : (vectorof (symbol? int hashtable)) -> trans-key int ->
(define ((add-tk-map map) tk v)

@ -59,7 +59,7 @@
(define (reverse-assoc assoc)
(define reverse-hash (make-hash))
(define (hash-table-add! ht k v)
(hash-set! ht k (cons v (hash-ref ht k (λ () '())))))
(hash-set! ht k (cons v (hash-ref ht k '()))))
(for ([trans-key/kernel (in-list assoc)])
(define tk (car trans-key/kernel))
(hash-table-add! reverse-hash
@ -118,7 +118,7 @@
(define/public (run-automaton k s)
(hash-ref (vector-ref transitions (kernel-index k))
(gram-sym-symbol s)
(λ () #f)))
#f))
;; run-automaton-back : (listof kernel?) gram-sym? -> (listof kernel)
;; returns the list of states that can reach k by transitioning on s.
@ -126,7 +126,7 @@
(for*/list ([k (in-list k)]
[val (in-list (hash-ref (vector-ref reverse-transitions (kernel-index k))
(gram-sym-symbol s)
(λ () '())))])
'()))])
val))))
(define ((union comp<?) l1 l2)
@ -216,11 +216,11 @@
(define (add-item! table i)
(define gs (sym-at-dot i))
(cond
[gs (define already (hash-ref table (gram-sym-symbol gs) (λ () '())))
[gs (define already (hash-ref table (gram-sym-symbol gs) '()))
(unless (member i already)
(hash-set! table (gram-sym-symbol gs) (cons i already)))]
((zero? (vector-length (prod-rhs (item-prod i))))
(define current (hash-ref epsilons ker (λ () '())))
(define current (hash-ref epsilons ker '()))
(hash-set! epsilons ker (cons i current)))))
;; Group the items of the LR0 closure of the kernel
@ -237,7 +237,7 @@
(cond
[(null? gsyms) '()]
[else
(define items (hash-ref table (gram-sym-symbol (car gsyms)) (λ () '())))
(define items (hash-ref table (gram-sym-symbol (car gsyms)) '()))
(cond
[(null? items) (loop (cdr gsyms))]
[else (cons (list (car gsyms) items)

@ -22,7 +22,7 @@
(for ([term (in-list term-binders)])
(hash-set! t (syntax-e term) term))
(λ (x)
(define r (hash-ref t (syntax-e x) (λ () #f)))
(define r (hash-ref t (syntax-e x) #f))
(if r
(syntax-local-introduce (datum->syntax r (syntax-e x) x x))
x))))

@ -30,7 +30,7 @@
(for/vector ([state-entry (in-list (vector->list table))])
(define ht (make-hasheq))
(for* ([gs/actions (in-list state-entry)]
[group (in-value (hash-ref ht (car gs/actions) (λ () '())))]
[group (in-value (hash-ref ht (car gs/actions) '()))]
#:unless (member (cdr gs/actions) group))
(hash-set! ht (car gs/actions) (cons (cdr gs/actions) group)))
(hash-map ht cons)))
@ -226,7 +226,7 @@
(kernel-index to-state))))))
(send a for-each-state
(λ (state)
(for ([item (in-list (append (hash-ref (send a get-epsilon-trans) state (λ () '()))
(for ([item (in-list (append (hash-ref (send a get-epsilon-trans) state '())
(filter (λ (item)
(not (move-dot-right item)))
(kernel-items state))))])

Loading…
Cancel
Save