Re: [racket-users] Re: nested for loops and suggested alternatives

2019-02-11 Thread Daniel Prager
Hi Travis Glad you found it instructive. In mathematical terms these kinds of systems map from the current state at t=n to the next time-step at t=n+1. Given a transition function I tend to just use for/list (or for/vector) to build up a history. E.g. #lang racket (require math/matrix)

Re: [racket-users] Re: nested for loops and suggested alternatives

2019-02-10 Thread travis . hinkelman
For the benefit of other beginners, I think there was a small typo in prop-projection.v1 where the intention was to call that function recursively rather than calling pop-projection in the body of pop-projection.v1. The typo is corrected below: (define (pop-projection.v1 A n iter) (if (zero?

Re: [racket-users] Re: nested for loops and suggested alternatives

2019-02-10 Thread Matthias Felleisen
> On Feb 10, 2019, at 7:26 PM, Alex Harsanyi wrote: > > One way to do this is for `pop-abundances` to have an extra parameter, the > list of previous abundances, and whenever the function is called recursively, > it adds the current abundance to this list and passes it on to the next call.

Re: [racket-users] Re: nested for loops and suggested alternatives

2019-02-10 Thread Alex Harsanyi
On Monday, February 11, 2019 at 8:01:47 AM UTC+8, travis.h...@gmail.com wrote: > > Thanks, Daniel, this is helpful. I think that I understand your code, but > it is a still a foreign way of thinking for me. Of course, that is a big > part of why I'm learning Racket, i.e., to make programming

Re: [racket-users] Re: nested for loops and suggested alternatives

2019-02-10 Thread travis . hinkelman
Thanks, Daniel, this is helpful. I think that I understand your code, but it is a still a foreign way of thinking for me. Of course, that is a big part of why I'm learning Racket, i.e., to make programming with lists and recursion more natural. One key gap for me is how to build up data

Re: [racket-users] Re: nested for loops and suggested alternatives

2019-02-10 Thread Laurent
perhaps more importantly: -- (build-vector 5 (lambda (_) (make-vector 5 0))) -- (make-vector 5 (build-vector 5 (lambda (_) 0))) On Sun, Feb 10, 2019 at 3:16 PM Gustavo Massaccesi wrote: > To understand the problem, it will be useful to understand the difference > between > > -- (make-vector 5

Re: [racket-users] Re: nested for loops and suggested alternatives

2019-02-10 Thread Gustavo Massaccesi
To understand the problem, it will be useful to understand the difference between -- (make-vector 5 (make-vector 5)) -- (build-vector 5 (lambda (_) (build-vector 5 (lambda (_) 0 -- (for/vector ([_ 5]) (for/vector ([_ 5]) 0)) Gustavo On Sun, Feb 10, 2019 at 7:24 AM wrote: > Yes, this was

Re: [racket-users] Re: nested for loops and suggested alternatives

2019-02-10 Thread Daniel Prager
Thanks for the screenshot Travis. Just for fun, here's a version in Racket that eschews assignment, vectors and for loops, in favour of recursion and lists ... #lang racket (define years 30) (define prop-female 0.5) (define egg-surv 0.6) (define fecundity '(0 0 200 400 800)) (define survival

Re: [racket-users] Re: nested for loops and suggested alternatives

2019-02-10 Thread Jens Axel Søgaard
> > Performance Warning: Indexing the elements of arrays created in untyped >> Racket is currently 25-50 times slower than doing the same in Typed Racket, >> due to the overhead of checking higher-order contracts. We are working on >> it. > > I have no idea how to improve that (the timings are old

Re: [racket-users] Re: nested for loops and suggested alternatives

2019-02-10 Thread travis . hinkelman
I played around a bit with the math/matrix library. Actually, my first idea for a Racket learning project was to rewrite the code in the R popbio package (https://cran.r-project.org/web/packages/popbio/popbio.pdf) in Racket. But I bailed on that when I saw that eigendecomposition was still on

Re: [racket-users] Re: nested for loops and suggested alternatives

2019-02-10 Thread Daniel Prager
Hi Travis Would you mind sharing your results from R (and now Racket)? I'm having a play with the Racket code, and would like to check I'm not breaking anything as I refactor it. Dan -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To

[racket-users] Re: nested for loops and suggested alternatives

2019-02-10 Thread travis . hinkelman
Yes, this was the problem. I now have results that match the output from R. I've updated the gist with your line for the correct way to create a vector of vectors. I will have to spend some more time to understand the make-vector behavior. Perhaps my thinking is too constrained by my R

Re: [racket-users] Re: nested for loops and suggested alternatives

2019-02-10 Thread Alex Harsanyi
On Sunday, February 10, 2019 at 4:47:52 PM UTC+8, Philip McGrath wrote: > > You may also want to look into the math/array > and math/matrix > libraries. > looking at the code, it seems to me that

Re: [racket-users] Re: nested for loops and suggested alternatives

2019-02-10 Thread Philip McGrath
You may also want to look into the math/array and math/matrix libraries. -Philip On Sun, Feb 10, 2019 at 3:42 AM Alex Harsanyi wrote: > This line looks suspicious: > > (define results

[racket-users] Re: nested for loops and suggested alternatives

2019-02-10 Thread Alex Harsanyi
This line looks suspicious: (define results (make-vector years (make-vector (vector-length fecundity) 0))) The "(make-vector (vector-length fecundity) 0)" expression will create a single vector, than it creates the outer vector will all elements pointing to it. It is not a matrix, but a