Hello,
I'm a newby in LISP. Indeed, I'm translating some LISP code into C++. This is fairly simple for functions (there are all mathematical functions, so very simple to test the validity of my translation). However, I'm blocked for 3 macro.
Is somebody could help me to translate into C/C++ ?
Thanks beforehand
Code:
(defmacro binary-search (l lo h hi x test end)
;; TYPE (* real * real * (real->boolean)
;; TYPE ((real real)->boolean)) -> real
;; Bisection search for $x$ in [$lo$..$hi$] such that
;; $end$ holds. $test$ determines when to go left.
(let* ((left (gensym)))
`(do* ((,x false (/ (+ ,h ,l) 2))
(,left false ,test)
(,l ,lo (if ,left ,l ,x))
(,h ,hi (if ,left ,x ,h)))
(,end (/ (+ ,h ,l) 2)))))
(defmacro invert-angular (f y r)
;; TYPE (real->angle real interval) -> real
;; Use bisection to find inverse of angular function
;; $f$ at $y$ within interval $r$.
(let* ((varepsilon 1/100000)); Desired accuracy
`(binary-search l (begin ,r) u (end ,r) x
(< (mod (- (,f x) ,y) 360) (deg 180))
(< (- u l) ,varepsilon))))
(defmacro sigma (list body)
;; TYPE (list-of-pairs (list-of-reals->real))
;; TYPE -> real
;; $list$ is of the form ((i1 l1)...(in ln)).
;; Sum of $body$ for indices i1...in
;; running simultaneously thru lists l1...ln.
`(apply '+ (mapcar (function (lambda
,(mapcar 'car list)
,body))
,@(mapcar 'cadr list))))