[plt-scheme] Question about how to get the value of function

From: Stephen Chang (stchang at ccs.neu.edu)
Date: Mon May 31 10:46:37 EDT 2010

If you do not give do a finish-expr, then it will evaluate to void,
which is what is happening with your code:

http://download.plt-scheme.org/doc/html/reference/for.html?q=do#%28form._%28%28lib._scheme/private/more-scheme..ss%29._do%29%29



2010/5/31 Hsiu-Hao Tsao <s_h_tsao at hotmail.com>:
> 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.
>
> Best Regards ,
>
> Hsiu-Hao Tsao
>
> Master Student
>
> Ultrafast Photonics Laboratory ,
> Institute Photonics of Technologies ,
> National Tsing Hua University , Taiwan
>
> Lab : +8863-5715131-34178
> Office : +8863-5715131-34007
> Cell Phone : +886920158033
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>


Posted on the users mailing list.