You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
570 B
Racket
18 lines
570 B
Racket
9 years ago
|
#lang racket/base
|
||
6 years ago
|
(require (for-syntax
|
||
|
racket/base
|
||
4 years ago
|
sugar/private/syntax-utils)
|
||
6 years ago
|
"define.rkt")
|
||
8 years ago
|
|
||
9 years ago
|
(define+provide+safe (make-caching-proc base-proc)
|
||
|
(procedure? . -> . procedure?)
|
||
|
(let ([cache (make-hash)])
|
||
8 years ago
|
(make-keyword-procedure
|
||
|
(λ (kws kw-args . args)
|
||
8 years ago
|
(hash-ref! cache (list* kws kw-args args) (λ () (keyword-apply base-proc kws kw-args args)))))))
|
||
|
|
||
9 years ago
|
(provide+safe define/caching)
|
||
|
(define-syntax (define/caching stx)
|
||
6 years ago
|
(with-syntax ([(ID LAMBDA-EXPR) (lambdafy stx)])
|
||
|
#'(define ID (make-caching-proc LAMBDA-EXPR))))
|