A bit of modernity yields this: (define (project-pop.v1 y r k thetasd t [i 1]) (cond [(= i t) (list y)] [else (define theta (flvector-ref (flnormal-sample 0.0 thetasd 1) 0)) (define y1 (* y (- r (* r (/ y k))) (exp theta))) (cons y (project-pop y1 r k thetasd t (+ i 1)))]))
Since this is really a fold, you could also use one of the Racket comprehensions to bring across the intent: (define (project-pop.v2 y r k thetasd t) (define-values (_ l) (for/fold ((y y) (l '())) ((i (in-range 0 t 1))) (define theta (flvector-ref (flnormal-sample 0.0 thetasd 1) 0)) (values (* y (- r (* r (/ y k))) (exp theta)) (cons y l)))) (reverse l)) Given how short these functions are, v1 is just fine. Or you could stick to the original R design and write an imperative vector-fill function: (define (project-pop.v3 y0 r k thetasd t) (define y (make-vector t y0)) (for ((i (in-range 1 t 1))) (define theta (flnormal-sample 0.0 thetasd 1)) (define y@i-1 (vector-ref y (- i 1))) (vector-set! y i (* y@i-1 (- r (* r (/ y@i-1 k))) (exp (flvector-ref theta 0))))) y) -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.