How to do pattern matching in scheme -


has idea how make match in scheme 2 (?x lives-in ?city) (john lives-in new-york) ?i've tried using match-define didn't succeed

i guess meant pattern matching. general solution problem, think implementing unification algorithm, there's complete working solution described in sicp. alternatively, consider embedding minikanren in code, it's simple logic programming system works scheme.

now, simpler match can use racket's pattern matching abilities. example in question:

(define expression '(john lives-in new-york))  (match expression   [(list ?x 'lives-in ?city) (list ?x ?city)]   [_ #f])  => '(john new-york) 

the above match given expression against (?x lives-in ?city) pattern, returning list matched values ?x , ?city, or #f if no match found.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -