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: Anonymous 2012-01-30 23:07

>>20
I see, if I understood that right, then my function should work just fine for you (just call it like in the example given), although a more efficient version using hashtables would be nicer.


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


Example usage:

CL-USER> (generate-buzzword-hashtable '((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)))
#<HASH-TABLE :TEST EQL :COUNT 4 {243D30F9}>
CL-USER> (gethash 'a-kind-of *)
((POST1 BRICK) (LINTEL WEDGE))
T

In this case, you generate the table once, use as many times as you want.

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