;;Degree Grammar ;;Adam Nelson ;;Chet Tobrey ;;; the functions and grammar in this file generate a cs/ee/cpe degree plans for wvu (defun mappend (fn list) "Append the results of calling fn on each element of the list. Like mancon, but uses append instead of nconc." (apply #'append (mapcar fn list))) (defparameter *degree* '((CPE -> (cemr-core cpe-core cpe-electives cpe-electives general-electives general-electives)) (CS -> (cemr-core cs-core cs-electives cs-electives cs-electives general-electives general-electives)) (EE -> (cemr-core ee-core ee-electives ee-electives general-electives general-electives)) (cs-core -> (cs-110 cs-111 cpe-271 cpe-272 cs-210 cs-220 cs-310 cs-311 cs-221 cs-230 cs-310 cs-350)) (ee-core -> (math-251 math-261 cpe-271 cpe-272 cs-110 ee-223 ee-224 ee-251 ee-252 ee-327 ee-335 ee-356 ee-355 ee-356 cep-310 cpe-311 ee-328 ee-329 basket-weaving )) (cpe-core -> (cpe-271 cpe-272 math-251 math-261 ee-221 ee-222 cs-110 ee-223 ee-224 ee-251 ee-252 cpe-310 cpe-311 cs-111 ee-327 ee-355 ee-356 math-375 cpe-312 cpe-313 cs-230 cs-350 cs-450 )) (cemr-core -> (engr-101 engr-199 engr-102 engl-101 engl-102 math-155 math-156 phys-111 phys-112 stat-215 econ-201 econ-202 Senior-Project )) (cs-electives -> cs-315 cs-101 cs-410 cs-415 cs-420 cs-430 cs-440 cs-422 cs-451 cs-472 cs-453 cs-470) (ee-electives -> ee-293 ee-336 ee-345 ee-421 ee-426 ee-436 ee-437 ee-445 ee-450 ee-455 ee-461) (cpe-electives -> cpe-435 cpe-442 cpe-450 cpe-454 cpe-462 cpe-470 cpe-471) (general-electives -> cake-baking-101 hum-101 span-101 hist-102 pols-102 mus-101 art-101)) "A grammar for cs/cpe/ee degree programs at WVU.") (defvar *grammar* *degree*) (defun one-of (set) "picks an element of a set, and makes a list of it." (list (random-elt set))) (defun random-elt(choices) "Chooses and element randomly from a list" (elt choices (random (length choices)))) (defun rule-lhs (rule) "left hand side of a rule" (first rule)) (defun rule-rhs(rule) "right hand side of a rule" (rest (rest rule))) (defun rewrites (category) "return a list of possible rewrites for this category" (rule-rhs (assoc category *grammar*))) (defun generate (phrase) "Generate a random sentence or phrase" (cond ((listp phrase) (mappend #'generate phrase)) ((rewrites phrase) (generate (random-elt(rewrites phrase)))) (t (list phrase)))) (egs :degree (eg '(generate 'CPE) :of "Generate a CPE major...") (eg '(generate 'EE) :of "Generate an EE major...") (eg '(generate 'Cs) :of "Generate a CS major..."))