guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about how to get the value of function


From: No Itisnt
Subject: Re: Question about how to get the value of function
Date: Mon, 31 May 2010 12:46:36 -0500

>>(define y '(1 2 3 4))
>>(define dt 1)
>>(define foo
>       (lambda (t) (do ((i 0 (+ i 1))) ((> i 3)) (if (and (>= t 0) (and (>= t
> (* i dt)) (< t (* (+ i 1) dt)))) (list-ref y i) #f))))

DO does not return its body. It can be a little confusing.

http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.2.4

Also I think you have an extra AND there. You can have as many
arguments to AND as you need, so doing (and 1 (and 2 3)) is the same
as (and 1 2 3).

You can accomplish the same thing with LET. I think this does what you want:

> (define (foo t)
>   (let loop ((i 0))
>     (if (and (>= t 0) (>= t (* i dt)) (< t (* (+ i 1) dt)))
>         (list-ref y i)
>         (if (> i 3)
>           #f
>           (loop (+ i 1))))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]