Introduction to newLISP

Started by Lutz, March 24, 2006, 05:37:19 AM

Previous topic - Next topic

Lutz

Just posted a wonderful contribution from Cormullion. The first 'Introduction to newLISP'. There is a lot to find in there, not only for beginners: http://newlisp.org/introduction-to-newlisp.pdf">http://newlisp.org/introduction-to-newlisp.pdf and linked to from http://newlisp.org/index.cgi?Documentation">http://newlisp.org/index.cgi?Documentation



Thanks Cormullion



Lutz

cormullion

#1
- and thanks for your contributions and for hosting it, Lutz.



If you have any comments or suggestions, please let me know!

HPW

#2
Cormullion,



Thanks for your nice contribution. Good reading.



Some comment from an old-autolisp-horse:


Quotecond is an oldstyle version of if.


It may be oldstyle but I find it better because it provides a lispy structure inside the code. In such short demo-source 'if' looks good because of less typing. But in huge production-code I have no problem with a few more paranthesis. You tell about good editors some page prior and here they come into use again. The editor checks for me where each cond section start and ends. Of cource no one-liners but may be more than one screen-height. With 'if' I would always need to check if there are pairs of nested lists. And an oldstyler sees at once 'if'=2 Options 'cond'= more than 2 options (consider here also hugher codeblocks).



Also the formating guidelines may tell about options discussed here:



http://www.alh.net/newlisp/phpbb/viewtopic.php?t=893&highlight=formatting">http://www.alh.net/newlisp/phpbb/viewto ... formatting">http://www.alh.net/newlisp/phpbb/viewtopic.php?t=893&highlight=formatting



1: (define (f x)
2:   (when (< (g x) 3)
3:      (h x 2)
4:   )
5:   (foobar g h)
6: )


My Ultraedit matches not only the braces but also highlight the complete area. So when matching braces are aligned in columns you can see nicely the indenting deep and where it gets back. Also copy and pasting of code-blocks become more easy without much paranthesis checking.



Just my 2 cents! ;-)
Hans-Peter

cormullion

#3
Thanks!



Point taken about cond. People trying newLISP having used other varieties of Lisp have different expectations than those who've used mainly non-Lisp languages before. It's been interesting observing the two different approaches!



I may have to do more work on formatting newLISP code. It's something that beginners like me have trouble with - experts know the language well enough to be able to format their code well, whereas the new user is trying to learn both the language and how to write it well, and I've made some mistakes with the language because I haven't formatted the code well.



As you know, I've tried to write scripts that format my newLISP code for me, with varying degrees of success. Some of the scripts work OK but lose comments, others fall over when they meet certain statements, others just get confused with strings nested in comments, or something.



I'd love it if there was a utility that formatted newLISP code for me (with a few parameters to adjust, obviously)...

pjot

#4
Very nice reading indeed! Well written, clear examples. By coincidence, last weekend I introduced a friend to newLISP, so this introduction appears at the right moment. Thanks!



Peter

Dmi

#5
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 ;-)
(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:
(if
 (< x 0)   (set 'a "impossible
 (< x 10)  (set 'a "small")
 (< x 20)  (set 'a "medium")
 (>= x 20) (set 'a "large")
 )

(set 'a
  (if
    (< x 0)   "impossible"
    (< x 10)  "small")
    (< x 20)  "medium"
              "large"))

"if" can return value and either can have "else" branch.
WBR, Dmi

cormullion

#6
Hi, Dmitry! Thanks for the comments. I like them spicy!



re 1: My original idea for the document was to introduce the language, for people that perhaps find the reference manual a bit, well - look through the first few pages and you'll see what I mean! The first example is, I think, an HTTP server... :-)



For this document I suggested that "This short document is intended to be a straightforward and simple description of the basics of the language." Perhaps I should underline the word 'basics and 'simple' a bit more. It's really aimed at beginners like me.



Your questions are good ones, but I don't know the answers to why you shouldn't use Perl or Python or lists or whatever. It's true, I'm a terrible salesman, and I'm not the person to try and 'sell' you newLISP rather than another language. For all I know, you would be better off using Ruby or Python or Visual Basic... I just felt that, if someone's interested enough to look into the language and they haven't met it before, they might appreciate a beginner-friendly introduction.



2 The example on page 5 was intended to show only that a good text editor will help you edit newLISP. The choice was entirely arbitrary - I chose the first thing in my newLISP folder that had lots of closing parentheses...   You're right, it's not very good. On the other hand, why not include less good code from time to time? :-)



I thought about putting some longer examples in, but to be honest there's loads of good and useful newLISP code floating around the documentation and the web site. And as soon as people get the hang of the basics, they'll want to start work on their own projects.



Thanks again for reading!

Dmi

#7
Ok. Now I more understand the goals. Thanks.

Yes, this will be a sufficient introduction for thoose programmers, who _need_ to understand newlisp's code.



My questions was more about the people, searching a good language for writing things... They will be interested in tricks, paradigms, methods etc.

In other hand, "newlisp in 21 minute" and another one (I can't restore it's name because of troubles to access newlisp.org now) covers this topic.



About "the answers": there are ones, but hey are in area of functional style etc...



Either You done a nice job! :-)
WBR, Dmi

cormullion

#8
Quote from: "Dmi"My questions was more about the people, searching a good language for writing things... They will be interested in tricks, paradigms, methods etc.


I hope that other members of the newLISP community can do this! Especially people who are good at marketing and selling things... :-)