Reputation: 415
Chicken Scheme 4.8.0.5
Greetings all,
Here's a snippet of a malformed definition of a list of lists. I say malformed because the variable name lies outside the leftmost parenthesis and there is no explicit define statement ie. (define techDisplays ((AG1 fillerIgnore....nil nil))
snippet.il
techDisplays(
;( LayerName Purpose Packet Vis Sel C2C Drg Val )
;( --------- ------- ------ --- --- --- --- --- )
( AG1 fillerIgnore AG1_fillerIgnore t t nil t nil )
( AG2 drawing AG2_drawing t t nil t t )
( AG2 fillerIgnore AG2_fillerIgnore t t nil t nil )
( AG2 frame AG2_frame t t nil t t )
( AG2 frameOnly AG2_frameOnly t t nil t t )
( AG2 frameOnlyHole AG2_frameOnlyHole t t nil t t )
( y0 flight y0_flight t t t t nil )
( y1 flight y1_flight t t t t nil )
( y2 flight y2_flight t t t t nil )
( y3 flight y3_flight t t t t nil )
( y4 flight y4_flight t t t t nil )
( y5 flight y5_flight t t t t nil )
( y6 flight y6_flight t t t t nil )
( y7 flight y7_flight t t t t nil )
( y8 flight y8_flight t t t t nil )
( y9 flight y9_flight t t t t nil )
( border boundary border_boundary t nil t t nil )
( snap grid snap_grid t nil t nil nil )
) ;techDisplays
Problem: I need to get Scheme to recognise this as a valid top-level definition Further problem: Solution must be scalable as there's 100s more where this one came from that I must read in as well Constraint: I would very very much like NOT to have to write some parsing routine as it'd very likely turn out wrong what with all the parenthesis-counting , matching, and layering.
Any ideas, hints, constructive critisisms are all welcome.
TIA,
Still-learning Steve
Upvotes: 0
Views: 96
Reputation: 1372
Consider this,
; this is structured as your input with just a space after the first name
#;1> (define inp
'(techdisps (foo bar baz)
(foo1 bar1 baz1)
(foo2 bar2 baz2)))
#;2> inp
(techdisps (foo bar baz) (foo1 bar1 baz1) (foo2 bar2 baz2))
#;3> (define techdisps cdr)
;get all the displays from you input
#;4> (techdisps inp)
((foo bar baz) (foo1 bar1 baz1) (foo2 bar2 baz2))
;this should be just a tech display, let's see how it parses.
#;5> (car (techdisps inp))
(foo bar baz)
#;6> (define foo car)
#;7> (define bar cadr)
#;8> (define baz caddr)
;this will give us all the bazes
#;9> (map baz (techdisps inp))
(baz baz1 baz2)
If you think this won't scale (although 100s more won't be something that a modern scheme interpreter in a decent box will have trouble crunching) we can suggest alternatives. Hope this helps.
Cheers.
Upvotes: 0