sample problems: pattern matching (1)
- problem
Write a simplified version of (match pat dat) which takes
iin two args, both lists, representing the pattern & the datum.
The pattern has ?, ?variable & symbols. The datum has symbols.
It returns #f if there is no dictionary or it returns the
appropriate dictionary.
You can assume you have a procedure
(insert var val d) that returns a new dictionary obtainined by adding
the pair (var, val) to d, unless var is already there, in which case it
returns d if (var, val) is present and #f otherwise.
You can also assume that you have primitive procedures var?, anon-var?
that take a symbol and return true if the symbol is a variable, anonymous
variable
- examples
(match '(? ?a b c ?d) '(hi there b c hello)) ==> ((?a there) (?d hello))
(match '(? ?a b c ?d) '(hi there b bad hello))==> #f