Guest User

Untitled

a guest
Dec 15th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. // for マクロ
  2. macro @for ( it, enumerate, body )
  3. syntax ( "for", it, "in", enumerate, body )
  4. {
  5. <[
  6. {
  7. loop $it = first( $enumerate ), tail = rest( $enumerate ) {
  8.  
  9. ~$body
  10.  
  11. when null? tail {
  12. recur first( tail ), rest( tail )
  13. }
  14. }
  15. }
  16. ]>
  17. }
  18.  
  19. // for マクロを使ったコード:
  20. for n in 1..10 {
  21. println( n )
  22. }
  23.  
  24. // これは以下のように展開される(はず):
  25. {
  26. loop n = first( 1..10 ), tail = rest( 1..10 ) {
  27.  
  28. println( n )
  29.  
  30. when null? tail {
  31. recur first( tail ), rest( tail )
  32. }
  33. }
  34. }
Add Comment
Please, Sign In to add comment