Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

LISP: A dynamic car

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?

Name: >>3 2012-01-30 21:31

>>9,12
If you have any actual complaints about the code, feel free to say them, but your posts are void of actual content. You're probably that kodak guy who just randomly insults people here to feel good about himself.
>>10
Sounds simple enough, here's my solution:


(defun get-arguments-of (relation relation-list) 
  (remove-if-not #'(lambda (x)
                     (destructuring-bind (first a-relation . rest) x
                       (when (eq relation a-relation)
                         (cons first rest))))
                 relation-list))


Testing:
CL-USER>(get-arguments-of 'a-kind-of '((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 A-KIND-OF WEDGE) (POST1 A-KIND-OF BRICK))



If you just wanted to switch the first and the second for the entire list to make processing easier, all you'd have to do is:

(defun lispify-relations (relation-list)
  (mapcar #'(lambda (x)
          (destructuring-bind (first relation . rest) x
        `(,first ,relation ,@rest)))
      relation-list))


Test:

(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)))


What about building a list with all the answers? I'd rather use a hashtable for that as it'd be more efficient than an alist, do let me know if you want me to write that example, it'd be trivial.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List