Well, actually that will be nested vectors, I just used list as example.
I thought about storing arrays as one-dimentional vectors, but it makes hard to
work with literal arrays. If I use nested vectors, then I can write something
like:
(matrix-* A #[#[1 2 3] #[4 5 6]])
--
You received this
Daniel, thank you for your response!
It really helped. I've focuded too much on recursion and tried to put nested
array generation into it, without realizing that I can use external loop.
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To
Hi Vasily
Since you insist ... ;-)
The main issue is how to reduce the number of args with each step of the
recursion: looks like a job for curry!
Here's one way to do it:
(define (generate-array n f)
(for/list ([i 3])
(if (= n 1)
(f i)
(generate-array (sub1 n) ((curry f)
(If this is for a school assignment, and the following comments are
confusing, please disregard them. The comments might make a school
assignment harder than it's supposed to be.)
Are you sure you want your n-dimensional arrays to be implemented as
nested Racket lists?
What about a
On Thursday, July 13, 2017 at 9:30:44 PM UTC+2, Daniel Prager wrote:
> It's straightforward to design a recursive macro with similar intent, but
> different surface syntax:
>
> (generate-array (i) 10)
> (generate-array (i) i)
> (generate-array (i j) (+ (* 10 i) j))
>
>
> Dan
Thanks for the
It's straightforward to design a recursive macro with similar intent, but
different surface syntax:
(define-syntax generate-array
(syntax-rules ()
[(_ (i) exp) (for/list ([i 3]) exp)]
[(_ (i j...) exp) (for/list ([i 3]) (generate-array (j...) exp))]))
(generate-array (i) 10)
6 matches
Mail list logo