(show&tell) The Many or the Few

Started by m i c h a e l, May 02, 2006, 11:17:36 PM

Previous topic - Next topic

m i c h a e l

Lutz recently reminded me that constant can take multiple pairs of arguments. At the newLISP prompt the other day, I wondered if new did this, as well. So, rather than do the sensible thing and refer to the manual or one of the http://www.alh.net/newlisp/phpbb/viewtopic.php?t=1068">aforementioned introductions (see 8th post down), I just tried it . . .


> (setq a:n 1 b:n 2 c:n 3)
3
> (new a 'ac)
ac
> ac:n
1
> ; so far, so good.
> (new b 'bc c 'cc)
bc
> ; wait, something's amiss.
> cc:n
nil
> ; yep. but i bet 'bc was bound to the 'b context.
> bc:n
2
> yes.


So, only one argument pair as with define. This makes perfect sense with define, but does it with new? This made me realize I needed some way to intuit, or at least find out, what a function is capable of doing. Of course, the manual clears all these matters right up. So what might be helpful is a function that returns a string of the manual's definition for that symbol (symbols?):


> (println (help 'dolist)) ~>
dolist
syntax: (dolist (sym list) body ...)

The expressions in body are evaluated for each element in list. The
variable in sym is set to each of the elements before evaluation of the
body expressions. The variable used as loop index is local and behaves
according to the rules of dynamic scoping.
example:

    (set 'x 123)
    (dolist (x '(a b c d e f g))       ; prints: abcdefg
        (print x))      => g   ; return value

    ; x is local in dolist
    ; x has still its old value outside the loop

    x       => 123  ; x has still its old value

This prints abcdefg in the console window. The value for x is
unchanged after execution of dolist because of x's local scope. The
return value of dolist is the result of last evaluated expression.

Note that removing elements from the list, i.e. using pop will cause
dolist to leave the loop after the removal of the element.


This shortens the path to the information needed to freely experiment with the language. And experimentation is a powerful way to quickly learn how to do almost anything.



I sense that newLISP may be very close. To what and how close, I do not know. These are the more abstract qualities of a language, harder to put into words. Lutz would know best what these qualities may be. He seems to have made all the right choices so far, and -- barring its hostile takeover by a borg-like entity -- newLISP will continue to be the best LISP to do everyday programming in.





m i c h a e l

cormullion

#1
Yes, it would be very nice. Some ideas at:



http://www.alh.net/newlisp/phpbb/viewtopic.php?p=5228">//http://www.alh.net/newlisp/phpbb/viewtopic.php?p=5228

m i c h a e l

#2
Quote from: "cormullion"Yes, it would be very nice. Some ideas at . . .

   

Thank you, cormullion. I ended up using both Lutz's help and your ?? macros. I like the terseness of ?? for the quickies and the more verbose (four letters is verbose?!) help for the in-depth, but less often needed, full documentation.



And I agree that a beginner can write more sophisticated code in newLISP. I'm often suprised by a function's proper (yes, I'm going to say it) functioning when I try out my first best guess. I've only had this experience one other time and that was while studying Haskell. I was following along with A Gentle Introduction to Haskell of all things (well-known for being neither gentle nor an introduction), and I had this experience of really "getting" it. Everything made perfect sense, and I was comfortable coding in it, too. I have this kind of relationship with newLISP, as well, and the great thing is I don't have to learn big, scary things like monads and arrows just to say "Hello, world!" :-)





m i c h a e l

Lutz

#3
Quote
Note that removing elements from the list, i.e. using pop will cause dolist to leave the loop after the removal of the element.


Oops, this is not true anymore and I will correct it in the documentaion. The behaviour was reverted in 8.5.1.  Now it is safe again to modify the iteration list in 'dolist' which will iterate on a copy of the original list.



Also, you can just do:



(help dolist)


The macro using the lynx browser in init.ls(.example) does not need the quote or the 'println'



Lutz