refactor this pasted by gahr on Tue Feb 13 11:14:00 2024
(define (cheap-pre-check . args) ; this can return #t of #f #t) (define (expensive-calculation . args) ; this can return #f or some other object (list 'some 'object)) (define (entry-point) (if (not (cheap-pre-check 'foo 'bar)) (list #f 'foobar) (let ((result (expensive-calculation 'baz 'moo))) (if result (list #t result) (list #f 'foobar)))))
alternative pasted by Bunny351 on Tue Feb 13 11:20:42 2024
(define (entry-point)
(let* ((r (cheap-pre-check 'foo 'bar))
(r2 (and r (expensive-calculation 'baz 'moo))))
(list (and r r2 #t) (and r2 'foobar))))
Simpler solution pasted by sjamaan on Tue Feb 13 11:21:04 2024
(define (entry-point)
(or (and (cheap-pre-check 'foo 'bar)
(expensive-calculation 'baz 'moo))
(list #f 'foobar)))
Using cond added by sjamaan on Tue Feb 13 11:24:48 2024
(define (entry-point)
(cond ((and (cheap-pre-check 'foo 'bar)
(expensive-calculation 'baz 'moo))
=> (lambda (result)
(list #t result)))
(else (list #f 'foobar))))