The WITH- Macro

Pondering the philosophy behind the language
Locked
nallen05
Posts: 21
Joined: Sun Apr 19, 2009 10:12 pm

The WITH- Macro

Post by 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/onl ... html#SEC84

Thanks for your time

Nick

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

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
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post by Kazimir Majorinc »

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.

nallen05
Posts: 21
Joined: Sun Apr 19, 2009 10:12 pm

Post by nallen05 »

Kazimir Majorinc wrote: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 ;-)

Image

Take care

Nick

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post by Kazimir Majorinc »

I. 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.

Image

Locked