Name: Anonymous 2012-01-30 20:27
I have a complex list of lists and want something to check the second element of every list of the list in the loop, any supported features like this?
(arch (parts lintel post1 post2)
(lintel must-be-supported-by post1)
(lintel must-be-supported-by post2)
(lintel a-kind-of wedge)
(post1 a-kind-of brick)
(post1 must-not-touch post2)
(post2 must-not-touch post1))
(defun lispify-relations (relation-list)
(mapcar #'(lambda (x)
(destructuring-bind (first relation . rest) x
`(,first ,relation ,@rest)))
relation-list))
(lispify-relations '((parts lintel post1 post2)
(lintel must-be-supported-by post1)
(lintel must-be-supported-by post2)
(lintel a-kind-of wedge)
(post1 a-kind-of brick)
(post1 must-not-touch post2)
(post2 must-not-touch post1)))
(defun lispify-relations (relation-list)
(mapcar #'(lambda (x)
(destructuring-bind (first relation . rest) x
`(,relation ,first ,@rest)))
relation-list))
CL-USER> (lispify-relations '((parts lintel post1 post2)
(lintel must-be-supported-by post1)
(lintel must-be-supported-by post2)
(lintel a-kind-of wedge)
(post1 a-kind-of brick)
(post1 must-not-touch post2)
(post2 must-not-touch post1)))
((LINTEL PARTS POST1 POST2) (MUST-BE-SUPPORTED-BY LINTEL POST1)
(MUST-BE-SUPPORTED-BY LINTEL POST2) (A-KIND-OF LINTEL WEDGE)
(A-KIND-OF POST1 BRICK) (MUST-NOT-TOUCH POST1 POST2)
(MUST-NOT-TOUCH POST2 POST1))
(defun type-lint(pass &optional buzzword)
(let ( (temp ()))
(con temp (car arch))
(setq arch (delete (car arch) arch))
(loop
(if (null arch) (return))
(setq temp ())
(if = (car :(car arch)) `must-be-supported-by
(setq arch (delete (car arch) arch))
(con must-be ((car (car arch)) (car temp)))
(setq arch(delete (car arch)))
)
(if = (car :(car arch)) `a-kind-of
(setq arch (delete (car arch) arch))
(con a-kind ((car (car arch)) (car temp)))
(setq arch(delete (car arch)))
)
(if = (car :(car arch)) `must-not-touch
(setq arch (delete (car arch) arch))
(con must-not ((car (car arch)) (car temp)))
(setq arch(delete (car arch)))
)
)
)
)
(defun generate-buzzword-hashtable (list)
(let ((ht (make-hash-table)))
(loop for (first relation . rest) in list
do (push (cons first rest) (gethash relation ht) ))
ht))