From: Fab
Subject: A set of programs to test a tiny LISP ?
Date: 
Message-ID: <0e8e28ad-acec-44dd-a02e-0ddfcfc134fc@d27g2000prf.googlegroups.com>
  Hi !

  I'm writing a very tiny LISP (again). It's a restricted interpreter
without macro.
There are some perfect simple examples in LISP I programmer's manual
to test it.
 Please do you know were it's possible to get some other basic
additional source examples ?

 Thanks,

Fabrice

From: ···@informatimago.com
Subject: Re: A set of programs to test a tiny LISP ?
Date: 
Message-ID: <5abdf515-57e9-4ad9-a710-1678731e1102@w28g2000hsf.googlegroups.com>
On Dec 5, 4:33 pm, Fab <···············@free.fr> wrote:
>   Hi !
>
>   I'm writing a very tiny LISP (again). It's a restricted interpreter
> without macro.
> There are some perfect simple examples in LISP I programmer's manual
> to test it.
>  Please do you know were it's possible to get some other basic
> additional source examples ?

Try AIM-8:
http://www.informatimago.com/develop/lisp/small-cl-pgms/aim-8/aim-8.aim-8

or the Wang algorithm (well, it's from LISP I Programmer's Manual):
http://www.informatimago.com/develop/lisp/small-cl-pgms/wang.html


If you want to try more modern code, you could use #+clisp EXT:EXPAND-
FORM or other code-walker/expander.

But really, it's so simple to define a macro system, you should do it
first.

For example, here is the most basic one (defvar *macs* '())
(defun mac-function (name)
  (cdr (assoc name *macs*)))
(defun make-mac (name mac-function)
  (let ((ass (assoc name *macs*)))
    (if ass
        (rplacd ass mac-function)
        (setq *macs* (cons (cons name mac-function) *macs*)))))

(make-mac 'defmac
          (function (lambda (name args &rest body)
            (make-mac name
                      (eval (list 'function (cons 'lambda (cons args
body)))))
            (list 'quote name))))


(defun mac-expand (form)
  (cond
    ((atom form) form)                  ; no symbol-macs ;-)
    ((mac-function (first form))        ; a macro, let's expand it.
     (mac-expand (apply (mac-function (first form)) (rest form))))
    (t
     (case (first form)
       ;; Here you need to case on the special operator and expand
accordingly.
       ;; For example:
       ((function quote)
        form)
       ((lambda)
        (cons 'lambda (cons (second form)
                            (mapcar (function mac-expand) (cddr
form)))))
       ((if)
        (list 'if (mac-expand (second form))
              (mac-expand (third form))
              (mac-expand (fourth form))))
       ((block)
        (cons 'block (cons (second form)
                           (mapcar (function mac-expand) (cddr
form)))))
       ((prog1 prog2 progn)
        (cons 'progn (mapcar (function mac-expand) (cdr form))))
       ((let let*)
        (cons (first form)
              (mapcar (lambda (binding)
                        (cond
                          ((atom binding) binding)
                          ((null (cdr binding)) binding)
                          (t (list (first binding) (mac-expand (second
binding))))))
                      (second form))))
       #| ... |#
       (otherwise                       ; function call.
        (if (and (consp (first form))
                 (eq 'lambda (first (first form))))
                                        ; ((lambda (x) (my-macro x))
y) :
            (cons (cons 'lambda (cons (second (first form))
                                      (mapcar (function mac-expand)
(rest (first form))))))
                                        ; (fun (my-macro x)) :
            (cons (first form) (mapcar (function mac-expand) (rest
form)))))))))



(defun load-with-mac (file)
  (with-open-file (src file)
    (loop
       :for form = (read src nil src)
       :until (eq form src)
       :do (eval (mac-expand form)))))


(defun repl-with-mac ()
  (terpri) (princ "> ") (finish-output)
  (loop
     :for form = (read *standard-input* nil  *standard-input*)
     :until (eq form  *standard-input*)
     :do (print (eval (mac-expand form)))
     :do (terpri) (princ "> ") (finish-output)))

(of course you'll have to translate it to your simple lisp, I wrote it
in CL, using a few CL macros).

With this, you can type (repl-with-mac) and start to write little
macros:

  (repl-with-mac)

  (defmac cond (&rest clauses)
    (if (null clauses)
        'nil
        (list 'if (first (first clauses))
              (cons 'progn (rest (first clauses)))
              (cons 'cond (rest clauses)))))
==> COND

  (mac-expand '(cond ((= a b) 'one)
                ((= 1 z) 'one 'two)
                (t       'one 'two 'three)))

==> (IF (= A B) (PROGN 'ONE) (IF (= 1 Z) (PROGN 'ONE 'TWO) (IF T
(PROGN 'ONE 'TWO 'THREE) NIL)))


Making such a simple macro system providing 90% of the needs is so
easy that it's unforgivable not to find something equivalent in the
other programming languages.

Mind you, even assembly programming languages had macro systems long
before lisp was invented!!!

--
__Pascal Bourguignon__
From: szergling
Subject: Re: A set of programs to test a tiny LISP ?
Date: 
Message-ID: <6ca8898e-f2f6-4e68-ba1d-812f9b88f10f@t1g2000pra.googlegroups.com>
On Dec 7, 2:37 am, ····@informatimago.com wrote:
> On Dec 5, 4:33 pm, Fab <···············@free.fr> wrote:

[[ ... ]]

>
> --
> __Pascal Bourguignon__

Offtopic: Woo oo ooh! Welcome back to c.l.l, Pascal.
I was beginning to wonder where you've been!
From: Pascal J. Bourguignon
Subject: Re: A set of programs to test a tiny LISP ?
Date: 
Message-ID: <7codd23l17.fsf@simias.anevia.com>
szergling <···············@gmail.com> writes:

> On Dec 7, 2:37 am, ····@informatimago.com wrote:
>> On Dec 5, 4:33 pm, Fab <···············@free.fr> wrote:
>
> [[ ... ]]
>
>>
>> --
>> __Pascal Bourguignon__
>
> Offtopic: Woo oo ooh! Welcome back to c.l.l, Pascal.
> I was beginning to wonder where you've been!

I've been without Internet connexion at home since a few months :-(
I hope to get a new one soon.

In the meantime, I've read L.i.S.P. ;-)

-- 
__Pascal Bourguignon__
From: Rob Warnock
Subject: Re: A set of programs to test a tiny LISP ?
Date: 
Message-ID: <H-KdnQYhIZN0JcbanZ2dnUVZ_qzinZ2d@speakeasy.net>
Pascal J. Bourguignon <···@informatimago.com> wrote:
+---------------
| In the meantime, I've read L.i.S.P. ;-)
+---------------

Wonderful!! Even for CL-ers, a valuable read!  IMHO.


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Fab
Subject: Re: A set of programs to test a tiny LISP ?
Date: 
Message-ID: <1d1bb556-e4b5-4024-be49-24f4d954b3f4@y43g2000hsy.googlegroups.com>
  Thanks a lot Mr Bourguignon for your valuable help.

The original Lisp : that's a nice example. Can compare it to my
program.
Moreover there are "differentiation" and "Turing machine" examples
that fit the kind of oldies I was looking for.

 About macros, will see.

Apologize for this very late answer.

Fabrice Marchant