[plt-scheme] Scheme Idiom

From: Anton van Straaten (anton at appsolutions.com)
Date: Thu Sep 5 11:36:10 EDT 2002

> (call-with-current-continuation
>   (lambda (kont)
>     (map (lambda (bool)
> 	   (if bool
>               (kont bool)))
>           lst)
>    #f))
>
> Is there a nicer idiom for this particular task?

I agree with Eli that ormap makes sense.  But if you're going to drag
call/cc into it, I'd like to point out that you could also just do it the
old-fashioned way, by defining a function like this:

(define (orlist lst)
  (cond
    ((null? lst) #f)
    ((car lst) (car lst))
    (else (orlist (cdr lst)))))

Or, if you really want to do it inline:

(let loop ((lst lst))
  (cond
    ((null? lst) #f)
    ((car lst) (car lst))
    (else (loop (cdr lst)))))

BTW, (eval (append '(or) lst)) is buggy - try it with lists containing
quoted values.

Anton




Posted on the users mailing list.