[racket] FOR loop
Why don't you use the one that's available in Racket?
On May 4, 2014, at 11:09 PM, Zee Ken wrote:
> Hi. I am trying to implement the for loop.
>
> My for loop structure:
>
> (for <variable> <initial> <limit> <increment> <body>)
>
>
> (define (fvar exp) (cadr exp))
> (define (fstart exp) (car (cddr exp)))
> (define (flimit exp) (car (cdddr exp)))
> (define (fincr exp) (cadr (cdddr exp)))
> (define (fbody exp) (caddr (cdddr exp)))
>
> (define (for exp)
> (begin
> (define (iter current limit step)
> (if (< current limit)
> (begin
> (eval (fbody exp))
> (iter (+ current step) limit step))
> (display "\n")))
> (iter (fstart exp) (flimit exp) (fincr exp))))
>
> I tried executing (for '(i 1 10 4 (display 2))) and it showed:
>
> 222
>
> in the REPL.
>
> It is working well when constants are involved. How can I incorporate the variable binding?
>
> I tried extracting the variable, that is, (fvar exp), it returns 'i=(quote i). How can I define i to be the initial value?
>
>
> --
> Thanking You,
> Zee Ken
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140505/05d9754e/attachment.html>