Arc Forumnew | comments | leaders | submitlogin
1 point by stefano 6093 days ago | link | parent

(mac dowhile (test . body) (w/uniq (f) `(rfn ,f () ,@body (if ,test (,f)))))

Should work(haven't tested it yet).



1 point by almkglor 6093 days ago | link

Here's a better version which puts the test at the end:

  (mac dowhile body
    (with (rbody (cut body 0 -1)
           test (last))
      (w/uniq f
        `(rfn ,f ()
          ,@body
          (if ,test (,f))))))

-----

3 points by drcode 6092 days ago | link

Thanks guys- Sounds like noone else knows of a way to do this with the current libraries either. Now I know I didn't just miss this feature somehow.

-----

1 point by tokipin 6091 days ago | link

i would use something like (based on the rfn idea):

  (= a 0)
  
  ((afn ()
     (pr ++.a)
     (if (isnt a 8) (self))))

-----

3 points by drcode 6090 days ago | link

right- as I mentioned in the other comment, this is less cumbersome with "drain"

  (= a 0)
  
  (drain (do (pr ++.a)
             (isnt a 8)))

-----

3 points by almkglor 6089 days ago | link

shorter thus:

  (drain:do
    (pr ++.a)
    (isnt a 8))

-----