newLISP - at last

Started by didi, May 04, 2007, 10:35:25 PM

Previous topic - Next topic

didi

Until now i programmed in basic - pascal - visual basic - c - c++ - python , i looked at forth, haskell common-lisp , c#, f# , dylan ...... frustrated i was thinking about an own language and how  it  should be

( chromatic wrote an article ,  which has a lot of ideas i like, even if it might be an  april-fool - http://www.oreillynet.com/onlamp/blog/2006/03/the_worlds_most_maintainable_p.html">http://www.oreillynet.com/onlamp/blog/2 ... ble_p.html">http://www.oreillynet.com/onlamp/blog/2006/03/the_worlds_most_maintainable_p.html )

 

Paul Grahams Hackers&Painter book esp. his idea of the 100year-language is not bad - but he didn't realize that newLisp has already a lot of what he's dreaming of . ( ok , i can not follow his macro-hype ,  i must still think about that ... )  



After i found newLisp i realized, that i could stop searching - it's already there , my language !  I like newLISP it's absolut super , it's modern, powerful - and the  small footprint is amazing.



Because i have the idea to use newLISP in two ways for quite new applications and  for everyday-programming ,therefore i have some questions and i'm happy to join this forum .

cormullion

#1
Hi there! We like newLISP too.  Although I hear that it isn't everyone's 'cup of tea'... ;-)



I will try and help you, but I'm sure that very soon you will be asking questions to which I don't know the answers...

Jeff

#2
Didi,



Welcome.  Glad to have you.  Allow me to pipe in on the subject of macros.



The beauty of macros is that they allow you to create your own syntax for the language.  This means that if the language does not support the feature you want, you can always implement it yourself using a macro.



For example, I came to lisp from PHP.  After using the prototype JS library and seeing how useful lambda functions are (anonymous functions that can be passed as parameters to another function), I tried to find something similar in PHP.  PHP's lambda is a joke (and not even subject to garbage collection, so using it to iterate over a list/array would create a memory leak), as PHP does not consider functions to be objects.



If PHP had macros, I could have written a macro that accepted a function definition as its argument (but then, I would never have found lisp or newlisp).



In fact, I replicated Ruby's each syntax in newLisp a little while back as an exercise to help teach myself macros.  The difference between functions and macros is that macros do not evaluate their arguments as they are passed.



Normally, a function only has access to the values that result from the evaluation of its arguments.  With macros, the function must evaluate those arguments itself.  This gives it the opportunity to pass those code blocks to other functions or macros, evaluate only portions of them, alter their syntax, etc.



You could convert a statement like:



(my-macro write "hello world" 5 times)



And my-macro could convert that syntax to something like:



(dotimes (x 5)

  (println "hello world"))



...or similar.
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

didi

#3
By the way, I am a bit overwhelmed of the positive reaction to my threads.

Like newLISP itself , this community here is really amazing.



@jeff

many thanks to your detailed explanation :-)

As you know both , do you think common lisp has more powerful macro possibilities  than newLISP ?

Jeff

#4
Macros work almost identically between common lisp and newlisp.  The main difference is that since newlisp is entirely interpreted, macros are expanded (processed by the interpreter) at runtime.  In common lisp, macros have an advantage in speed over regular functions.  The only other difference is syntactic - newlisp breaks from common lisp by using define and define-macro.



However, macros' are defined by the fact that their arguments are passed unexpanded, which is their major advantage.  This is the same in all lisps (that I know of).
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

didi

#5
I heard a talk , a podcast on ITC from Matz the developer of ruby , he made a joke about  Lisp , he said  ' the answer to every problem for a lisp-programmer is  A MACRO '  .

BUT thats no blame, i think now, if the core language has not the feature you need , you can program it yourself - if the language has THIS feature of expanding ..

Wouldn't it be good to have a collection of macros ?

Jeff

#6
Yes, and I do.  Enjoy:


