[plt-scheme] Pattern-matching macro chokes on conditional statement which would otherwise work.

From: Gregory Cooper (greg at cs.brown.edu)
Date: Sat Jan 19 14:28:04 EST 2008

That's odd.  When I use the Macro Stepper, clicking "Next Term", "Next
Term", "Step" gets me to the following expression, which contains an
obvious error.  If you can't figure it out, then I'd recommend reading
up a bit before trying to write programs you don't understand.  Also,
showing some basic courtesy when addressing the mailing list would
probably evoke a more helpful and sympathetic response in the future.

(cond
 ((and (not (doublequoted-symbol? (quote one))) (symbol? (quote one)))
  (let ((one (car '(1 2 3))))
    (cond
     ((and (not (doublequoted-symbol? (quote 2))) (symbol? (quote 2)))
      (let ((2 (car (cdr '(1 2 3)))))
        (match (cdr (cdr '(1 2 3))) (three) (display three))))
     ((eqv? 2 (car (cdr '(1 2 3))))
      (match (cdr (cdr '(1 2 3))) (three) (display three)))
     (else #f))))
 ((eqv? one (car '(1 2 3)))
  (match (cdr '(1 2 3)) (2 three) (display three)))
 (else #f))

On Jan 19, 2008 1:10 PM, Ran Gutin <manicmessiah at gmail.com> wrote:
> Yup. Tried that too. It expands the code (which seems right at first), and
> before it can continue to reveal the wonders beneath it, it stops and
> replaces the expanded form with 'Error'.
>
> That's very nice indeed.
>
>
>
> On Jan 19, 2008 6:05 PM, Gregory Cooper <greg at cs.brown.edu> wrote:
> > Actually, though, since the error seems to arise during the expansion
> > of your macro, you'd probably find that the Macro Stepper is more
> > appropriate than the Debug button.  (The Debug button won't show you
> > what happens until after macro expansion is finished.)
> >
> >
> >
> >
> > On Jan 19, 2008 12:43 PM, Ran Gutin <manicmessiah at gmail.com> wrote:
> > > Wait. It seems that you're right.
> > > I'm running version 371. So I'll update now.
> > >
> > > :) Thanks. I'll update you in how things go.
> > >
> > >
> > >
> > > On Jan 19, 2008 3:57 PM, Gregory Cooper < greg at cs.brown.edu> wrote:
> > > > What version of DrScheme are you running?  There was a bug in the v371
> > > > debugger that would produce error messages like that, but it should
> > > > have been fixed in v372 (and in svn as of r7169 I think).
> > > >
> > > >
> > > >
> > > >
> > > > On Jan 19, 2008 10:28 AM, Ran Gutin < manicmessiah at gmail.com> wrote:
> > > > > (define (doublequoted-symbol? sym)
> > > > >   (and (pair? sym) (eqv? (car sym) 'quote)))
> > > > >
> > > > > (define-syntax match
> > > > >   (syntax-rules ()
> > > > >     ((match vars [pfirst prest ...] body ...)
> > > > >
> > > > >      (cond
> > > > >
> > > > >         ((and (not (doublequoted-symbol? (quote pfirst)))
> > > > >              (symbol? (quote pfirst)))
> > > > >         (let ((pfirst (car vars)))
> > > > >           (match (cdr vars) [prest ...] body ...)))
> > > > >
> > > > >        ((eqv? pfirst (car vars))
> > > > >         (match (cdr vars) [prest ...] body ...))
> > > > >
> > > > >        (else #f)))
> > > > >
> > > > >     ((match vars [] body ...) (begin body ...))))
> > > > >
> > > > > (match '(1 2 3) (one 2 three)
> > > > >   (display three))
> > > > >
> > > > >
> > > > >
> > > > > Sorry for not commenting on the code, but here's a basic idea of
> what it
> > > > > SHOULD do:
> > > > > (match '(1 2 3) (1 2 3) (display 3)) should match perfectly and
> display
> > > 3 on
> > > > > the terminal (it doesn't).
> > > > > (match '(1 2 3) (one two three) (display 3)) works perfectly, and
> prints
> > > 3.
> > > > > (match '(1 2 3) ('one 'two 'three) (display 'one)) - This should
> fail to
> > > > > match the pattern altogether, as symbols which are already quoted
> are
> > > > > matched for equality, rather than used as identifiers as above. This
> > > dies
> > > > > miserably without returning #f.
> > > > > (match '(1 2 3) (one 2 three) (display three)) - This should
> immediately
> > > > > create an alias for the values 1 and 3 ('one' and 'three) and match
> the
> > > > > second values for equality. Unfortunately, this is not the case.
> > > > >
> > > > >
> > > > >  (match '(1 2 3) (one 2 three)
> > > > >    (display three))
> > > > > ... gives the following error:
> > > > > "let: bad syntax (not an identifier) in: 2"
> > > > >
> > > > > It seems to be completely ignoring the conditional.
> > > > > So I performed a test:
> > > > > (and (not (doublequoted-symbol? (quote 2)))
> > > > >              (symbol? (quote 2)))
> > > > > ... actually returns FALSE. So then why is the conditional statement
> > > > > branching off completely wrong?
> > > > >
> > > > > And then, here's the real kill. I can't debug the damn thing.
> > > > >  Doing so sends an alert window flying in my face, and a larger one
> > > behind
> > > > > it.
> > > > >
> > > > > "rest: expected argument of type <non-empty list>; given ()
> > > > >
> > > > >  === context ===
> > > > > C:\Program Files\PLT\collects\mzlib\list.ss:295:2: rest
> > > > > C:\Program Files\PLT\collects\mztake\debug-tool.ss:804:10:
> can-step-out?
> > > > >
> > > > > rest: expected argument of type <non-empty list>; given ()
> > > > >
> > > > >  === context ===
> > > > > C:\Program Files\PLT\collects\mzlib\list.ss:295:2: rest
> > > > > C:\Program Files\PLT\collects\mztake\debug-tool.ss:804:10:
> can-step-out?
> > > > >
> > > > > rest: expected argument of type <non-empty list>; given ()
> > > > >
> > > > >  === context ===
> > > > > C:\Program Files\PLT\collects\mzlib\list.ss:295:2: rest
> > > > > C:\Program Files\PLT\collects\mztake\debug-tool.ss:804:10:
> can-step-out?
> > > > >
> > > > > rest: expected argument of type <non-empty list>; given ()
> > > > >
> > > > >  === context ===
> > > > > C:\Program Files\PLT\collects\mzlib\list.ss:295:2: rest
> > > > > C:\Program Files\PLT\collects\mztake\debug-tool.ss:804:10:
> can-step-out?
> > > > >
> > > > > rest: expected argument of type <non-empty list>; given ()
> > > > >
> > > > >  === context ===
> > > > > C:\Program Files\PLT\collects\mzlib\list.ss:295:2: rest
> > > > > C:\Program Files\PLT\collects\mztake\debug-tool.ss:804:10:
> can-step-out?
> > > > >
> > > > > rest: expected argument of type <non-empty list>; given ()
> > > > >
> > > > >  === context ===
> > > > > C:\Program Files\PLT\collects\mzlib\list.ss:295:2: rest
> > > > > C:\Program Files\PLT\collects\mztake\debug-tool.ss:804:10:
> can-step-out?
> > > > >
> > > > > rest: expected argument of type <non-empty list>; given ()
> > > > >
> > > > >  === context ===
> > > > > C:\Program Files\PLT\collects\mzlib\list.ss:295:2: rest
> > > > > C:\Program Files\PLT\collects\mztake\debug-tool.ss:804:10:
> > > can-step-out?"
> > > > >
> > > > > ^ Can someone tell me what the hell is going on?
> > > > >
> > > > > _________________________________________________
> > > > >   For list-related administrative tasks:
> > > > >   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> > > > >
> > > > >
> > > >
> > >
> > >
> >
>
>


Posted on the users mailing list.