Re: Translating parse result into instances
- From: Ken Tilton <kennytilton@xxxxxxxxxxxxx>
- Date: Fri, 31 Aug 2007 09:21:12 -0400
Is this homework?! This looks like homework!
Frank Goenninger DG1SBG wrote:
I have a - hm, what? - a "stream" of data as follows:
("model" (("id" "FRGO"))
("polygon" (("color" "+RED+") ("class" "GNC-QUAD"))
("points" (("n" "4"))
("point" NIL ("x" NIL "0") ("y" NIL "0") ("z" NIL "0"))
("point" NIL ("x" NIL "100") ("y" NIL "0") ("z" NIL "0"))
("point" NIL ("x" NIL "100") ("y" NIL "-100") ("z" NIL "0"))
("point" NIL ("x" NIL "0") ("y" NIL "-100") ("z" NIL "0"))))
("polygon" (("color" "+BLUE+") ("class" "GNC-QUAD"))
("points" (("n" "4"))
("point" NIL ("x" NIL "50") ("y" NIL "0") ("z" NIL "5"))
("point" NIL ("x" NIL "100") ("y" NIL "60") ("z" NIL "5"))
("point" NIL ("x" NIL "100") ("y" NIL "-60") ("z" NIL "50"))
("point" NIL ("x" NIL "50") ("y" NIL "-100") ("z" NIL "50"))))
("polygon" (("color" "+GREEN+") ("class" "GNC-QUAD"))
("points" (("n" "4"))
("point" NIL ("x" NIL "-50") ("y" NIL "10") ("z" NIL "30"))
("point" NIL ("x" NIL "150") ("y" NIL "60") ("z" NIL "5"))
("point" NIL ("x" NIL "150") ("y" NIL "-60") ("z" NIL "50"))
("point" NIL ("x" NIL "-50") ("y" NIL "-100") ("z" NIL "50")))))
I need to create a Model instance with ID slot being bound to
:frgo. Next I want to create Polygon instances ... You get the idea.
New one for me, really. What if this goes to some few hundreds of
polygons...
Maude has the most RAM. Otherwise... look at your data, and think "destructuring-bind". You have:
(class slots parts)
You can worry about destructuring slots if you get that far.
Parts will have the same structure, so at long last you have an excuse to use recursion! (I just wanted to goad some fool into posting an iterative solution.)
Functions are good at recursion. so...
(defun build-model (model-spec)
(destructuring-bind (class slots parts) spec
...left as an exercise...))
I hope your teacher reads this NG!
kenny
ps. You'll need APPLY and (intern slot-name :keyword) to pull off the make-instance, and the foresight to make the initargs for the slot the same as the expected input slot names. kt
--
http://www.theoryyalgebra.com/
"We are what we pretend to be." -Kurt Vonnegut
.
- References:
- Translating parse result into instances
- From: Frank Goenninger DG1SBG
- Translating parse result into instances
- Prev by Date: Re: Parsing binary Java doubles
- Next by Date: How to use Lisp in C/C++
- Previous by thread: Re: Translating parse result into instances
- Next by thread: Re: Translating parse result into instances
- Index(es):
Relevant Pages
|