summaryrefslogtreecommitdiffstats
path: root/tests/011/macros-2.txr
blob: 0d7cc607668a809c221746b1704bb1cf328ea0b9 (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
38
@(do
   (set *gensym-counter* 0)

   (macro-time
     (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
       (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)))))))