Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - eliben

#1
Anything else we might add? / Returning closures
December 05, 2006, 11:31:56 AM
Hello,



I'm trying to understand how to utilize the contexts of newlisp to implement various lexical bound idioms, for instance returning closures. Take this CL code for example:



(defun make-multiplier (x) (lambda (y) (* x y))


make-multiplier is a generator of multiplier functions. It can generate as many functions as I want, each with its own internal data. For example:



(setq doubler (make-multipler 2))
(funcall doubler 13)


Produces 26.

And then:



(setq tripler (make-multipler 3))
(funcall tripler 13)


Produces 39.



How can I do it in newlisp ?



Thanks in advance
#2
newLISP newS /
April 20, 2006, 10:42:11 AM
Quote from: "rickyboy"
Quote from: "eliben"It just feels a little clunky to me that this 'catch' should wrap a loop to enable us to exit from it. Perhaps 'dolist' can be expanded by means of a macro to enable a more structured way to exit from a loop.


I know.  I felt the same way when I found out that 'return' in CL works by the fact that all functions are wrapped with a 'block' tagged with the same name as the function.


I guess this can't be too difficult to implement using macros in newlisp ?



Care to give it a shot  ?
#3
newLISP newS /
April 20, 2006, 10:10:11 AM
Quote from: "rickyboy"
Quote from: "eliben"So, the common idiom in newlisp for returning (breaking) in the middle of the loop is by using the exception ?


I like to think of 'catch/throw' as non-local exiting (i.e. I treat it in this more generic sense as a programming construct).  Non-local exits can be used (are most often used?) for exception handing.  However, non-local exits which are non-exceptional, if you will, are OK too.  Don't let the 'throw' keyword *throw* you.  (* rimshot *)  :-)




It just feels a little clunky to me that this 'catch' should wrap a loop to enable us to exit from it. Perhaps 'dolist' can be expanded by means of a macro to enable a more structured way to exit from a loop.
#4
newLISP newS /
April 20, 2006, 10:05:00 AM
Comments and discussion are beginning to pile up on both the blog and comp.lang.lisp



I strongly encourage newlisp enthusiasts to participate. In my opinion it can be a great learning experience for us all - using comparisons is a great way to learn.
#5
newLISP newS /
April 20, 2006, 09:43:48 AM
Quote from: "rickyboy"
QuoteIs there no way to achieve this without catch / throw ?

Yes, there is a way: with recursion, my good man, with recursion.  :-)


So, the common idiom in newlisp for returning (breaking) in the middle of the loop is by using the exception ?
#6
newLISP newS /
April 20, 2006, 09:32:14 AM
Quote from: "Lutz"Yes, here is another similar 'lazy' evaluating version (also written as a macro):



(define-macro (my-and)
    (catch (dolist (i (args))  
        (if (not (eval i)) (throw nil) true))))


now only tested elements up to the thrown are evaluated



Lutz


Is there no way to achieve this without catch / throw ?
#7
newLISP newS / Article about newlisp vs. other lisps
April 20, 2006, 08:25:46 AM
Hi,



I have posted an article about my impression of newlisp:

http://eli.thegreenplace.net/2006/04/20/newlisp-an-intriguing-dialect-of-lisp/">http://eli.thegreenplace.net/2006/04/20 ... t-of-lisp/">http://eli.thegreenplace.net/2006/04/20/newlisp-an-intriguing-dialect-of-lisp/



Comments from the newlisp point of view are more than welcome.

Eli
#8
newLISP newS /
April 20, 2006, 07:09:53 AM
Lutz,



Thanks for the very informative post - this is exactly what I was looking for. I want to address a few points:



1) I agree that the division between "wanting to evaluate all arguments" and "not wanting to evaluate some of the argumetns" is logical regarding usage of macros, in most cases. However, in the established Lisp flavors, macros are also often used for optimization purposes, being expanded at "compile" time. I'm placing the word "compile" in quotes intentionally, since as I mentioned, it doesn't necessarily imply a compiler, but rather some pre-processing before the code is interpreted. In this sense it is similar to the "macros" of C and C++, which are expanded by the preprocessor.



