In PAIP section 2.3, Norvig gives an example of a generative grammar:
;; common lisp
(defparameter *simple-grammar*
'((sentence -> (noun-phrase verb-phrase))
(noun-phrase -> (Article Noun))
(verb-phrase -> (Verb noun-phrase))
(Article -> the a)
(Noun -> man ball woman table)
(Verb -> hit took saw liked))
"A grammar for a trivial subset of English.")
What's the most idiomatic way to write something like this in
Clojure? My first attempt is as follows:
(defonce- *simple-grammar*
{:sentence [:noun-phrase :verb-phrase]
:noun-phrase [:Article :Noun]
:verb-phrase [:Verb :noun-phrase]
:Article '(the a)
:Noun '(man ball woman table)
:Verb '(hit took saw liked)}
"A grammar for a trivial subset of English.")
Assume I'm going to need some way to distinguish terminals from non-
terminals. Above I used lists vs vectors. If this were a non-toy app
where I was optimizing for performance, would it make more sense to
use vectors everywhere? If so, what would be a good succinct way to
differentiate the two rule types? Could I add meta-data to the vector
literals somehow? Or perhaps use structs instead?
Thanks,
Mike
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en