Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!fas-news.harvard.edu!newspump.wustl.edu!news.starnet.net!wupost!howland.reston.ans.net!news.sprintlink.net!pipex!uknet!festival!dcs.ed.ac.uk!bojh
From: bojh@dcs.ed.ac.uk (Benjamin Hammond)
Subject: Inconsistency in R4RS ?
Message-ID: <D30nGE.A02@dcs.ed.ac.uk>
Sender: cnews@dcs.ed.ac.uk (UseNet News Admin)
Organization: Department of Computer Science, University of Edinburgh
Date: Thu, 26 Jan 1995 14:12:13 GMT
Lines: 92

I am an undergraduate at the University of Edinburgh, and my Honours
project is to implement an interpreter for Scheme which adheres strictly
to the syntax and semantics defined in the Revised 4 Report on Scheme.

I have uncovered a problem with one of the rewrite rules for derived
expression types.

Page 37 of the report defines the transformation for letrec as follows.

(letrec ((<variable1> <init1>)
	   ...
	)
  <body>
)

transforms to

(let ((<variable1> <undefined>)
	...
     )
  (let ((<temp1> <init1>)
	 ...
       )
    (set! <variable1> <temp1>)
	 ...
  )
  <body>
)

It seems to me that this may lead to a malformed expression.

In the GENERAL case, let & letrec statements have the syntax

	(let (<binding spec>*) <body>)

where <body> represents

	<definition>* <expression>* <expression>

(Note that "*" represents a Kleene star)

Now, in reference to the specific case of the rewrite rule:

The inner "let" statement is parsed as a (derived) expression.
Since this let statement is the first element in the body of the outer
let statement, and it is an expression, then according to the syntax rules
for <body>, the body of the outer let statement may not contain any <definition>
elements.
However, the subsequent elements of the body of the outer let statement is
defined by the <body> of the original letrec statement. I cannot see that there
are be any restrictions on this letrec statement not containing any
<definition> s. When the letrec statement does contain <definition> s then
the outermost let statement will have the syntax

(let (<binding spec>*) <expression> <definition>* <expression>* <expression>)
                           ^^
			ie the inner "let" statement

This syntax for the outer let statement is malformed.

The problem could be given a quick fix by redefining the rewrite transformation
as


(let ((<variable1> <undefined>)
	...
     )
  (let ((<temp1> <init1>)
         ...
       )
    <body>
  )
)

Alternatively, the problem could be fixed by disallowing <definition> s in
letrec statements.

I suppose the first solution is closer to the spirit of the language.

I hope I've explained the problem adequately !
Has anyone else come across this problem ? Is there something I haven't
realised which solved the problem. If it really is an oversight on the 
part of the authors of R4RS, I can't believe no-one else has discovered
it first.

All suggestions gratefully recieved.

Cheers,
 Ben Hammond

          4th year Artificial Intelligence/Computer Science
                     University of Edinburgh.