But as I understand from you, such optimization is impossible in newlisp because macros are just like functions. I understand, and it's not a big deal really. However, wouldn't it be quite simple to implement, in your opinion ? A single "expansion" pass of the interpreter on the code, detecting and expanding all the instances of macros, can make this optimization possible. What don't I see that makes it difficult ?



2) The example you provided of the 'defun' macro using (args) for hygienic identifiers looks a little cumbersome, can't you just say:


(set (args 0) (append '(lambda ) (list args)))

Or something of the sort ?



3) I completely agree with what you are saying on comparing languages. However, experiences programmers who know well several languages from different groups (imperative, functional, OO) have more ammunition to reason and compare between languages based on features. Sometimes it is biased, but it can't be dismissed as irrelevant.
#9
newLISP newS /
April 20, 2006, 04:32:44 AM
Quote from: "HPW"
QuoteAre newlisp macros evaluated at "compile time" - like CL macros (and C "macros", for that matter) ? This is important for performance, of course.


No, since there is no compiling with newLISP.

So everything in newLISP is interpreted.

In CL you can save your modified image to file and gets your own modified lisp-system.



But the newLISP interpreter is substantial smaller than every current CL implementation, it is easy embedable in other enviroments and it is quit fast for an interpeter. For performance-critical tasks you can easy call external DLL's.



As always use the right tool for the job.

;-)


I will explain what I mean by "compile time". In Common Lisp, even when it is interpreted and not compiled - there is a preliminary pass where all macros are "expanded" and only then the interpreter begins.



I hope that the performance benefits of this are obvious.
#10
newLISP newS /
April 19, 2006, 09:24:35 PM
Quote from: "Lutz"Welcome to the group Eliben!



Macros and many other things are quite different from Common LISP or SCHEME. Most code except for very simple examples from books about LISP will not run under newLISP.



To find out more about the differences from newLISP to Common LISP and SCHEME see the following page: 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



Lutz


Hello Lutz, thanks for the response.

The page you refer to says a few words about the difference of macros, and I've already read it, but without a few examples it is not too useful. Examples are the best way to demonstrate things.



I'm taking some time to look at newlisp, but my first goal is to understand if its macros are as powerful as Common Lisp's. I don't expect to copy paste CL code into a newlisp interpreter and see it run, but I want to know that the expressive power is comparable.



I will provide more concrete questions:



* Are newlisp macros evaluated at "compile time" - like CL macros (and C "macros", for that matter) ? This is important for performance, of course.



For example, here is a CL function and macro for 1+:


(defun 1+ (x) (+ 1 x))
(defmacro 1+ (x) '(+ 1 ,x))


The macro is better, since it saves a function call.



* Can macros be recursive ? For example, here is a CL macro that mimics the 'and' behavior:


(defmacro our-and (&rest args)
  (case (length args)
    (0 t)
    (1 (car args))
    (t '(if ,(car args)
            (our-and ,@(cdr args))))))


Can this be done in newlisp ? Can you please show how ?



That's it for now. Thanks :-)
#11
newLISP newS / Macros and deficiencies from CL
April 19, 2006, 02:02:27 PM
Hello,



I have a couple of questions, one of which is probably controversial. I want to note first that I'm here out of sheer curiosity as newLisp looks interesting. I come from a Perl / Ruby / C++ background with some knowledge and experience in Common Lisp. My intention is not flame, but rather a sheer interest in newlisp.



So, the questions:



1) Does newlisp have macros in the full Lisp sense ? I.e. can newlisp's macros do what CL's macros do ? Can the code from Paul Graham's "On Lisp" be implemented in newlisp ?



2) newlisp looks to be not too well received in the CL community. Granted, it's a pretty demanding community, but still it's surprising to see that newlisp is perceived practically as a joke in comp.lang.lisp

I wonder about the cause of this. It looks peculiar since newlisp seems at first sight quite complete and useful.

Has a serious attempt been ever made to understand c.l.l's criticism and answer it ?



Thanks in advance