Thanks, Lutz - I've made some progress now. I'm working in BBEdit/textWrangler. I've got a Unix filter with this:
Code: Select all
#!/usr/bin/newlisp
(set 't (load (main-args 2)))
(save "/tmp/newlisp.lsp" 't)
(println (load "/tmp/newlisp.lsp"))
Then I run it from within BBEdit on a file containing this:
Code: Select all
(define (scan-file f) (set 'table '()) (set 'in-file (open f "read")) (while (read-line in-file) (if (find "<value>" (current-line)) (begin (set 'the-values (parse (current-line) "<value>|</value>" 1)) (dolist (i the-values) (set 'j (trim i)) (unless (= j "") (if (set 'result (lookup j table 1)) (replace-assoc j table (list j (+ result 1))) (push (list j 1) table -1))))))))
and it produces this:
Code: Select all
(lambda (f) (set 'table '()) (set 'in-file (open f "read"))
(while (read-line in-file)
(if (find "<value>" (current-line))
(begin
(set 'the-values (parse (current-line) "<value>|</value>" 1))
(dolist (i the-values)
(set 'j (trim i))
(unless (= j "")
(if (set 'result (lookup j table 1))
(replace-assoc j table (list j (+ result 1)))
(push (list j 1) table -1))))))))
- which is pretty good, but the function name has been replaced with (lambda (f).
It's tantalizing that newLISP can format functions nicely but I can't get my functions to look as good!