[plt-scheme] A data point on 'match' in intro programming

From: Prabhakar Ragde (plragde at uwaterloo.ca)
Date: Tue Jul 14 11:03:29 EDT 2009

Matthias Felleisen wrote:
> 
> Agreed, showing them pattern matching late but still in the first year 
> is the right thing.
> 
> BSL, with list abbrv:
> 
>> (require scheme/match)
>>
>> ;; [Listof Number] -> Number
>>
>> (check-expect (sum '(1 2 3)) 6)
>>
>> (define (sum x)
>>   (match x
>>     [`() 0]
>>     [(cons fst rst) (+ fst (sum rst))]))
> 
> Enjoy -- Matthias

Is this 4.2 where you can (require scheme/match)? I'm still at 4.1.3 
(waiting for 4.2.1), and I can't. If I put

#lang scheme
(provide match)

in matchmodule.ss and then (require "matchmodule.ss"), I can get your 
code to work. However, this doesn't work:

(define (sum x)
   (match x
     [`() 0]
     [`(,fst ,rst ...) (+ fst (sum rst))]))

I get:

fst: name is not defined, not a parameter, and not a primitive name

That last bit of code works fine in Module. --PR


Posted on the users mailing list.