Posted by: leppie | October 4, 2007

Hmmm donuts

This is so yummy, I thought I would share it; I just love the way this works:

; tests for define-syntax
(define-syntax begin
  (syntax-rules ()
    ((_ exp ...)
     ((lambda () exp ...)))))
  
(define-syntax for
  (syntax-rules (in into)
    ((_ a in b f ...)
     (for-each (lambda (a) (begin f ...)) b)) ;nested begin
    ((_ a b f)
     (for-each (lambda (a) f) b))
    ((_ a into b f ...)
     (for-each (lambda (a) f ...) b))))
     
(for c in "hello"
  (begin
    (display (char-upcase c))))

(newline)

(for c into "hello"
  (display (char-upcase c)))

(newline)

(for c "hello"
  (display (char-upcase c)))

(newline)

; error check
(for c out-of "hello"
  (display (char-upcase c)))

(for c "hello"
  (display (char-upcase c))
  (display (char-downcase c)))
About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: