- Making little sub-languages for specialized processing e.g.
(with-vectors (v1 v2 v3) (v1 <- (+ v2 v3)))
for summing up the vectors v2 and v3 and storing it in v1.
Nice!
I also liked the challenge in example #1 of allowing multiple bodies in the bindings.
Here's a challenge for #2 -- would this language be any more usable by eliminating the need to declare the vectors, i.e. how about this...
(with-vectors (v1 <- (+ v2 v3)))
-Patrick
Afficher les réponses par date
Here's a challenge for #2 -- would this language be any more usable by eliminating the need to declare the vectors, i.e. how about this...
(with-vectors (v1 <- (+ v2 v3)))
-Patrick
Patrick,
That would be nice if you only had symbols which refer to vectors in your expressions, but suppose you want to encode Newton's force law for gravity:
(with-bodies (b1 b2) (let ((r (norm-with-vectors (q1 q2) (- q1 q2)))) (with-vectors (f q1 q2) (f <- (/ (* m1 m2 (- q2 q1)) (cube r))))))
There, m1, m2 and r are scalar variables, so you wouldn't be able to know at compile time (without introducing static types into the language anyway) that you wanted to "vectorize" q1 and q2, but not m1 m2 and r. Unfortunately, this is a bit easier to use (not to implement, of course) in C++ with template meta-programming, where you *can* tell at compile time which symbols refer to vectors. (In fact, this whole approach was "inspired" (in a very loose way) by C++ libraries like Blitz++.)
Will