procker.scm 920 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. (import
  2. (scheme base)
  3. (scheme read)
  4. (scheme write))
  5. (define-syntax function
  6. (syntax-rules ()
  7. ((_ (proc args ...) body ...)
  8. (define (proc args ...) body ...))))
  9. (define-syntax var
  10. (syntax-rules ()
  11. ((_ (sym val))
  12. (define sym val))
  13. ((_ sym)
  14. (define sym #f))
  15. ((_ first rest ...)
  16. (begin
  17. (_ first)
  18. (_ rest ...)))))
  19. (define-syntax while
  20. (syntax-rules ()
  21. ((_ pred body ...)
  22. (let loop ()
  23. (when pred
  24. (begin body ...)
  25. (loop))))))
  26. (define-syntax for
  27. (syntax-rules ()
  28. ((_ (init pred inc) body ...)
  29. (begin
  30. init
  31. (let loop ()
  32. (when pred
  33. (begin body ...)
  34. inc
  35. (loop)))))))
  36. (define-syntax =!
  37. (syntax-rules ()
  38. ((_ a b)
  39. (set! a b))))
  40. (define-syntax ++
  41. (syntax-rules ()
  42. ((_ i)
  43. (set! i (+ i 1)))))
  44. (define-syntax *=
  45. (syntax-rules ()
  46. ((_ a b)
  47. (set! a (* a b)))))