[plt-scheme] match question
Could anyone help explain why the following program doesn't work? Many
thanks.
Chongkai
#lang scheme
(define (make-nil)
'())
(define nil? null?)
(define make-::
(match-lambda
((hash-table ('|1| a) ('|2| d))
(cons a d))))
(define ::? pair?)
(define (::-content p)
(make-immutable-hash-table
(list (cons '|1| (car p))
(cons '|2| (cdr p)))))
(define my-append
(match-lambda
((hash-table ('|1| (? nil?)) ('|2| l)) l)
((hash-table
('|1| (? ::? (app ::-content (hash-table ('|1| h) ('|2| t)))))
('|2| l))
(make-::
(make-immutable-hash-table
(list
(cons '|1| h)
(cons
'|2|
(my-append
(make-immutable-hash-table
(list (cons '|1| t) (cons '|2| l)))))))))))
;matchs fine
(match '(a b)
((? ::? (app ::-content (hash-table ('|1| h) ('|2| t))))
(values h t)))
;matchs fine
(my-append (make-immutable-hash-table
(list (cons '|1| '())
(cons '|2| '(1 2)))))
;match error, why?
(my-append (make-immutable-hash-table
(list (cons '|1| '(a b))
(cons '|2| '(1 2)))))