Advertisement
chemoelectric

Untitled

Jan 10th, 2013
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. scheme@(guile-user)> (sc-expand '(cond (a 1) (b 2) (c 3) (d 4)))
  2. $21 = (if a (quote 1) (if b (quote 2) (if c (quote 3) (if d (quote 4) (void)))))
  3.  
  4. Okay, that’s a straightforward expansion.
  5.  
  6. scheme@(guile-user)> (sc-expand '(case a ((50) 1) ((60 70) 2) ((80 3) (90 4))))
  7. $23 = ((lambda (#{ g6254}#) (if (memv #{ g6254}# (quote (50))) (quote 1) (if (memv #{ g6254}# (quote (60 70))) (quote 2) (if (memv #{ g6254}# (quote (80 3))) ((quote 90) (quote 4)) (void))))) a)
  8.  
  9. But that isn’t very readable, is it?
  10.  
  11. Following are what Guile’s internal macro-expander produces; it outputs the Tree-IL language rather than Scheme.
  12.  
  13. scheme@(guile-user)> (macroexpand '(cond (a 1) (b 2) (c 3) (d 4)))
  14. $26 = #<tree-il (if (toplevel a) (const 1) (if (toplevel b) (const 2) (if (toplevel c) (const 3) (if (toplevel d) (const 4) (void)))))>
  15.  
  16. (macroexpand '(case a ((50) 1) ((60 70) 2) ((80 3) (90 4))))
  17. $27 = #<tree-il (let (key) (key-6338) ((toplevel a)) (if (apply (@@ (guile) memv) (lexical key key-6338) (const (50))) (const 1) (if (apply (@@ (guile) memv) (lexical key key-6338) (const (60 70))) (const 2) (if (apply (@@ (guile) memv) (lexical key key-6338) (const (80 3))) (apply (const 90) (const 4)) (void)))))>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement