Created
March 18, 2012 04:12
-
-
Save mikebridge/2068786 to your computer and use it in GitHub Desktop.
Codelesson Clojure Assignment 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns codelesson.assignment-3) | |
(defn match-element | |
[pattern-el data-el] | |
{:pre [(not (coll? pattern-el)) ] | |
:post [(or (true? %) (false? %))] } | |
(or | |
(= pattern-el data-el) | |
(= '? pattern-el))) | |
(defn match-list | |
[pattern-list data-list] | |
{:post [(or (false? %) (true? %))] } | |
(if (not (coll? pattern-list)) | |
(match-element pattern-list data-list) | |
(or (and | |
(empty? pattern-list) | |
(empty? data-list)) ; both leaf-nodes are empty, halt | |
(and | |
(match-list (first pattern-list) (first data-list)) | |
(match-list (rest pattern-list) (rest data-list)))))) | |
(defn match? | |
"Determine if a string representation of a sexp matches a string representation of data, according to the description of assignment 2" | |
[pattern data] | |
{:pre [(string? pattern) (string? data)] | |
:post [(or (true? %) (false? %))] } | |
(let [pattern-coll (read-string pattern) | |
data-coll (read-string data)] | |
(match-list pattern-coll data-coll))) | |
Author
mikebridge
commented
Mar 18, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment