[plt-scheme] Not so hygienic macros?

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Tue Dec 29 02:21:08 EST 2009

On Mon, Dec 28, 2009 at 9:02 PM, michael rice <nowgate at yahoo.com> wrote:
> OK, here's some code (at bottom) to work with. Use of MATCH seems to cause a lot of
> problems. Code is actually Scheme translation of some Logo code from an old TLC Logo
> book (for the Mattel Aquarius no less) authored by John R. Allen.

I think you're running into what Matthew calls "hopeless top-level
problems". Eli can probably say more about what is going on with the
Swindle language that leads to these precise results.

In the meatime, I think that if you use the module language, I think
you'll find that the program behaves much more sanely. That is, get
rid of the eopl require, prefix the program with "#lang scheme", and
use the "Module" language to run the program in DrScheme. When I do
that, both versions of the program, the one you posted, and the one
below, behave identically on the example inputs you send, namely
producing #f for both of these calls:

  (compare '(likes desi lucy) db)
  (compare '(likes romeo juliet) db)


#lang scheme

(define match
  (λ (pat1 pat2)
    (if (null? pat1)
        (null? pat2)
        (if (null? pat2)
            (if (match-first (car pat1) (car pat2))
                (match (cdr pat1) (cdr pat2))

(define match-first
  (λ (pat1 pat2)
    (if (symbol? pat1)
        (if (symbol? pat2)
            (equal? pat1 pat2)
        (cond ((symbol? pat2) #f)
              ((match-first pat1 (car pat2)) (match (cdr pat1) (cdr pat2)))
              (else #f)))))

(define compare
  (λ (q db)
    (cond ((null? db) #f)
          (else (cond ((match q (car db)) #t)
                      (else (compare q (cdr db))))))))

(define db '((likes minnie mickey) (likes jack jill) (likes daisy donald)))

Posted on the users mailing list.