[plt-scheme] Not so hygienic macros?

From: michael rice (nowgate at yahoo.com)
Date: Mon Dec 28 22:02:55 EST 2009

Hi,

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.

Let me know if anything else is needed.

Michael

========== Bad output using MATCH and MATCH-FIRST

Welcome to DrScheme, version 4.1.2 [3m].
Language: Swindle; memory limit: 128 megabytes.
> (compare '(likes desi lucy) db)
#t
> (compare '(likes romeo juliet) db)
#t
> 

========= Output after replacing MATCH with MMATCH and MATCH-FIRST with MMATCH-FIRST
========= Here's the untraced output:

Welcome to DrScheme, version 4.1.2 [3m].
Language: Swindle; memory limit: 128 megabytes.
> (compare '(likes desi lucy) db)
#f
> (compare '(likes romeo juliet) db)
#f
> (compare '(likes jack jill) db)
#t
>

========= And some traced output:

> (compare '(likes desi lucy) db)
|(compare (likes desi lucy) ((likes minnie mickey) (likes jack jill) (likes daisy donald)))
| (mmatch (likes desi lucy) (likes minnie mickey))
| |(mmatch-first likes likes)
| |#t
| (mmatch (desi lucy) (minnie mickey))
| |(mmatch-first desi minnie)
| |#f
| #f
|(compare (likes desi lucy) ((likes jack jill) (likes daisy donald)))
| (mmatch (likes desi lucy) (likes jack jill))
| |(mmatch-first likes likes)
| |#t
| (mmatch (desi lucy) (jack jill))
| |(mmatch-first desi jack)
| |#f
| #f
|(compare (likes desi lucy) ((likes daisy donald)))
| (mmatch (likes desi lucy) (likes daisy donald))
| |(mmatch-first likes likes)
| |#t
| (mmatch (desi lucy) (daisy donald))
| |(mmatch-first desi daisy)
| |#f
| #f
|(compare (likes desi lucy) ())
|#f
#f


> (compare '(likes jack jill) db)
|(compare (likes jack jill) ((likes minnie mickey) (likes jack jill) (likes daisy donald)))
| (mmatch (likes jack jill) (likes minnie mickey))
| |(mmatch-first likes likes)
| |#t
| (mmatch (jack jill) (minnie mickey))
| |(mmatch-first jack minnie)
| |#f
| #f
|(compare (likes jack jill) ((likes jack jill) (likes daisy donald)))
| (mmatch (likes jack jill) (likes jack jill))
| |(mmatch-first likes likes)
| |#t
| (mmatch (jack jill) (jack jill))
| |(mmatch-first jack jack)
| |#t
| (mmatch (jill) (jill))
| |(mmatch-first jill jill)
| |#t
| (mmatch () ())
| #t
|#t
#t
>

========= There's also something screwy going on with the use of Edit|Find and Replace
========= that may be associated with the use of MATCH in the code. If I do Edit|Find
========= MMATCH and replace it with MATCH (or vice versa) an extra blank gets inserted
========= at the end of MATCH (or MMATCH going the other way), not a problem with MATCH
========= but MATCH-FIRST becomes MATCH -FIRST.
 

========= Tracing the code also seems to be messed up when using MATCH.

========= Here's traced output using MATCH and MATCH-FIRST:

Welcome to DrScheme, version 4.1.2 [3m].
Language: Swindle; memory limit: 128 megabytes.
> (compare '(likes desi lucy) db)
|(compare (likes desi lucy) ((likes minnie mickey) (likes jack jill) (likes daisy donald)))
| (match (likes desi lucy) (likes minnie mickey))
| |(match-first likes likes)
| |#t
| (likes minnie mickey)
|#t
#t
>   

================== This code works:

(require eopl/eopl)

(define mmatch
  (λ (pat1 pat2)
    (if (null? pat1)
        (null? pat2)
        (if (null? pat2)
            #f
            (if (mmatch-first (car pat1) (car pat2))
                (mmatch (cdr pat1) (cdr pat2))
                #f)))))

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

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


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

;(trace compare match  match-first)


--- On Mon, 12/28/09, Robby Findler <robby at eecs.northwestern.edu> wrote:

From: Robby Findler <robby at eecs.northwestern.edu>
Subject: Re: [plt-scheme] Not so hygienic macros?
To: "michael rice" <nowgate at yahoo.com>
Cc: plt-scheme at list.cs.brown.edu
Date: Monday, December 28, 2009, 10:39 AM

That doesn't sound like a lack of hygiene.

Its hard to tell what is going on without a program, but my guess is
that you wrote a program that boils down to this one:

  #lang scheme
  (set! match 5)

and the error message is telling you that you're trying to assign to
one of the imports to your library.

Note that if you had written this:

  #lang scheme
  (define match 6)
  (set! match 5)

the definition of 'match' in the body of the module would have
shadowed the import and you'd just get the local version of match
only.

hth,
Robby


On Mon, Dec 28, 2009 at 9:28 AM, michael rice <nowgate at yahoo.com> wrote:
>
> I have a function named MATCH and I seem to be mixing it up with underlying macro code. At least that's what I think is happening.
>
> The error message: set!: cannot mutate syntax identifier in: match
>
> Must I change the name of my function?
>
> Michael
>
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20091228/ee56810e/attachment.html>

Posted on the users mailing list.