I have attached code for this problem, with comments.
Code: Select all
;; sites-sm.txt
[text]
;; copy below to sites-sm.txt
1 google.com
2 facebook.com
3 yahoo.com
4 youtube.com
5 live.com
6 wikipedia.org
7 blogger.com
8 baidu.com
9 msn.com
10 yahoo.co.jp
[/text]
(set 'sites (parse (read-file "sites-sm.txt") "\n"))
;; ("1\tgoogle.com" "2\tfacebook.com" "3\tyahoo.com" "4\tyoutube.com" i
;; "5\tlive.com" "6\twikipedia.org" "7\tblogger.com" "8\tbaidu.com"
;; "9\tmsn.com" "10\tyahoo.co.jp" "")
(println "Sites has " (length sites) " entries") ; ->
;; Sites has 11 entries
(println (slice (sites 0) (+ 1 (find "\t" (sites 0))) ) )
;; google.com
(dolist (x sites)
(println (slice x (+ 1 (find "\t" x)) ) ) )
;; prints: google.com ... yahoo.co.jp
;;
;; ERR: value expected : (find "\t" x)
(exit)
This causes everything from the parse to start failing, for various reasons.
* 11 items, when there are only 10 in the list (or, should only be 10)
* The dolist fails on the "" item, because there is no "\t" character to find
Obviously, I can correct this with something like:
Code: Select all
(dolist (x sites)
(if (> (length x) 0) (push x newsites))
)
(set 'sites newsites)