Compability with CommonLisp?

Started by Alexander, July 11, 2007, 12:32:16 AM

Previous topic - Next topic

Alexander

Good day,



I have a big experience in C++, but I am very novice in Lisp programming, so I am sorry in advance for silly questions :)



I've two books dedicated to Lisp, but they are oriented to CommonLisp.

As far as I can see newLISP and CommonLisp a slightly different. I realize that we can imitate (defun) via (define) and so on, but is there a kind of "adapter" so I can use code for CommonLisp on newLISP compiler with only few changes?

Is there a sort of standard (like ANSI C/C++) for LISP interpreters? I mean documented functions, its behaviors, etc? Great variety of different LISP interpreters confuse me, though I understand that so creative people as creators of  lisp interpreters could not have the same points of view :)



With respect,

Alexander

cormullion

#1
Hi Alexander!



I think it's best if you take some of the basic concepts of Lisp and transfer these to newLISP, rather than try to translate the syntax. CL is much more complicated -  newLISP's great strength for me is that it's simpler and easier to use: there are fewer obscure function names, fewer tests for equality, and so on.



Translating Common Lisp source code to something else doesn't seem like a road that would lead anywhere fast - and perhaps you'd rather get somewhere easily than spend too long travelling...



There is no magic adapter. But there's quite a lot of newLISP code floating about to help you do without one.

Jeff

#2
A couple of clarifications:



1.  Most common lisps has a compiler, albeit a byte-compiler, but newLisp does not.  It is an interpreted language, just like Python or PHP.  The interpreter is written in C.



2.  Even among common lisp implementations, there is a lot of syntactic variance.  In fact, I think that newLisp's syntax is much closer to that of Scheme than Common Lisp.



Now... if you want to emulate CL-type syntax, you can easily redefine or alias the names of functions.  For example, if you wish for a purist "rest",


(constant (global 'cdr) rest)
(println (cdr '(foo bar baz bat))) ; => '(bar baz bat)


Macros may also be used to emulate CL syntax (just as CL macros could emulate newLisp syntax):


(define-macro (defun _fn _param _body)
  (eval (expand '(define (_fn _param) _body) '_fn '_param '_body)))

(defun foo (bar)
 (println bar))

(foo "hello world") ; => "hello world"
Jeff

=====

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



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

Alexander

#3
Thanks for clarification!


QuoteThere is no magic adapter. But there's quite a lot of newLISP code floating about to help you do without one.


Well, I understand that there is no magic at all :) I mean is there a kind of adapter, in other words a newLisp file which emulates a lot of general CommonLisp functions ("generic" Lisp functions?) such as most common car, cdr, defun. May be someone has such an adapter? There are a lot of samples which did not use overcomplicated facilities of CommonLisp and seems to be portable to newLisp (and other interpreter as well).

It's a pity if there is no simple way to reuse a lots of CommonLisp code.



Nevertheless, I'll try to deal with that in terms of my learning lisp :)



And one another question.



How can I include other lisp file if the lisp program is interpreted under newLisp compiler (just to reach compatibility in an interpreting in both CommonLisp and newLISP)?

I mean something like that:



// solution in C :)
#ifdef MY_COMPILER
#include "my_compiler_adapter.h"
#endif


Thanks!

HPW

#4
Quote... such as most common car, cdr, defun. May be someone has such an adapter?

There are a lot of samples which did not use overcomplicated facilities of CommonLisp and seems to be portable to newLisp (and other interpreter as well).

It's a pity if there is no simple way to reuse a lots of CommonLisp code.


We had the same discussion in the past with Autolisp reuse.



So here a start for your adapter:

(define (car lst)
(if lst(first lst)nil))
 (constant (global 'car))

(define (caar lst)
(if lst(first(first lst))nil))
 (constant (global 'caar))

(define (cadr lst)
(if lst(first(rest lst))nil))
 (constant (global 'cadr))

(define (cadar lst)
(if lst(first(rest(first lst)))nil))
 (constant (global 'cadar))

(define (cadadr lst)
(if lst(first(rest(first(rest lst))))nil))
 (constant (global 'cadadr))

(define (caadr lst)
(if lst(first(first(rest lst)))nil))
 (constant (global 'caadr))

(define (caddr lst)
(if lst(first(rest(rest lst)))nil))
 (constant (global 'caddr))

(define (cadddr lst)
(if lst(first(rest(rest(rest lst))))nil))
 (constant (global 'cadddr))

(define (cdr lst)
(if lst(rest lst)nil))
 (constant (global 'cdr))

(define (cdar lst)
(if lst(rest(first lst))nil))
 (constant (global 'cdar))

(if (not defun) ; loading twice would fail because of constant
 (begin
 (define-macro (defun _func-name _arguments)
  (set _func-name (append
'(lambda )
(list _arguments)
(args))))
 (constant (global 'defun))
 )
)


QuoteHow can I include other lisp file if the lisp program is interpreted under newLisp compiler (just to reach compatibility in an interpreting in both CommonLisp and newLISP)?


Simply (load ..) it at the start of your lisp-code or put it into init.lsp



Of cource you have to see that CommonLisp is a different kind of animal than a Autolisp since the spec is far more bigger. Most traditional lisp's seems to be easily emulated in newLISP. For CommonLisp I would be not sure, but when you need it you can give cormanlisp a try.
Hans-Peter