From: Peter Baum
Subject: converting mulisp to common lisp
Date: 
Message-ID: <3608C0CC.308F5D08@mbox.cri.uni-hannover.de>
Hi,

mulisp90 has some extensions over the common lisp
standard (especially defun, loop and cond have different
definitions). Has anybody macros, which emulate
this behaviour in common lisp?

I'm just beginning to convert a muLisp program to
common lisp, so that it can run under windows...

Peter (absolut beginner with lisp)

From: rusty craine
Subject: Re: converting mulisp to common lisp
Date: 
Message-ID: <6ubdk7$idn$1@excalibur.flash.net>
Peter Baum wrote in message <·················@mbox.cri.uni-hannover.de>...
>Hi,
>
>mulisp90 has some extensions over the common lisp
>standard (especially defun, loop and cond have different
>definitions). Has anybody macros, which emulate
>this behaviour in common lisp?
>
>I'm just beginning to convert a muLisp program to
>common lisp, so that it can run under windows...
>
>Peter (absolut beginner with lisp)

Peter some of these guys might help you.  I have posted below how muLISP
(85) treats "LOOP".    LOOP in muLISP85 (don't have 90 yet) has an implied
COND in it. I think common lisp's loop is just an iterator.  You would have
to use common lisp LOOP with a conditonal in your form.  I really don't
think it would be very difficult.  I guess the big problem is I can't think
of no way to make the changes but by hand coding them.  RE: DEFUN in
muLISP85 it looks to me to be the same as DEFUN (as I understand it) is in
common lisp (i program a lot in muLISP85 but not in common lisp).  What do
you think the extra features are in muLISP's 90 DEFUN?  I have got muLISP-90
upgrade in the mail as we speak (little late but?).    if you have not got
your problems solved by the time i get it.  i will post the differences as i
understand them, then maybe some of these bright folks can give you some
hints.  btw welcome to LISP.  I have had the other side of the problem...i
had to code most of the stuff in common lisp in muLISP, so now my muLISP
looks a lot like common lisp save the esotrics of muLISP

I posted the code examples from muLISP-85's tutorial incase of have
misunderstood how common lisp handles loops.

>>>>from Mulisp85 tutorial>>>>>>>
muLISP supports the ITERATIVE style of programming.  This style
emphasizes iterative control constructs, variable assignments, and
sequential
processing.  The function LOOP is the primary muLISP iterative control
construct.  LOOP takes any number of arguments, which are sequentially
evaluated like the tasks of a function body, except:
1.  After LOOP's last argument is evaluated, control returns back to the
first
    task in the loop.
2.  When a nonNIL conditional task is evaluated in a loop, the value of the
    conditional is returned as the value of the loop, and evaluation
proceeds
    with the task immediately following the loop, if any.
There can be any number of conditional exits anywhere within a loop.  If
there
is no such exit, the loop will continue indefinitely.
To illustrate the use of the LOOP control construct,  here is an alternative
to the recursive definition of LAST-ELEMENT given earlier:

$ (DEFUN LAST-ELEMENT (LST)
    ((NULL LST) NIL)
    (LOOP
      ((NULL (CDR LST))
        (CAR LST) )
      (SETQ LST (CDR LST)) ) )

$ (DEFUN MBR (ATM LST)
    (LOOP
      ((NULL LST) NIL)
      ((EQL ATM (CAR LST)))
      (SETQ LST (CDR LST)) ) )
From: Peter Baum
Subject: Re: converting mulisp to common lisp
Date: 
Message-ID: <360A02B4.851E190B@mbox.cri.uni-hannover.de>
Hi Rusty 

> I think common lisp's loop is just an iterator.  You would have
> to use common lisp LOOP with a conditonal in your form.  I really don't
> think it would be very difficult.  I guess the big problem is I can't think
> of no way to make the changes but by hand coding them.  

are you shure, that there is no possibility to make some tricks with
macros
and/or defuns? It would be much easier (und less errorprone) to make
":%s/loop/mu-loop/g" and somewhere "(defmacro mu-loop ...)" than to
change
every loop by hand. But as I said, am an absolut beginner...


> RE: DEFUN in
> muLISP85 it looks to me to be the same as DEFUN (as I understand it) is in
> common lisp (i program a lot in muLISP85 but not in common lisp).  What do
> you think the extra features are in muLISP's 90 DEFUN?  

Well, at least this:

> $ (DEFUN LAST-ELEMENT (LST)
>     ((NULL LST) NIL)
>     (LOOP
>       ((NULL (CDR LST))
>         (CAR LST) )
>       (SETQ LST (CDR LST)) ) )

is rejected from Allegro with message "The first element (NULL LST) 
of a function application is not a function name.

> btw welcome to LISP.

Thank you.

Peter
From: Tim Bradshaw
Subject: Re: converting mulisp to common lisp
Date: 
Message-ID: <ey33e9hwv36.fsf@todday.aiai.ed.ac.uk>
* Peter Baum wrote:

> Well, at least this:

>> $ (DEFUN LAST-ELEMENT (LST)
>> ((NULL LST) NIL)
>> (LOOP
>> ((NULL (CDR LST))
>> (CAR LST) )
>> (SETQ LST (CDR LST)) ) )

> is rejected from Allegro with message "The first element (NULL LST) 
> of a function application is not a function name.

I remember this!  mulisp has this weird thing where there are implicit
CONDs all over the place, or there may be implicit CONDs anyway.  So
you can write:

	(defun foo (x)
          ((null x) 1)
	  ((= x 3) 2)
	  (t 4))

(not sure about the (t 4)). But I forget how it decides if there is a
COND there.  You could write a DEFMUFUN which tried to intuit if there
was an implicit COND, but you'd have to be quite careful about things
like ((LAMBDA (x) x) 4), and perhaps other things that might crop up.

Mulisp was quite a cool system for its time, anyway (I ran it on an
MSDOS machine (not a PC!) from 2 floppies).  Does it still exist?

--tim
From: Peter Baum
Subject: Re: converting mulisp to common lisp
Date: 
Message-ID: <360B4FE5.C2382F79@mbox.cri.uni-hannover.de>
As the loops in the program, that I have to support,
are relative simple (no lampda-expressions, as far
as I see), I've tried to define a loop macro with
implicite cond:

(defmacro mu-loop ( &body lst)
   (loop 
      (dolist (el lst)
         (cond
            ; Symbol or simple list
            ((or (atom el) (atom (car el))) (eval el) )
            ; implicit cond
            ((atom (caar el)) (if (eval (car el))
                                  (return-from mu-loop (eval (cdr el)))
))
            ( t   (print "!!!!! Error !!!!!!!") ) 
         ) 
      ) 
   )
)

That works, if I say
> (setf m 1)
1
> (mu-loop ((> m 4)) (print (* m m)) (incf m))
1 
4 
9 
16 
NIL

but if I try 
> (defun test2 (a) (setf m 1)(mu-loop ((> m a)) (print (* m m)) (incf m)))
;; Error: Unbound variable A in #<function 0 #xE9D024>

Any hints?

Peter
From: Tim Bradshaw
Subject: Re: converting mulisp to common lisp
Date: 
Message-ID: <ey3yar8uwex.fsf@todday.aiai.ed.ac.uk>
* Peter Baum wrote:
> As the loops in the program, that I have to support,
> are relative simple (no lampda-expressions, as far
> as I see), I've tried to define a loop macro with
> implicite cond:

> (defmacro mu-loop ( &body lst)
>    (loop 
>       (dolist (el lst)
>          (cond
>             ; Symbol or simple list
>             ((or (atom el) (atom (car el))) (eval el) )
>             ; implicit cond
>             ((atom (caar el)) (if (eval (car el))
>                                   (return-from mu-loop (eval (cdr el)))
> ))
>             ( t   (print "!!!!! Error !!!!!!!") ) 
>          ) 
>       ) 
>    )
> )

You need to be much cleverer than that I think (and you don't need an
eval!).  Here's a hack implementation of DEFMUFUN.  This may be
*wrong* but I don't remember what the rules actually are.

(defun massage-mulisp-body (body)
  ;; body is something that may be an implicit cond.  But it might not
  ;; either.  It is a cond if it contains elements whose CAR is a list,
  ;;and whose CAAR is not LAMBDA.
  ;; This rule may not be the one mulisp uses
  (if (find-if #'(lambda (elt)
		   (and (consp elt)
			(consp (car elt))
			(not (eq (caar elt) 'lambda))))
	       body)
      `((cond ,@body))
      body))

(defmacro defmufun (name args &body bod)
  `(defun ,name ,args
     ,@(massage-mulisp-body bod)))

--tim