[gambit-list] Newbie: define-macro question
Will Farr
wmfarr at gmail.com
Thu Aug 18 17:07:44 EDT 2005
> 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
More information about the Gambit-list
mailing list