> On Apr 15, 2017, at 7:16 AM, Angus <[email protected]> wrote:
>
> I am doing it using cond like this:
>
> (define (lines t)
> (cond [(and (false? (node-l t)) (false? (node-r t))) <<do no children
> thing>>] ;; if no children
> [(and (false? (node-l t)) (not (node-r t))) <<left child only>>] ;;
> if left child only
> [(and (node-l t) (false? (node-r t))) <<right child only>> ] ;; if
> right child only
> [else <<both children>> ])) ;; if both children
`cond` expressions can be simplified by remembering that later conditions are
only evaluated if the preceding conditions were false. Personally I find that
the `false?` predicate makes things harder to read:
(define (f pr)
(cond
[(car pr)
(if (cdr pr)
'both
'left)]
[(cdr pr) 'right]
[else 'neither]))
(f (cons #t #t)) ; 'both
(f (cons #t #f)) ; 'left
(f (cons #f #t)) ; 'right
(f (cons #f #f)) ; 'neither
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.