| Hi, I presume the reverse order in "for" was never intended to work... arc> (for i 28 23
(prn i))
nil
arc> (for i -1 -4
(prn i))
nil
So I hacked pg's code, not the greatest fix, but it works for all scenarios: (mac for2 (v start end . body)
(w/uniq (gi gm)
(if (> start end)
`(with (,v nil ,gi ,start ,gm (- ,end 1))
(loop (set ,v ,gi) (> ,v ,gm) (set ,v (- ,v 1))
,@body))
`(with (,v nil ,gi ,start ,gm (+ ,end 1))
(loop (set ,v ,gi) (< ,v ,gm) (set ,v (+ ,v 1))
,@body)))))
arc> (for2 i 28 23
(prn i))
28
27
26
25
24
23
nil
arc> (for2 i 23 28
(prn i))
23
24
25
26
27
28
nil
arc> (for2 i -1 -4
(prn i))
-1
-2
-3
-4
nil
arc> (for2 i -4 -1
(prn i))
-4
-3
-2
-1
nil
My only problem has been that when I try to substitute the 'for2" mac for the original 'for' mac,I get an error, on loading arc, in ac.scm char 604: >: expects type <real number> as 2nd argument, given: (- end start 1 . nil); other arguments were: 0
and I start getting lost in all the ac.scm code.Anyone have any ideas on what's happening here? I can always just use for2, but it would be nice to fix it
well. Please and Thanks,
T. |