3 ms·
You should use an empty line to make a new paragraph, and then start every line with two spaces: #lang racket (define memo-table (box empty)) (define-st
by gus_massa 14y ago
You should use an empty line to make a new paragraph, and then start every line with two spaces:
#lang racket
(define memo-table (box empty))
(define-struct memo (key ans))
(define (memoize f)
(lambda args
(local ([define lookup (filter (lambda (v)
(equal? args (memo-key v)))
(unbox memo-table))])
(if (empty? lookup)
(begin (local ([define ans (apply f args)])
(begin
(set-box! memo-table (cons (make-memo args ans)
(unbox memo-table)))
ans)))
(memo-ans (first lookup))))))