Whitespace cleanup
This commit is contained in:
50
d-.scm
50
d-.scm
@@ -45,8 +45,8 @@
|
||||
(define-syntax-rule (if-let ([ident test]) expr ...)
|
||||
(let ([ident test])
|
||||
(if ident
|
||||
(begin expr ...)
|
||||
#f)))
|
||||
(begin expr ...)
|
||||
#f)))
|
||||
|
||||
(define-syntax for
|
||||
(syntax-rules ()
|
||||
@@ -54,20 +54,20 @@
|
||||
[(for ([ident lst] bindings ...) expr ...)
|
||||
(let iter ([rest lst])
|
||||
(if (pair? rest)
|
||||
(let ([ident (car rest)])
|
||||
(append (for (bindings ...) expr ...) (iter (cdr rest))))
|
||||
'()))]))
|
||||
(let ([ident (car rest)])
|
||||
(append (for (bindings ...) expr ...) (iter (cdr rest))))
|
||||
'()))]))
|
||||
|
||||
(define (partial fn . args)
|
||||
(lambda x (apply fn (append args x))))
|
||||
|
||||
(define (argmin arg lt? . vals)
|
||||
(reduce (lambda (val min)
|
||||
(if (lt? (arg val) (arg min))
|
||||
val
|
||||
min))
|
||||
#f
|
||||
vals))
|
||||
(if (lt? (arg val) (arg min))
|
||||
val
|
||||
min))
|
||||
#f
|
||||
vals))
|
||||
|
||||
(define (iterate n f v)
|
||||
"Repeatedly call f on values returned from (f v)"
|
||||
@@ -85,16 +85,16 @@
|
||||
(if (null? preds)
|
||||
(lambda (x) #t)
|
||||
(lambda (x)
|
||||
(if ((car preds) x)
|
||||
((apply conjoin (cdr preds)) x)
|
||||
#f))))
|
||||
(if ((car preds) x)
|
||||
((apply conjoin (cdr preds)) x)
|
||||
#f))))
|
||||
|
||||
(define (distinct? . a)
|
||||
"Are all values distinct, as in equal?"
|
||||
(if (or (null? a) (null? (cdr a)))
|
||||
#t
|
||||
(and (not (any (lambda (x) (equal? (car a) x)) (cdr a)))
|
||||
(apply distinct? (cdr a)))))
|
||||
(apply distinct? (cdr a)))))
|
||||
|
||||
;; Shamelessly ripped from https://wingolog.org/archives/2013/02/25/on-generators
|
||||
(define (make-generator f)
|
||||
@@ -105,8 +105,8 @@
|
||||
(call-with-prompt tag
|
||||
thunk
|
||||
(lambda (k value)
|
||||
(set! thunk k)
|
||||
value))))
|
||||
(set! thunk k)
|
||||
value))))
|
||||
|
||||
(define-syntax generator
|
||||
;; generator with an anaphoric yield
|
||||
@@ -114,9 +114,9 @@
|
||||
(syntax-case x ()
|
||||
[(generator expr ...)
|
||||
(with-syntax ([yield (datum->syntax x 'yield)])
|
||||
#'(make-generator
|
||||
(lambda (yield)
|
||||
expr ...)))])))
|
||||
#'(make-generator
|
||||
(lambda (yield)
|
||||
expr ...)))])))
|
||||
|
||||
;; Why wasn't this included?
|
||||
(define macro-expand (compose tree-il->scheme macroexpand))
|
||||
@@ -131,12 +131,12 @@
|
||||
[(amb a b ...)
|
||||
(let ([fail0 *fail*])
|
||||
(call/cc
|
||||
(lambda (cc)
|
||||
(set! *fail*
|
||||
(lambda ()
|
||||
(set! *fail* fail0)
|
||||
(cc (amb b ...))))
|
||||
(cc a))))]))
|
||||
(lambda (cc)
|
||||
(set! *fail*
|
||||
(lambda ()
|
||||
(set! *fail* fail0)
|
||||
(cc (amb b ...))))
|
||||
(cc a))))]))
|
||||
(define (amb-reset)
|
||||
;; Shouldn't be necessary, but prompts are hard and I'm dumb dumb dummy
|
||||
(set! *fail* (lambda () (error "Could not satisfy amb"))))
|
||||
|
||||
Reference in New Issue
Block a user