Re: Fixed string corruption bugs (was Guile: What's wrong with this?)

2012-01-07 Thread Mark H Weaver
From a8da72937ff4d04e8d39531773cc05e676b2be1c Mon Sep 17 00:00:00 2001 From: Mark H Weaver m...@netris.org Date: Wed, 4 Jan 2012 17:59:27 -0500 Subject: [PATCH] Fix bugs related to mutation-sharing substrings * libguile/strings.c (scm_i_is_narrow_string, scm_i_try_narrow_string,

Re: Guile: What's wrong with this?

2012-01-07 Thread Mark H Weaver
Bruce Korb bk...@gnu.org writes: Fail early and fail hard. Yes. But after all these discussions, I now doubt I have too many places where I am expecting to change a static value. That's good news! :) Most of the strings that I wind up altering are created with a scm_from_locale_string() C

Re: mutable interfaces - was: Guile: What's wrong with this?

2012-01-07 Thread Bruce Korb
On 01/07/12 08:13, Mark H Weaver wrote: Most of the strings that I wind up altering are created with a scm_from_locale_string() C function call. BTW, beware that scm_from_locale_string() is only appropriate for strings that came from the user (e.g. command-line arguments, reading from a port,

Re: mutable interfaces - was: Guile: What's wrong with this?

2012-01-07 Thread David Kastrup
Bruce Korb bk...@gnu.org writes: On 01/07/12 08:13, Mark H Weaver wrote: Most of the strings that I wind up altering are created with a scm_from_locale_string() C function call. BTW, beware that scm_from_locale_string() is only appropriate for strings that came from the user (e.g.

Re: mutable interfaces - was: Guile: What's wrong with this?

2012-01-07 Thread Mark H Weaver
Bruce Korb bk...@gnu.org writes: On 01/07/12 08:13, Mark H Weaver wrote: Most of the strings that I wind up altering are created with a scm_from_locale_string() C function call. BTW, beware that scm_from_locale_string() is only appropriate for strings that came from the user (e.g.

Re: mutable interfaces - was: Guile: What's wrong with this?

2012-01-07 Thread Mark H Weaver
Replying to myself... Again, I stress that this has nothing to do with Guile. All software, if it wishes to be properly internationalized, needs to think about where a string came from. In general, your program's source code (and thus the C string literals it contains) will have a different

Re: Guile: What's wrong with this?

2012-01-07 Thread Ian Price
Mark H Weaver m...@netris.org writes: As I understand it, in the Scheme standards (at least before R6RS's immutable pairs) the rationale behind marking literal constants as immutable is solely to avoid needlessly making copies of those literals, while flagging accidental attempts to modify

Re: Guile: What's wrong with this?

2012-01-06 Thread Mike Gran
From: Mark H Weaver m...@netris.org   It is curious that action of 'copy' really means the action of 'create a copy with different properties'.   Shouldn't (string-copy a) create another immutable string? Why would you want to copy an immutable string? Likewise, shouldn't (substring

Re: Guile: What's wrong with this?

2012-01-06 Thread David Kastrup
Mike Gran spk...@yahoo.com writes: There is an obvious syntax to construct a string immutable object: namely to have it appear as a literal in the source code. There thus isn't a need for a constructor function. Huh? There are _lots_ of strings which are better computed than spelled out.

Re: Guile: What's wrong with this?

2012-01-06 Thread Mark H Weaver
Mike Gran spk...@yahoo.com writes: The word 'string' in Scheme is overloaded to mean both string immutables and string mutables.   Since a string immutable can't be modified to be a mutable, they really are different object types.  String mutables appear to still exist in the latest draft of 

Re: Guile: What's wrong with this?

2012-01-06 Thread Bruce Korb
On 01/06/12 10:13, Mark H Weaver wrote: Imagine that you were evaluating Scheme by hand on paper. You have your program written on one page, and you have another scratch page used for the data structures that your program creates during evaluation. Suppose your program contains a very large

Re: Guile: What's wrong with this?

2012-01-06 Thread David Kastrup
Bruce Korb bk...@gnu.org writes: On 01/06/12 10:13, Mark H Weaver wrote: Imagine that you were evaluating Scheme by hand on paper. You have your program written on one page, and you have another scratch page used for the data structures that your program creates during evaluation. Suppose

Re: Guile: What's wrong with this?

2012-01-05 Thread Mark H Weaver
Bruce Korb bk...@gnu.org writes: So because it might be the case that one reference might want to see changes made via another reference then the whole concept is trashed? all or nothing? Anyway, such a concept should be kept very simple: functions that modify their argument make copies of

Re: non-reproduction of initial issue -- was: Guile: What's wrong with this?

2012-01-05 Thread Mark H Weaver
Bruce Korb bk...@gnu.org writes: On 01/04/12 16:01, Ludovic Courtès wrote: BTW, were you able to find a stripped-down example that reproduces the ‘string-upcase’ problem? Here's the stripped down example, but it does not reproduce the problem. :( I didn't copy into it my variation on

Re: Guile: What's wrong with this?

2012-01-05 Thread David Kastrup
Bruce Korb bk...@gnu.org writes: On 01/04/12 15:59, Mark H Weaver wrote: Implementing copy-on-write transparently without the user explicitly making a copy (that is postponed) is _impossible_. The problem is that although we could make a new copy of the string, we have no way to know which

Re: Guile: What's wrong with this?

2012-01-05 Thread Mark H Weaver
Bruce Korb bk...@gnu.org writes: Anyway, such a concept should be kept very simple: functions that modify their argument make copies of any input argument that is read only. Any other SCM's lying about that refer to the unmodified object continue referring to that same unmodified object.

Re: Guile: What's wrong with this?

2012-01-05 Thread Mike Gran
`define' merely makes a new reference to an existing object.  If you want a copy, you must explicitly ask for one (though this could be hidden by custom syntax).  It would not be desirable for the language to make copies automatically as part of the core `define' syntax.  For one thing,

Re: Guile: What's wrong with this?

2012-01-05 Thread Mark H Weaver
Mike Gran spk...@yahoo.com writes: It is curious that action of 'copy' really means the action of 'create a copy with different properties'.   Shouldn't (string-copy a) create another immutable string? Why would you want to copy an immutable string? Likewise, shouldn't (substring abc 1)

Re: Guile: What's wrong with this?

2012-01-05 Thread Noah Lavine
Hello all, I must admit that I do not know much about why R5RS says that literals are constant, but I think there is a misunderstanding. Bruce does not want `define' to always copy its result. I think what he wants is for literals embedded in source code to be mutable. This would, of course,

Re: Guile: What's wrong with this?

2012-01-04 Thread David Kastrup
Mike Gran spk...@yahoo.com writes:   In many systems it is desirable for constants (i.e. the values of literal   expressions) to reside in read-only-memory.  To express this, it is   convenient to imagine that every object that denotes locations is   associated with a flag telling whether

Re: Guile: What's wrong with this?

2012-01-04 Thread Mark H Weaver
Bruce Korb bruce.k...@gmail.com writes: 2. it is completely, utterly wrong to mutilate the Guile library into such a contortion that it interprets this: (define y hello) to be a request to create an immutable string anyway. It very, very plainly says, make 'y' and

Re: Guile: What's wrong with this?

2012-01-04 Thread Mike Gran
From: Mark H Weaver m...@netris.org No, `define' does not copy an object, it merely makes a new reference to an existing object.  This is also true in C for that matter, so this is behavior is quite mainstream.  For example, the following program dies with SIGSEGV on most modern systems,

Re: Guile: What's wrong with this?

2012-01-04 Thread David Kastrup
Mike Gran spk...@yahoo.com writes: If you follow that logic, then Guile is left without any shorthand to create and initialize a mutable string other than   (define y (substring hello 0)) or (define y (string-copy hello)) Sure. Guile does not have shorthands for _mutable_ literals for

Re: Guile: What's wrong with this?

2012-01-04 Thread Andy Wingo
On Wed 04 Jan 2012 12:16, Bruce Korb bk...@gnu.org writes: We could add a compiler option to turn string literals into (string-copy FOO). Perhaps that's the thing to do. No, because your clients have no control over how Guile gets built. We _do_ have control over startup code, however: I

Re: Guile: What's wrong with this?

2012-01-04 Thread Bruce Korb
On 01/04/12 08:47, Andy Wingo wrote: I was going to propose a workaround with an option to change vm-i-loader.c:43 and vm-i-loader.c:115 to use a scm_i_mutable_string_literals_p instead of 1, but that really seems like the path to perdition: previously compiled modules would start creating

Re: Guile: What's wrong with this?

2012-01-04 Thread David Kastrup
Bruce Korb bk...@gnu.org writes: On 01/04/12 04:19, Ian Price wrote: ... As for mutable strings, I consider them a mistake to begin with,... Let's step back and consider the whole point of Guile in the first place. My understanding is that one primary purpose is to be a facilitation

Re: Guile: What's wrong with this?

2012-01-04 Thread David Kastrup
Bruce Korb bruce.k...@gmail.com writes: On 01/04/12 08:47, Andy Wingo wrote: I was going to propose a workaround with an option to change vm-i-loader.c:43 and vm-i-loader.c:115 to use a scm_i_mutable_string_literals_p instead of 1, but that really seems like the path to perdition: previously

Re: Guile: What's wrong with this?

2012-01-04 Thread David Kastrup
Andy Wingo wi...@pobox.com writes: On Wed 04 Jan 2012 12:14, David Kastrup d...@gnu.org writes: Andy Wingo wi...@pobox.com writes: We could add a compiler option to turn string literals into (string-copy FOO). Perhaps that's the thing to do. What for? It would mean that a literal would

Re: Guile: What's wrong with this?

2012-01-04 Thread Mark H Weaver
Andy Wingo wi...@pobox.com writes: David Kastrup d...@gnu.org writes: What for? It would mean that a literal would not be eq? to itself, a nightmare for memoization purposes. I agree that it should not be the default behavior, but I don't see the harm in allowing users to compile their own

Re: Guile: What's wrong with this?

2012-01-04 Thread Bruce Korb
On 01/04/12 11:43, Andy Wingo wrote: The correct behavior is the status quo. We are considering adding a hack to produce different behavior for compatibility purposes. We don't have to worry about correctness in that case, only compatibility. IMO anyway :) It would be a nice added benefit

Re: Guile: What's wrong with this?

2012-01-04 Thread David Kastrup
Bruce Korb bruce.k...@gmail.com writes: On 01/04/12 11:43, Andy Wingo wrote: The correct behavior is the status quo. We are considering adding a hack to produce different behavior for compatibility purposes. We don't have to worry about correctness in that case, only compatibility. IMO

Re: Guile: What's wrong with this?

2012-01-04 Thread David Kastrup
Bruce Korb bruce.k...@gmail.com writes: Who knows where I learned the idiom. I learned the minimal amount of Guile needed for my purposes a dozen years ago. My actual problem stems from this: Backtrace: In ice-9/boot-9.scm: 170: 3 [catch #t #catch-closure 8b75a0 ...] In unknown file:

Re: Guile: What's wrong with this?

2012-01-04 Thread Ian Price
Bruce Korb bk...@gnu.org writes: On 01/04/12 04:19, Ian Price wrote: ... As for mutable strings, I consider them a mistake to begin with,... Let's step back and consider the whole point of Guile in the first place. This was not intended as an answer to this question, nor to be

Re: Guile: What's wrong with this?

2012-01-04 Thread Mark H Weaver
Bruce Korb bk...@gnu.org writes: You have to go to some extra trouble to be certain that a string value that you have assigned to an SCM is not read only. If you're going to mutate a string, you'd better be safe and make a copy before mutating it, unless you know very clearly where it came

Re: Guile: What's wrong with this?

2012-01-04 Thread David Kastrup
Bruce Korb bk...@gnu.org writes: On 01/04/12 13:52, Ian Price wrote: So my main question is: Which is the higher priority, language purity or ease of use? That is a loaded question, as it presupposes ease of use is always the same thing as impurity e.g. ... Absolutely not. Making

Re: Guile: What's wrong with this?

2012-01-03 Thread Ludovic Courtès
Hi Bruce, And happy new year! Bruce Korb bruce.k...@gmail.com skribis: Thank you for the explanation. However: On 01/03/12 07:03, Mike Gran wrote: It worked until I upgraded to openSuSE 12.1. $ guile --version guile (GNU Guile) 2.0.2 . (set! tmp-text (get act-text))

Re: Guile: What's wrong with this?

2012-01-03 Thread Bruce Korb
On 01/03/12 14:24, Ludovic Courtès wrote: 2. it is completely, utterly wrong to mutilate the Guile library into such a contortion that it interprets this: (define y hello) to be a request to create an immutable string anyway. It very, very plainly says, make 'y' and

Re: Guile: What's wrong with this?

2012-01-03 Thread Mike Gran
  In many systems it is desirable for constants (i.e. the values of literal   expressions) to reside in read-only-memory.  To express this, it is   convenient to imagine that every object that denotes locations is   associated with a flag telling whether that object is mutable or immutable.  

Re: Guile: What's wrong with this?

2012-01-03 Thread Noah Lavine
Hello, Then it turned out that the string functions would now clear the high order bit on strings, so they are no longer byte arrays and there is no replacement but to roll my own.  I stopped supporting byte arrays.  A noticable nuisance. This is just a side note to the main discussion, but