Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok, here is my first attempt in elisp:</p> <ol> <li>I start a buffer with elisp and paredit modes on, open double quotes and paste the text</li> <li>I bind it to a symbol using <code>let</code></li> </ol> <pre> (let ((foobar "** Diego: b QI ** bruno-gil: b QI ** Koma: jo ** um: rsrs pr0n ** FelipeAugusto: esp ** GustavoPupo: pinto, tr etc ** GP: lit gtk ** Alan: jo mil pc ** Jost: b hq jo 1997 ** Herbert: b rsrs pr0n ** Andre: maia mil pseudo ** Rodrigo: c ** caue: b rsrs 7arte pseudo ** kenny: cri gif ** daniel: gtk mu pr0n rsrs b ** tony: an 1997 esp ** Vitor: b jo mimimi ** raphael: b rpg 7arte ** Luca: b lit gnu pc prog mmu 7arte 1997 ** LZZ: an qt ** William: b an jo pc 1997 ** Epic: gtk ** Aldo: b pseudo pol mil fur ** GustavoKyon: an gtk ** CarlosIsaksen : an hq jo 7arte gtk 1997 ** Peter: pseudo pol mil est 1997 gtk lit lang ** leandro: b jo cb ** frederico: 7arte lit gtk ** rol: b an pseudo mimimi 7arte ** mathias: jo lit ** henrique: 1997 h gtk qt ** eumané: an qt ** walrus: cri de ** FilipePinheiro: lit pseudo ** Igor: pseudo b ** Erick: b jo rpg q 1997 gtk ** Gabriel: pr0n rsrs qt ** george: clo mimimi ** anão: hq jo 1997 rsrs clô b ** jeff: 7arte gtk ** davidatenas: an 7arte 1997 esp qt ** HHahaah: b ** Eduardo: b ")) foobar) </pre> <p>Now I change foobar to something fancy.</p> <ol start="3"> <li>First I remove the symbols with a regexp and split the text in strings using <code>(split-string)</code></li> <li>Then I do a mapcar to turn each line into a list of words</li> </ol> <pre> (mapcar #'(lambda (y) (split-string y " " t)) (split-string (replace-regexp-in-string "[:\*]" "" foobar) "\n" t)) </pre> <ol start="5"> <li>Then I create a hashmap and bind it to temphash (<code>(temphash (make-hash-table :test 'equal))</code>)</li> <li>And then I loop into the nested lists to add the elements to the hash-table. I think I'm not supposed to do non-functional programming with mapcar, but nobody is looking ;)</li> </ol> <pre> (mapcar #'(lambda (l) (mapcar #'(lambda (m) (puthash m (format "%s %s" (car l) (let ((tempel (gethash m temphash))) (if tempel tempel ""))) temphash)) (rest l))) (mapcar #'(lambda (y) (split-string y " " t)) (split-string (replace-regexp-in-string "[:\*]" "" foobar) "\n" t))) </pre> <ol start="7"> <li>Finally, I extract the elements from the hash table into another set of nested lists with a handy function stolen from Xah Lee's webpage, </li> <li>And finally I pretty print it to another buffer with M-x pp-eval-last-sexp</li> </ol> <p>It's a little mind-bending, specially the double mapcar, but it sorta works. Here is the full "code":</p> <pre> ;; Stolen from Xah Lee's page (defun hash-to-list (hashtable) "Return a list that represent the hashtable." (let (mylist) (maphash (lambda (kk vv) (setq mylist (cons (list kk vv) mylist))) hashtable) mylist ) ) ;; Code (let ((foobar "** Diego: b QI ** bruno-gil: b QI ** Koma: jo ** um: rsrs pr0n ** FelipeAugusto: esp ** GustavoPupo: pinto, tr etc ** GP: lit gtk ** Alan: jo mil pc ** Jost: b hq jo 1997 ** Herbert: b rsrs pr0n ** Andre: maia mil pseudo ** Rodrigo: c ** caue: b rsrs 7arte pseudo ** kenny: cri gif ** daniel: gtk mu pr0n rsrs b ** tony: an 1997 esp ** Vitor: b jo mimimi ** raphael: b rpg 7arte ** Luca: b lit gnu pc prog mmu 7arte 1997 ** LZZ: an qt ** William: b an jo pc 1997 ** Epic: gtk ** Aldo: b pseudo pol mil fur ** GustavoKyon: an gtk ** CarlosIsaksen : an hq jo 7arte gtk 1997 ** Peter: pseudo pol mil est 1997 gtk lit lang ** leandro: b jo cb ** frederico: 7arte lit gtk ** rol: b an pseudo mimimi 7arte ** mathias: jo lit ** henrique: 1997 h gtk qt ** eumané: an qt ** walrus: cri de ** FilipePinheiro: lit pseudo ** Igor: pseudo b ** Erick: b jo rpg q 1997 gtk ** Gabriel: pr0n rsrs qt ** george: clo mimimi ** anão: hq jo 1997 rsrs clô b ** jeff: 7arte gtk ** davidatenas: an 7arte 1997 esp qt ** HHahaah: b ** Eduardo: b ") (temphash (make-hash-table :test 'equal))) (mapcar #'(lambda (l) (mapcar #'(lambda (m) (puthash m (format "%s %s" (car l) (let ((tempel (gethash m temphash))) (if tempel tempel ""))) temphash)) (rest l))) (mapcar #'(lambda (y) (split-string y " " t)) (split-string (replace-regexp-in-string "[:\*]" "" foobar) "\n" t))) (hash-to-list temphash)) </pre> <p>And here is the output:</p> <pre> (("clô" "anão ") ("clo" "george ") ("q" "Erick ") ("de" "walrus ") ("h" "henrique ") ("cb" "leandro ") ("lang" "Peter ") ("est" "Peter ") ("fur" "Aldo ") ("pol" "Peter Aldo ") ("qt" "davidatenas Gabriel eumané henrique LZZ ") ("mmu" "Luca ") ("prog" "Luca ") ("gnu" "Luca ") ("rpg" "Erick raphael ") ("mimimi" "george rol Vitor ") ("an" "davidatenas eumané rol CarlosIsaksen GustavoKyon William LZZ tony ") ("mu" "daniel ") ("gif" "kenny ") ("cri" "walrus kenny ") ("7arte" "davidatenas jeff rol frederico CarlosIsaksen Luca raphael caue ") ("c" "Rodrigo ") ("pseudo" "Igor FilipePinheiro rol Peter Aldo caue Andre ") ("maia" "Andre ") ("1997" "davidatenas anão Erick henrique Peter CarlosIsaksen William Luca tony Jost ") ("hq" "anão CarlosIsaksen Jost ") ("pc" "William Luca Alan ") ("mil" "Peter Aldo Andre Alan ") ("gtk" "jeff Erick henrique frederico Peter CarlosIsaksen GustavoKyon Epic daniel GP ") ("lit" "FilipePinheiro mathias frederico Peter Luca GP ") ("etc" "GustavoPupo ") ("tr" "GustavoPupo ") ("pinto," "GustavoPupo ") ("esp" "davidatenas tony FelipeAugusto ") ("pr0n" "Gabriel daniel Herbert um ") ("rsrs" "anão Gabriel daniel caue Herbert um ") ("jo" "anão Erick mathias leandro CarlosIsaksen William Vitor Jost Alan Koma ") ("QI" "bruno-gil Diego ") ("b" "Eduardo HHahaah anão Erick Igor rol leandro Aldo William Luca raphael Vitor daniel caue Herbert Jost bruno-gil Diego ")) </pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload