From: Aric Zion
Subject: LISP to SCHEME
Date: 
Message-ID: <28933@uflorida.cis.ufl.EDU>
I am working on a program that will translate 
Common Lisp to Scheme, so that DEC's Scheme->C
translator can then convert the Scheme to C.
I have come up against a couple of problems,
and I would appreciate some help.

PROBLEM 1
---------

In SCHEME, (define ab-list '(a b))  

performs the side effect and also evaluates to => ab-list


In LISP, (setf ab-list '(a b))

also performs the side effect but evaluates to => (a b)


PROBLEM 2
---------

SETF is global if the argument does not exist locally
DEFINE is local even if the argument does not exist locally

for example,

In SCHEME, 
	   (define x 4)

	   (define (somefunction)
		(define x 3)
	   )

	   (somefunction)

	   x => 4 

But in LISP, 
	   (setf x 4)

	   (defun somefunction ()
		(setf x 3)
	   )

	   (somefunction)

	   x => 3


What can I do in these cases to make SCHEME emulate LISP.


Please respond to: ···@reef.cis.ufl.edu


Thanks,
Aric Zion

From: Richard A. O'Keefe
Subject: Re: LISP to SCHEME
Date: 
Message-ID: <6127@goanna.cs.rmit.oz.au>
In article <·····@uflorida.cis.ufl.EDU>, ···@cis.ufl.edu (Aric Zion) writes:
> PROBLEM 1

> In SCHEME, (define ab-list '(a b))  
> performs the side effect and also evaluates to => ab-list
> 
> In LISP, (setf ab-list '(a b))
> also performs the side effect but evaluates to => (a b)

The description of the Scheme form is incorrect.
The Scheme form
    ***creates a local binding for ab-list unless there is one already
    sets the local binding for ab-list to '(a b)
    returns an ***UNSPECIFIED*** result.
The Scheme standard makes it very clear that the result of (define ..),
and of (set! ..) (set-car! ..) (set-cdr! ..) (vector-set! ..) and
(string-set! ..) is NOT DEFINED.  Different Schemes do it differently.
(For example, Elk returns the *previous* value of a variable.)

If you want to translate Lisp's (setf ab-list '(a b)) to Scheme, use
	(begin (set! ab-list '(a b)) ab-list)

> PROBLEM 2
> ---------
> 
> SETF is global if the argument does not exist locally
> DEFINE is local even if the argument does not exist locally

> 	   (define x 4)
> 	   (define (somefunction)
> 		(define x 3)
> 	   )
> 	   (somefunction)
> 	   x => 4 

> What can I do in these cases to make SCHEME emulate LISP.

Scheme's "define" is a form for DECLARING things!  The Scheme standard
says quite explicitly that internal defines are equivalent to the use
of letrec.  If you want assignment, use Scheme's assignment form,
which is set!.  What you want is
	(define x 4)		; *DECLARE* x and initialise it to 4
	(define (somefunction)
	    (set! x 3))		; *ASSIGN* to the non-local variable x

Before trying to write a Lisp->Scheme translator, it really would be
a good idea to learn Scheme.  The difference between DEFINE and SET!
is quite basic.

-- 
Should you ever intend to dull the wits of a young man and to
incapacitate his brains for any kind of thought whatever, then
you cannot do better than give him Hegel to read.  -- Schopenhauer.
From: Barry Margolin
Subject: Re: LISP to SCHEME
Date: 
Message-ID: <1991Jun6.055331.20956@Think.COM>
In article <·····@uflorida.cis.ufl.EDU> ···@cis.ufl.edu (Aric Zion) writes:
>I am working on a program that will translate 
>Common Lisp to Scheme, so that DEC's Scheme->C
>translator can then convert the Scheme to C.
>I have come up against a couple of problems,
>and I would appreciate some help.

Both problems are due to trying to translate (setf <variable> <expression>)
into (define <variable> <expression>).  I think you would get better
results if you translated it to (set! <variable> <expression>).  DEFVAR,
DEFPARAMETER, and DEFCONSTANT can be translated to DEFINE.
-- 
Barry Margolin, Thinking Machines Corp.

······@think.com
{uunet,harvard}!think!barmar