Hi Cormullion!
Nice reading!
Just a two imhos (a few flame, as alaways ;-)
1.
Overlooking all document, tell me (if, say, I'm newbie), why I need newLisp, but not Perl, or Python? I haven't see no one advantage.
For example:
- Perl offers more short tricks for most "real-world" examples, have a gigantic set of libraries and permit U feel like a hacker with all it's brain damaged syntax.
- Python offers the Perl's power for thoose BASIC-lovers, who can't understand Perl ;-)
- why I need lists, if I already have hashes?
- why I need all these parentheses if most examples uses "set" "for" etc, that are already everywere?
- how newLisp can speedup your day-to-day works?
What is the goal of this document?
2.
The first (and alone) complex example at page 5 is not much good:
1. there's no explanation of it's goal and construction.
2. it's much procedural, than newLisp's native functional style.
3. no bottom-up style demonstration (without it the lisp programs will be unreadable like Perl ones ;)
4. "counting words" isn't good for lisp's power demonstration - this task was constructed especially for HASH'es, and not for assoc-lists ;-)
lisp will be more powerful for lists, trees and sorting...
5. (imho) it will not work in some cases (for ex. if tags are in different lines or are out of the order.
More lispish variant may looks like follow (I haven't tested it - just for fun and for example ;-)
Code: Select all
(define (read-values fname)
(map (fn (x) ((parse x "</value>") 0))
(parse (read-file fname) "<value>")))
(define (normalize-value v)
(replace (trim v) "\n"))
(define (value-count lst) ; HASH context will fit better here, I think...
(let (i 0 old-value nil cnt-lst '())
(dolist (l (sort lst))
(if (= l old-vlaue) (inc 'i)
(begin
(push (list old-value i) cnt-list)
(setq i 1 old-value l))))
(value-count (map normalize-value (read-values "filename")))
What we can see here:
1. The task is splitted to well-understanding short functions which we can combine and reuse.
2. minimum of iterators: we make a list from a file, then transform it by "map" -as a result we have a pieces of code code in much human readable form. You have a nice chapter about map, but (imho) too late :-\
3. the word-count goal is not much elegant for newbie's imagination ;-)
...And also brief note:
Code: Select all
(if
(< x 0) (set 'a "impossible
(< x 10) (set 'a "small")
(< x 20) (set 'a "medium")
(>= x 20) (set 'a "large")
)
Code: Select all
(set 'a
(if
(< x 0) "impossible"
(< x 10) "small")
(< x 20) "medium"
"large"))
"if" can return value and either can have "else" branch.