#!r6rs

(import (rnrs)
        (srfi :28))

(define-syntax from
  (syntax-rules (upto)
    ([from x upto y fn]
     [let ([finish (+ y 1)]
           [add1 (lambda (n) (+ n 1))])
       (let loop ([cur x])
         (if (not (= cur finish))
             (begin
               (fn cur)
               (loop (add1 cur)))))])))

(from 1 upto 3 (lambda (x) (display (format "~a~n" x))))

(define-syntax macro-code
  (syntax-rules ()
    ((_)
     (begin
       (display "Hello, world.")
       (newline)))))

(let ((display error))
  (macro-code))

(define-syntax code-macro
  (syntax-rules ()
    ((_ body)
     (let ((display error))
       body))))

(code-macro
 (begin (display "Hello, world.")
        (newline)))

(define-syntax aif
  (lambda (stx)
    (syntax-case stx ()
      ([aif test-form then-form else-form]
       [with-syntax ([it (datum->syntax (syntax aif) 'it)])
         (syntax
          (let ((it test-form))
            (if it 
                then-form
                else-form)))]))))

(display (format "~a~n" (aif (+ 10 10) it -1)))

(display (format "~a~n" (aif #f it -1)))

(define-syntax sequencing
  (syntax-rules ()
    [(_ expression) expression]
    [(_ expression expressions ...)
     ((lambda (ignored) (sequencing expressions ...)) expression)]))

(sequencing
 (display 'a)
 (display 'b)
 (display 'c))