SapphireDensetsu / ypsilon

Automatically exported from code.google.com/p/ypsilon
Other
0 stars 0 forks source link

'(()) and (cons '() '()) behave differently with regard to set-car! #94

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I am using 0.9.6-update3.

I am not quite sure if this is a bug but it at least is weird:

> (let ((c (cons '() '()))) (set-car! c c))

gives "#1=(#1#)" as I expect, the following seemingly equivalent expression 
raises an error:

> (let ((c '(()))) (set-car! c c) c)

error in set-car!: attempt to modify literal constant (())

irritants:
  ((()) (()))

Original issue reported on code.google.com by ken.waki...@gmail.com on 16 Apr 2009 at 8:43

GoogleCodeExporter commented 8 years ago
That is probably by design.
Unlike pairs returned via cons, the constants obtained via quotation are 
considered
to be immutable, and, to quote R6RS, "An attempt to store a new value into a 
location
referred to by an immutable object should raise an exception with condition type
&assertion".

You can read more about this in "Storage model" (section 5.10 of R6RS [1]), and 
in
"Mutable pairs" (chapter 17 of R6RS Standard Libraries [2]).

[1] http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-2.html#node_toc_node_sec_5.10
[2] http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-1.html

Original comment by vmage...@gmail.com on 17 Apr 2009 at 11:45

GoogleCodeExporter commented 8 years ago
Thank you for your messages.

I design ypsilon that conforming R6RS as vmagerya mentioned. So, attempt to 
modify
literal constant cause an exception in R6RS mode.
You can suppress such exception by using `--compatible' flag if you have 
problem with
existing scheme scripts.

$ ypsilon --compatible
Ypsilon 0.9.6-update3 Copyright (c) 2008 Y.Fujita, LittleWing Company Limited.
> (let ((p '(1 2))) (set-cdr! p 3) p)
(1 . 3)
> 

Please try. Thank you!
-- fujita

Original comment by y.fujita...@gmail.com on 20 Apr 2009 at 11:50

GoogleCodeExporter commented 8 years ago
Thanks for clearing things up!

Ken

Original comment by ken.waki...@gmail.com on 20 Apr 2009 at 1:12