The WITH- Macro

Started by nallen05, April 21, 2009, 06:17:32 PM

Previous topic - Next topic

nallen05

Hello



I'm playing with newLISP lately. I think it's great. I *get* it (I think ;-)



But the one thing I can't seem to wrap my head around (coming from a CL/elisp/scheme background) is how to survive without DEFMACRO/quasiquote/&body etc..



What code pattern would a newLISP hacker use where a CL hacker would normally write a WITH- style macro using DEFMACRO?



http://www.bookshelf.jp/texi/onlisp/onlisp_12.html#SEC84">http://www.bookshelf.jp/texi/onlisp/onl ... html#SEC84">http://www.bookshelf.jp/texi/onlisp/onlisp_12.html#SEC84



Thanks for your time



Nick

cormullion

#1
Hi Nick... ! In my opinion, newLISP is a small, portable, fast, and elegant Lisp-like scripting language. But you may have other thoughts!



newLISP macros aren't the same as Lisp or Scheme macros. With no compilation in newLISP, macros are more for controlling evaluation than for generating code. I believe they're technically known as "f-exprs". But I don't really know - I very rarely use them myself.

Kazimir Majorinc

#2
I am not sure what Graham means by contexts. So, I'll not say anything about with- macros. Generally, if you want to use Newlisp macros on the same way as CL macros, instead of CL



(defmacro f (y ... ) <something>)




you write Newlisp



(define-macro (f x ... ) (eval <something>))



As Newlisp variables always use dynamic scope, this should work roughly the same. But it is really rough way for using Newlisp macros. My experience is that typical Newlisp macros have that eval, but it is pushed deeper inside <something>. It is then something like refined CL macro. If you want backquote, instead of



`(,a ,b)



you can use



(expand '(a b) 'a 'b)



letex is similar to expand, but with few additional details. Instead of &body check (args) and $args.



One important thing is - use eval, don't avoid it. Unlike in other Lisp dialects, eval in Newlisp is generally not related with performance penalties and it can access to all variables.
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

nallen05

#3
Quote from: "Kazimir Majorinc"One important thing is - use eval, don't avoid it. Unlike in other Lisp dialects, eval in Newlisp is generally not related with performance penalties and it can access to all variables.




Interesting. I look forward to learning to stop worrying and love the EVALl ;-)



http://ecx.images-amazon.com/images/I/51FXW5TZZ8L._SL500.jpg">



Take care



Nick

Kazimir Majorinc

#4
QuoteI. THE LISP LANGUAGE



The LISP language is designed primarily for symbolic data processing. It has been used for symbolic calculations in differential and integral calculus, electrical circuit theory, mathematical logic, game playing, and other fields of artificial intelligence.



LISP is a formal mathematical language. It is therefore podsible to give a concise yet complete description of it. Such is the purpose of this first section of the manual. Other sections will describe ways of using LISP to advantage and will explain extensions of the language which make it a convenient programming system. LISP differs from most programming languages in three important ways.



The first way is in the nature of the data. In the LISP language, all data are in the form of symbolic expressions usually referred to as S-expressions. S-expressions are of indefinite length and have a branching tree type of structure, so that significant subexpressions can be readily isolated. In the LISP programming system, the bulk of available memory is used for storing S-expressions in the form of list structures. This type of memory organization frees the programmer from the necessity of allocating storage for the different sections of his program.



The second important part of the LISP language is the source language itself which specifies in what way the S-expressions are to be processed. This consists of recursive functions of S-expressions. Since the notation for the writing of recursive functions of S-expressions is itself outside the S-expression notation, it will be called the meta language. These expressions will therefore be called M-expressions.



Third, LISP can interpret and execute programs written in the form of Sexpressions. Thus, like machine language, and unlike most other higher level languages, it can be used to generate programs for further execution.


John McCarthy, Lisp 1.5 Manual.



http://archive.computerhistory.org/resources/still-image/Chess_temporary/still-images/2-4a.Stanford_University.McCarthy-John.c1967.L062302006.STANFORD_UNIVERSITY.src.jpg">
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.