From: Bruno H. <br...@cl...> - 2004-10-20 15:06:38
|
Hi, Nikodemus Siivola wrote: > :readably t means to print for reading with the standard readtable So here's a test for numbers. It was mentioned in comp.lang.lisp recently. * (write-to-string 22/7 :base 5 :readably t) "42/12" * (let ((*readtable* sb-impl::*standard-readtable*)) (values (read-from-string *))) 7/2 * (eql * 22/7) NIL Bruno |
From: Nikodemus S. <tsi...@cc...> - 2004-10-26 10:11:35
|
On Wed, 20 Oct 2004, Bruno Haible wrote: > So here's a test for numbers. It was mentioned in comp.lang.lisp recently. > > * (write-to-string 22/7 :base 5 :readably t) > > "42/12" > * (let ((*readtable* sb-impl::*standard-readtable*)) > (values (read-from-string *))) > > 7/2 > * (eql * 22/7) Are we allowed to print "#5r42/12"? I'd like to conditionalize the base-specifier printing on (or *print-radix* (and *print-readably* (/= 10 *print-base*))). Cheers, -- Nikodemus Schemer: "Buddha is small, clean, and serious." Lispnik: "Buddha is big, has hairy armpits, and laughs." |
From: Bruno H. <br...@cl...> - 2004-10-26 11:37:29
|
Nikodemus Siivola wrote: > Are we allowed to print "#5r42/12"? I'd like to conditionalize the > base-specifier printing on (or *print-radix* (and *print-readably* (/= 10 > *print-base*))). Yes. You can also conditionalize it on (or *print-radix* *print-readably*) if you like. Bruno |
From: Nikodemus S. <tsi...@cc...> - 2004-10-26 10:22:15
|
On Tue, 26 Oct 2004, Nikodemus Siivola wrote: >> * (write-to-string 22/7 :base 5 :readably t) >> >> "42/12" > Are we allowed to print "#5r42/12"? I'd like to conditionalize the > base-specifier printing on (or *print-radix* (and *print-readably* (/= 10 > *print-base*))). Actually thinking more on this, I'd argue that while suboptimal this is not strictly non-conforming: base is not a feature of the readtable, and *print-readably* doesn't mention standard-io syntax. My suggested "fix" hasn't changed, though. Cheers, -- Nikodemus Schemer: "Buddha is small, clean, and serious." Lispnik: "Buddha is big, has hairy armpits, and laughs." |
From: Christophe R. <cs...@ca...> - 2004-10-26 10:42:44
|
Nikodemus Siivola <tsi...@cc...> writes: > On Tue, 26 Oct 2004, Nikodemus Siivola wrote: > >>> * (write-to-string 22/7 :base 5 :readably t) >>> "42/12" > >> Are we allowed to print "#5r42/12"? I'd like to conditionalize the >> base-specifier printing on (or *print-radix* (and *print-readably* >> (/= 10 *print-base*))). > > Actually thinking more on this, I'd argue that while suboptimal this > is not strictly non-conforming: base is not a feature of the > readtable, and *print-readably* doesn't mention standard-io syntax. My > suggested "fix" hasn't changed, though. I'm inclined to agree with your reasoning more than you are, then: that printing the radix is not required, because *print-readably* only manages printing readably relative to the standard readtable. Cheers, Christophe |
From: Bruno H. <br...@cl...> - 2004-10-26 12:13:17
|
Christophe Rhodes wrote: > I'm inclined to agree with your reasoning more than you are, then: > that printing the radix is not required, because *print-readably* only > manages printing readably relative to the standard readtable. Huh? I cannot follow the logic. The spec says that "printing any object O1 produces a printed representation that, when seen by the Lisp reader while the standard readtable is in effect, will produce an object O2 that is similar to O1." This spec does not mention the value of *print-base*, neither for the printing phase, nor for the reading phase. Therefore the sentence should hold regardless of the value of *print-base*, which in my example was 5 and 10 respectively. You seem to deduce from the non-mention of *print-base* that it should have the same value in the reading phase than in the printing phase. This is pure imagination. Bruno |
From: Christophe R. <cs...@ca...> - 2004-10-26 12:53:32
|
Bruno Haible <br...@cl...> writes: > Christophe Rhodes wrote: >> I'm inclined to agree with your reasoning more than you are, then: >> that printing the radix is not required, because *print-readably* only >> manages printing readably relative to the standard readtable. > > Huh? I cannot follow the logic. The spec says that > "printing any object O1 produces a printed representation that, when > seen by the Lisp reader while the standard readtable is in effect, > will produce an object O2 that is similar to O1." > > This spec does not mention the value of *print-base*, neither for the > printing phase, nor for the reading phase. Therefore the sentence should > hold regardless of the value of *print-base*, which in my example was > 5 and 10 respectively. > > You seem to deduce from the non-mention of *print-base* that it should have > the same value in the reading phase than in the printing phase. This is pure > imagination. Sure, but the problem with this is that one can take this to absurdity: consider printing a symbol foo:bar. Should this be printed as FOO:BAR or FOO::BAR or #.(export (intern "BAR" "FOO") "FOO") or #.(progn (or (find-package "FOO") (make-package "FOO")) (export (intern "BAR" "FOO") "FOO")) or something even more complex? "The spec does not mention the possibility of packages being altered, neither for the printing phase, nor for the reading phase. Therefore the sentence should hold regardless of the state of the package hierarchy." If you have a clear distinction between those things that are allowed to differ between printing and reading and those which aren't, then by all means please post it and we can discuss it; until then, please refrain from dismissing concerns and alternative interpretations as "pure imagination": there's no real need for that on technical mailing lists. Cheers, Christophe |
From: Raymond T. <ray...@er...> - 2004-10-26 14:29:32
|
>>>>> "Bruno" == Bruno Haible <br...@cl...> writes: Bruno> Christophe Rhodes wrote: >> I'm inclined to agree with your reasoning more than you are, then: >> that printing the radix is not required, because *print-readably* only >> manages printing readably relative to the standard readtable. Bruno> Huh? I cannot follow the logic. The spec says that Bruno> "printing any object O1 produces a printed representation that, when Bruno> seen by the Lisp reader while the standard readtable is in effect, Bruno> will produce an object O2 that is similar to O1." Bruno> This spec does not mention the value of *print-base*, neither for the Bruno> printing phase, nor for the reading phase. Therefore the sentence should Bruno> hold regardless of the value of *print-base*, which in my example was Bruno> 5 and 10 respectively. Bruno> You seem to deduce from the non-mention of *print-base* that it should have Bruno> the same value in the reading phase than in the printing phase. This is pure Perhaps not directly relevant, but I once asked on c.l.l. about printing floats readably. I thought floats printed readably should have an exponent marker. The general consensus on c.l.l. was that the read environment must match the print environment---in this case, *read-default-float-format* has to be the same. Ray |
From: Bruno H. <br...@cl...> - 2004-10-26 13:26:44
|
Christophe Rhodes wrote: > If you have a clear distinction between those things that are allowed > to differ between printing and reading and those which aren't, then by > all means please post it The page on *print-readably* links to "similar"; this links to "similarity"; this refers to section 3.2.4, and in particular the definition of similarity in 3.2.4.2. (It is strange that for defining the semantics of *print-readably*, they refer to a notion meant for explaining COMPILE-FILE, but that's how it is.) > Sure, but the problem with this is that one can take this to > absurdity: consider printing a symbol foo:bar. Should this be printed as > FOO:BAR > or > FOO::BAR or #.(intern "BAR" "FOO") > or > #.(export (intern "BAR" "FOO") "FOO") > or > #.(progn (or (find-package "FOO") (make-package "FOO")) > (export (intern "BAR" "FOO") "FOO")) > or something even more complex? The second is to be preferred over the first one, because no text in 3.4.2.2.2 says that the symbol must already exist and be exported during the reading phase. The third and the second one appear to be equivalent to me, because the *PRINT-READABLY* description says that the reading phase uses the standard readtable, and the standard readtable is poled to :UPCASE, as Nikodemus pointed out. It's unclear whether the fourth one is needed, because no text talks about the 'exported' status of symbols in this context. The fifth one is not needed because the text about symbols and packages in 3.4.2.2.2 says that the programmer is responsible for ensuring that the package exists. > please > refrain from dismissing concerns and alternative interpretations as > "pure imagination": there's no real need for that on technical mailing > lists. Sorry. I apologize for the words. I only meant to express that I didn't see a link/relation between your interpretation and the concrete text of the CLHS. Bruno |
From: Christophe R. <cs...@ca...> - 2004-10-26 13:45:08
|
Bruno Haible <br...@cl...> writes: > Christophe Rhodes wrote: >> If you have a clear distinction between those things that are allowed >> to differ between printing and reading and those which aren't, then by >> all means please post it > > The page on *print-readably* links to "similar"; this links to "similarity"; > this refers to section 3.2.4, and in particular the definition of similarity > in 3.2.4.2. (It is strange that for defining the semantics of > *print-readably*, they refer to a notion meant for explaining COMPILE-FILE, > but that's how it is.) So the idea would be that no matter what changes between the print phase and the read, (defvar *printed* (write-to-string foo :readably t)) [ ... a long time, but no mutation of FOO's aggregate structure or contents ... ] (defvar *read* (let ((*readtable* (copy-readtable nil))) (read-from-string *printed*))) (similarp *read* foo) => true provided the names of packages referenced by FOO or its contents still designate packages (not necessarily the same ones, though)? Are there any other exceptions? Cheers, Christophe |
From: Bruno H. <br...@cl...> - 2004-10-26 14:24:25
|
Christophe Rhodes wrote: > So the idea would be that no matter what changes between the print > phase and the read, > > (defvar *printed* (write-to-string foo :readably t)) > > [ ... a long time, but no mutation of FOO's aggregate structure or > contents ... ] > > (defvar *read* (let ((*readtable* (copy-readtable nil))) > (read-from-string *printed*))) > (similarp *read* foo) => true > > provided the names of packages referenced by FOO or its contents still > designate packages (not necessarily the same ones, though)? That's how I understand it, yes. > Are there any other exceptions? I don't see other "programmer requirements" in 3.2.4.2.2. Bruno |
From: Bruno H. <br...@cl...> - 2004-10-26 17:50:55
|
Raymond Toy wrote: > printing floats readably. I thought floats printed readably should > have an exponent marker. Yes, here's a test case. Fails in cmucl-19a and sbcl-0.8.15. (let ((x 3.7d0)) (eql x (read-from-string (let ((*read-default-float-format* 'double-float)) (write-to-string x :readably t))))) > The general consensus on c.l.l. was that the > read environment must match the print environment---in this case, > *read-default-float-format* has to be the same. Which paragraphs of ANSI CL was this argument based upon? Bruno |
From: Raymond T. <ray...@er...> - 2004-10-26 18:27:27
|
>>>>> "Bruno" == Bruno Haible <br...@cl...> writes: Bruno> Raymond Toy wrote: >> printing floats readably. I thought floats printed readably should >> have an exponent marker. Bruno> Yes, here's a test case. Fails in cmucl-19a and sbcl-0.8.15. For some value of "fail". :-) Is this what this discussion is about? :-) Bruno> (let ((x 3.7d0)) Bruno> (eql x (read-from-string Bruno> (let ((*read-default-float-format* 'double-float)) Bruno> (write-to-string x :readably t))))) >> The general consensus on c.l.l. was that the >> read environment must match the print environment---in this case, >> *read-default-float-format* has to be the same. Bruno> Which paragraphs of ANSI CL was this argument based upon? None AFAICT. But read for yourself: http://groups.google.com/groups?hl=en&lr=&c2coff=1&threadm=4n1yq7xv7k.fsf%40rtp.ericsson.se&rnum=1&prev=/groups%3Fq%3Dread-default-float-format%2Braymond%2Btoy%26hl%3Den%26lr%3D%26group%3Dcomp.lang.lisp.*%26c2coff%3D1%26selm%3D4n1yq7xv7k.fsf%2540rtp.ericsson.se%26rnum%3D1 Ray |