summaryrefslogtreecommitdiffstats
path: root/tests/011/macros-2.txr
blob: debc6eca97e5b3b70a93c4e2a9105f87f111c88f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@(do
   (set *gensym-counter* 0)

   (defmacro whilst ((condition : result) . body)
     (let ((cblk (gensym "cnt-blk-"))
           (bblk (gensym "brk-blk-")))
       ^(macrolet ((break (value) ^(return-from ,',bblk ,value)))
          (symacrolet ((break (return-from ,bblk))
                       (continue (return-from ,cblk)))
            (block ,bblk
              (for () (,condition ,result) ()
                (block ,cblk ,*body)))))))

   (let ((i 0))
     (whilst ((< i 100))
       (if (< (inc i) 20)
         continue)
       (if (> i 30)
         break)
       (prinl i)))

   (prinl
     (ignwarn
       (sys:expand
         '(whilst ((< i 100))
            (if (< (inc i) 20)
              continue)
            (if (> i 30)
              break)
            (prinl i)))))

   (let ((i 0))
     (whilst ((< i 5))
       (inc i)
       (labels ((whilst () 'whilst))
         (let ((break 'break))
           (prinl (list (whilst) break)))))))