I agree with the in-list explanation, but I want to remark a few details. >> I don't really understand the (in-list ...) thing. This seems to be internal >> magic to me.
`in-list` is not a function, it's a macro that looks like a function. `for` is another macro (that doesn't look like a function). But in Racket the macros are not just straightforward text substitution, they can do a lot of things. Most are simple, but some macros are very complex. For example `for` can examine some additional information stored in `in-list` and write very efficient code. I.e. magic, a lot of magic, but you can write your own magical `in-something`. The details are in https://docs.racket-lang.org/reference/for.html but it's not easy so I recommend reading it later after playing more with the simple macros. I looked at your solution with vectors. I think that vectors are not slower than lists, moreover, they should be slightly faster, but sometimes I guess wrong. The problem with your implementation is that it creates a lot of intermediate lists. For example in (apply + (map (lambda (class-label) ...) class-labels) The intermediate list must be allocated and free after use, the values are scattered in memory so it may be slower to use them. Also, the compiler can write more efficient code for the + in (+ x y) than for the + in (apply + ...). The solution of Daniel use (for/sum ...) instead of (apply + (map ...)). There are a few places that can be rewritten. My recommendation for fast code is to try to avoid allocations when possible. Gustavo -- 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.