(define-macro (each object do iter)
  (set 'iter (trim (string iter) "|"))
  (dolist (obj (eval object))
          (eval (set (sym (eval iter)) obj))
          (catch (doargs (a)
                 (if (= a 'end) (throw nil) (eval a))))))


...and run it:


(each '(ruby is not a lisp) do |item|
  (println item)
end)
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

rickyboy

#7
Quote from: "cormullion"Hi there! We like newLISP too.  Although I hear that it isn't everyone's 'cup of tea'... ;-)


He, he, he.  :-)  --Ricky
(λx. x x) (λx. x x)

didi

#8
Now some weeks and a few hacks later i am sure ,  the first feeling i had is absolutely correct .  

newLISP is super !



But what about macros - hmm .. lately i had the first ideas for macros , the new gui-server for example  a new command  ( gs:set-color  L1 col1  L2 col2  L3 col3 )  or even better  ( gs:set-color  L1 to L 3 , col1 to col3 )  ... ok, not really something you need for living .



But ist it correct what Paul stated between  the lines :   "  the smarter the program the more macros "  ??



I can't believe that, for me today it seems like this :  " the more macros , the bader the language "



newLISP has a huge instruction repertoire , about 300 commands in it's small exe file  of  about 200kbyte  == 0.2 MB !!  batteries included ;-)  



OK - and if now and then one command is really missing , you can write it by your own with a macro !  

.. but Lutz will be faster in the most cases ! :-)  



PS : in short time there will be a gui-included version with about 1MB !

.. this is the size of 1/3 of an mp3-song !



PPS :  I'm an amateur and i have not the insight of the big gurus - and who knows i might be a bit dumb .

Live and let live ... let's hack ..

Lutz

#9
QuoteBut ist it correct what Paul stated between the lines : " the smarter the program the more macros " ??


Paul G. is talking about Common LISP. The style of programming in Common LISP is very different and it is also a compiled language while newLISP is a scripting (interpreted) language.



newLISP has macros too but they work a bit different, see point (10) here:



http://newlisp.org/index.cgi?page=Differences_to_Other_LISPs">http://newlisp.org/index.cgi?page=Diffe ... ther_LISPs">http://newlisp.org/index.cgi?page=Differences_to_Other_LISPs



to understand newLISP macros you should also get familiar with the following functions: expand, letex, doargs



Lutz

cormullion

#10
I think you only need macros when you don't want a function to evaluate its arguments immediately. I think of it like this:


(define (calc e)
  (println "the answer to " e " is " (eval e)))
 
(calc (+ 2 2))

;-> the answer to 4 is 4

(define-macro (calc e)
  (println "the answer to " e " is " (eval e)))
 
(calc (+ 2 2))

;-> the answer to (+ 2 2) is 4



The function is no good, because it only sees the '4', not the expression. The macro is better, because e was evaluated only when we wanted it evaluated, giving us a chance to see it unevaluated.

Jeff

#11
The idea behind macros is to be able to expand the syntax of the language itself when necessary.  Granted, s-expressions make this both possible and less necessary, since you can pass a lambda as a "code block" to a function.



Here is a link to an article I wrote that (hopefully) explains a bit about macros and their use:



http://artfulcode.nfshost.com/files/macros.html">http://artfulcode.nfshost.com/files/macros.html



The beauty of macros is that they allow you to create syntactic structures specific to a program, often called domain-specific languages.  For example, if you have a bunch of data stored in xml, you could convert it to a lisp list using the xml functions built into newLisp, and then name a macro after the document root element, allowing you to then "execute" that entire xml list structure as a program, as suggested in this article:



http://www.defmacro.org/ramblings/lisp.html">http://www.defmacro.org/ramblings/lisp.html
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

didi

#12
Thankyou very much for your help. I'll read these articles .



Until now i had no speed problem with newLISP , maybe with larger applications, i think an interpreter is fast enough for a lot of applications.



I wonder if there are applications i'm not able to program in newLISP , which need  Common Lisp .

HPW

#13
QuoteUntil now i had no speed problem with newLISP , maybe with larger applications, i think an interpreter is fast enough for a lot of applications.


For heavy number/data crunching the compiled languages have still an advantage. But then you can import a lib for such jobs.



See base64 encoding discussion here:



http://www.alh.net/newlisp/phpbb/viewtopic.php?t=203&postdays=0&postorder=asc&highlight=mime&start=25">http://www.alh.net/newlisp/phpbb/viewto ... e&start=25">http://www.alh.net/newlisp/phpbb/viewtopic.php?t=203&postdays=0&postorder=asc&highlight=mime&start=25
Hans-Peter

rickyboy

#14
Quote from: "HPW"For heavy number/data crunching the compiled languages have still an advantage. But then you can import a lib for such jobs.

Good point H-P!



Although it is more of a monolith, this is also the basic idea behind Emacs: the heavy-duty ops are primitives written in C, and accessible by Emacs Lisp, and all the rest is written in Emacs Lisp -- a great design idea which was way ahead of its time (at least in "software engineering" circles).
(λx. x x) (λx. x x)