Re: Translating parse result into instances



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
.



Relevant Pages

  • Re: Simple recursion problem. Need help.
    ... I *did* use google and other search engines to find out anything even a HINT of how i'm supposed to solve this problem. ... this isn't a typical java problem. ... this is a question about recursion. ... asking anyone here to do my homework, as Thomas seems to be implying. ...
    (comp.lang.java.programmer)
  • Re: Fibonacci series...please help!!!
    ... >>> Although conceptually recursive calculation of the Fibonacci numbers ... you must be aware that the recursion can very quickly ... >> solution was the goal of the original homework assignment. ... A DO loop is fine. ...
    (comp.lang.fortran)
  • Re: Fibonacci series...please help!!!
    ... You do NOT need recursion to solve this problem. ... means that when function Fib is used, ... solution was the goal of the original homework assignment. ... If you use a recursive function, ...
    (comp.lang.fortran)
  • Re: Fibonacci series...please help!!!
    ... I've been told I need to use a recursive subprogram to do this ... You do NOT need recursion to solve this problem. ... solution was the goal of the original homework assignment. ... Presumably your course has covered the difference between SUBROUTINEs ...
    (comp.lang.fortran)