I have noticed that if i set the *print-base* to 32, sbcl will print
NIL as |NIL|
in the repl, but not inside a format ~A directive. Does anyone know
if this is
the correct behavior?
Jimka wrote:
> I have noticed that if i set the *print-base* to 32, sbcl will print
> NIL as |NIL|
> in the repl, but not inside a format ~A directive. Does anyone know
> if this is
> the correct behavior?
Maybe this will clarify:
* (setf *print-base* 32)
10
* 23
N
Eirik.
········@gmail.com wrote:
> Jimka wrote:
> > I have noticed that if i set the *print-base* to 32, sbcl will print
> > NIL as |NIL|
> > in the repl, but not inside a format ~A directive. Does anyone know
> > if this is
> > the correct behavior?
>
> Maybe this will clarify:
>
> * (setf *print-base* 32)
>
> 10
>
> * 23
>
> N
>
Or, to elaborate ;) :
* 24149
NIL
Eirik.
Hi eirik, it does not clarify but in fact just reiterates my question.
How should symbols print in the repl and how should they print
with format ~A when the *print-base* is different from 10?
-jim
········@gmail.com wrote:
> Jimka wrote:
> > I have noticed that if i set the *print-base* to 32, sbcl will print
> > NIL as |NIL|
> > in the repl, but not inside a format ~A directive. Does anyone know
> > if this is
> > the correct behavior?
>
> Maybe this will clarify:
>
> * (setf *print-base* 32)
>
> 10
>
> * 23
>
> N
>
> Eirik.
Jimka wrote:
> Hi eirik, it does not clarify but in fact just reiterates my question.
> How should symbols print in the repl and how should they print
> with format ~A when the *print-base* is different from 10?
>
Yeah, I was a bit quick on the trigger there.
(format t "~A~A" 'nil 24149) prints "NILNIL" in SBCL. Allegro CL also
prints without pipes, but uses lower-case for the numerical value, so
it becomes "NILnil". At least in Allegro CL you can tell the
difference.
Both are correct behaviour since ~A is "aestetic" printing, objects are
printed without any escape characters. If you use ~S (standard) you
will get pipes around NIL.
(format t "~A ~S" 'nil 'nil)
NIL |NIL|
Eirik.
"Jimka" <·····@rdrop.com> writes:
> ········@gmail.com wrote:
>> Jimka wrote:
>> > I have noticed that if i set the *print-base* to 32, sbcl will print
>> > NIL as |NIL|
>> > in the repl, but not inside a format ~A directive. Does anyone know
>> > if this is
>> > the correct behavior?
>>
>> Maybe this will clarify:
>>
>> * (setf *print-base* 32)
>>
>> 10
>>
>> * 23
>>
>> N
>>
>> Eirik.
>
> Hi eirik, it does not clarify but in fact just reiterates my question.
> How should symbols print in the repl and how should they print
> with format ~A when the *print-base* is different from 10?
(loop for *print-readably* in '(nil t)
do (format t "*print-readably* = ~S~%" *print-readably*)
(let ((*print-base* 36))
(format t "~{~A ~:* ~S ~:* ~W~%~}" '(nil #36rNIL))))
*print-readably* = NIL
NIL |NIL| |NIL|
NIL NIL NIL
*print-readably* = |COMMON-LISP|::|T|
NIL |COMMON-LISP|::|NIL| |COMMON-LISP|::|NIL|
NIL 30477. 30477.
CLHS ~A says that symbols should print without escape.
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
----------> http://www.netmeister.org/news/learn2quote.html <-----------
---> http://homepage.ntlworld.com/g.mccaughan/g/remarks/uquote.html <---
__Pascal Bourguignon__ http://www.informatimago.com/
From: Tim Bradshaw
Subject: Re: how should symbols be printed when *print-base* is different than 10?
Date:
Message-ID: <ecqegm$sfc$1$830fa7b3@news.demon.co.uk>
On 2006-08-26 14:10:06 +0100, "Jimka" <·····@rdrop.com> said:
> I have noticed that if i set the *print-base* to 32, sbcl will print
> NIL as |NIL|
> in the repl, but not inside a format ~A directive. Does anyone know
> if this is
> the correct behavior?
Yes, it is correct. ~A is defined to do what PRINC does, in particular
it binds *PRINT-ESCAPE* and *PRINT-READABLY* to NIL, so you get just
the name. I am not sure the top-level loop is defined tightly enough
to say, but I'm sure it's fine for an implementation to print results
with at least *PRINT-ESCAPE* bound to T (in other words to use, say,
PRINT, not WRITE etc). In fact that's what I'd hope they'd do.
It's perhaps easier to see what is going on if you consider a symbol
like what you get by (intern "3" *package*)
--tim
Jimka wrote:
> I have noticed that if i set the *print-base* to 32, sbcl will print
> NIL as |NIL|
> in the repl, but not inside a format ~A directive. Does anyone know
> if this is
> the correct behavior?
>
It's a way for Lisp to make it clear that it means that "NIL"
it returned was a symbol, since now it could also be a number.
try this :
(setf *print-base* 32)
(setf *read-base* 32)
(+ 1 nil)
... now try yourself to return in base 10 than look below
...
...
...
(|SETF| |*READ-BASE*| a)
(setf *print-base* 10)
funny ah ?
bye :)