sample problems: pattern matching (3)
- problem
Write a simplified version of (instantiate temp dict)
which takes in two args, a template, which is a list of
?variables & symbols and dict which is a dictionary that
better have all the ?variables mentioned in the template.
It returns the template with the variables substituted
appropriately.
- example
(instantiate '(this ?is a ?test) '((?is hi) (?test hello) (?other ignored)))
==> (this hi a hello)
- solution
(define (instantiate temp dict)(define (lookup v) (cadr (assq v dict)))(map lookup temp))