From 138c11b9087befa56c8d284e123fef1dce106722 Mon Sep 17 00:00:00 2001 From: Jack Firth Date: Wed, 30 Mar 2022 01:35:12 -0700 Subject: [PATCH] Get rid of unnecessary lambdas in `hash-ref` calls --- parser-tools/cfg-parser.rkt | 8 ++++---- parser-tools/examples/calc.rkt | 2 +- parser-tools/private-lex/deriv.rkt | 2 +- parser-tools/private-yacc/input-file-parser.rkt | 2 +- parser-tools/private-yacc/lalr.rkt | 2 +- parser-tools/private-yacc/lr0.rkt | 12 ++++++------ parser-tools/private-yacc/parser-builder.rkt | 2 +- parser-tools/private-yacc/table.rkt | 4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/parser-tools/cfg-parser.rkt b/parser-tools/cfg-parser.rkt index 227c8e0..87b8049 100644 --- a/parser-tools/cfg-parser.rkt +++ b/parser-tools/cfg-parser.rkt @@ -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 diff --git a/parser-tools/examples/calc.rkt b/parser-tools/examples/calc.rkt index 7ab406f..2e1c125 100644 --- a/parser-tools/examples/calc.rkt +++ b/parser-tools/examples/calc.rkt @@ -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)] diff --git a/parser-tools/private-lex/deriv.rkt b/parser-tools/private-lex/deriv.rkt index d3f014a..77b7488 100644 --- a/parser-tools/private-lex/deriv.rkt +++ b/parser-tools/private-lex/deriv.rkt @@ -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))] diff --git a/parser-tools/private-yacc/input-file-parser.rkt b/parser-tools/private-yacc/input-file-parser.rkt index 7ddd62c..51605e4 100644 --- a/parser-tools/private-yacc/input-file-parser.rkt +++ b/parser-tools/private-yacc/input-file-parser.rkt @@ -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?) diff --git a/parser-tools/private-yacc/lalr.rkt b/parser-tools/private-yacc/lalr.rkt index 99a221c..8be4333 100644 --- a/parser-tools/private-yacc/lalr.rkt +++ b/parser-tools/private-yacc/lalr.rkt @@ -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) diff --git a/parser-tools/private-yacc/lr0.rkt b/parser-tools/private-yacc/lr0.rkt index 9684822..193cd24 100644 --- a/parser-tools/private-yacc/lr0.rkt +++ b/parser-tools/private-yacc/lr0.rkt @@ -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 compsyntax r (syntax-e x) x x)) x)))) diff --git a/parser-tools/private-yacc/table.rkt b/parser-tools/private-yacc/table.rkt index faa1a82..9aa90d4 100644 --- a/parser-tools/private-yacc/table.rkt +++ b/parser-tools/private-yacc/table.rkt @@ -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))))])