Loops/With multiple ranges: Difference between revisions
→{{header|TXR}}: Make macro work harder, so programmer just specifies loop initial and final values and step.
(→{{header|TXR}}: New section.) |
(→{{header|TXR}}: Make macro work harder, so programmer just specifies loop initial and final values and step.) |
||
Line 2,719:
<syntaxhighlight lang="txrlisp">(defmacro mfor (:form f (var . range-triplets) . forms)
(with-gensyms (body toval stepval test)
^(let (,var)
(flet ((,body () ,*forms))
,*(append-each ((rt (tuples 3 range-triplets)))
(mac-param-bind f (
^((set ,var ,
(for* (
(,stepval ,step)
(,test (if (<= ,var ,toval)
(fun <=) (fun >=))))
([,test ,var ,toval])
((inc ,var ,stepval))
(,body)))))))))
(let ((prod 1) (sum 0)
(x 5) (y -5) (z -2)
(one 1) (three 3) (seven 7))
(mfor (j (- three)
(- seven)
555
22
1927
x
(expt 11 x)
(upd sum (+ (abs j)))
(if (and (< (abs prod) (ash 1 27))
Line 2,746 ⟶ 2,752:
<pre>sum = 348173; prod = -793618560</pre>
=={{header|uBasic/4tH}}==
|