[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question about how to get the value of function
From: |
Linas Vepstas |
Subject: |
Re: Question about how to get the value of function |
Date: |
Mon, 31 May 2010 12:40:44 -0500 |
2010/5/31 Hsiu-Hao Tsao <address@hidden>:
> Hello plt-scheme users ,
>
> I am new to scheme and sorry to ask a newbie question.
>
> I want to let function return the value , for example , in Drscheme :
>
>>(define add2 (lambda (i) (+ i i)))
>>(add2 2)
> 4
>
> I type (add2 2) in command line and it will return a value 4.
>
> But when I type my function foo in the command line
>
>>(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))))
>
>>(foo 0) ---->this should return 1 , but there is no value to come out.
>
>>(foo 1) ---->this should return 2
> .
> .
> .
> and so on.
>
> Can anyone tell me how to solve this problem ? I really appreciate your
> knowledge and hope I won't cause your inconvenience.
(define bar
(lambda (t)
(do
((i 0 (+ i 1)))
((> i 3))
42
)
)
)