ashinn / chibi-scheme

Official chibi-scheme repository
Other
1.23k stars 142 forks source link

define-function/define-variable equivalence #149

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
> (define ((f x) y) (+ x y))

What is the expected output?
f should be defined as (lambda (x) (lambda (y) (+ x y)))

What do you see instead?
ERROR on line 1: can't define a non-symbol: (define ((f x) y) (+ x y))

What version of the product are you using? On what operating system?
boran/OS X and Linux

Please provide any additional information below.
I haven't dug into the source code but I assume (define var val) and (define 
(func . args) body) are evaluated differently. If (define (func . args) body) 
expands to (define func (lambda args body)) then it follows that (define ((func 
. args1) . args2) body) should expand to (define (func . args1) (lambda args2 
body)) which expands to (define func (lambda args1 (lambda args2 body))).

I know it's not in the standard, but it is used throughout SICM if that means 
anything to you. Plus it's just a really cool way to write clean higher-order 
functions.

Original issue reported on code.google.com by caseydwyer on 24 Oct 2012 at 11:14

GoogleCodeExporter commented 9 years ago
I'll have to think about this.  I'm trying to keep the
core of Chibi as close to R7RS as possible, so people
can move their programs easily to other implementations.

It's probably better to simply write a library with a
define macro that handles this, so you can import and
use that portably.

Original comment by alexsh...@gmail.com on 24 Oct 2012 at 11:29