Lisp HUG Maillist Archive

open :element-type has no effect

When trying to save a buffer containing SIMPLE-TEXT-STRINGs, in the 
Lispworks Editor, I get the error

     <char> is not of type BASE-CHAR

A little experimentation led me to suspect that this is the result of a 
more fundamental problem:

(with-open-file (stream "~/whatever"
			:direction :output
			:if-exists :supersede
			:element-type 'lw:simple-char)
   (stream-element-type stream))

=>  BASE-CHAR

:element-type seems to be ignored, by OPEN (and therefore also by 
WITH-OPEN-FILE).


I am using LW 4.3.7 for Macintosh Personal Edition.

Is this a known bug? Is it a restriction of the Personal Edition? Or am 
I missing something?

Thanks.


Re: open :element-type has no effect

Jacek Generowicz wrote:

> When trying to save a buffer containing SIMPLE-TEXT-STRINGs, in the 
> Lispworks Editor, I get the error
> 
>     <char> is not of type BASE-CHAR
> 
> A little experimentation led me to suspect that this is the result of a 
> more fundamental problem:
> 
> (with-open-file (stream "~/whatever"
>             :direction :output
>             :if-exists :supersede
>             :element-type 'lw:simple-char)
>   (stream-element-type stream))
> 
> =>  BASE-CHAR
> 
> :element-type seems to be ignored, by OPEN (and therefore also by 
> WITH-OPEN-FILE).
> 
> 
> I am using LW 4.3.7 for Macintosh Personal Edition.
> 
> Is this a known bug? Is it a restriction of the Personal Edition? Or am 
> I missing something?
> 

On LWW I got it to work by doing this (I had to cut some of it out
to get it into my mail client):

It looks like you have to specify the :external-format of the file
to :utf-8 (or maybe some other format).

CL-USER 3 > (setf s (make-array 16 :element-type 'lw:simple-char))

CL-USER 4 > (type-of (char s 0))
BASE-CHAR

CL-USER 5 > (loop for i from 0 below (length s)
                   do (setf (char s i) (int-char 512)))
NIL

CL-USER 7 > (type-of (char s 0))
SIMPLE-CHAR

CL-USER 8 > (with-open-file (stream "test" :direction :output
                                     :element-type 'lw:simple-char)

               (write-string s stream))

Error: In a call to SEQ::%SET-ACCESS-ARRAY: #\A is not of type BASE-CHAR.
   1 (abort) Return to level 0.
   2 Return to top loop level 0.

Type :b for backtrace, :c <option number> to proceed,  or :? for other options

CL-USER 9 : 1 > :a


CL-USER 12 > (with-open-file (stream "test" :direction :output
                                     :external-format :utf-8
                                     :element-type 'simple-char)
                (write-string s stream))

<stuff deleted, text string>

CL-USER 13 > (char-int (with-open-file (stream "test" :direction :input
                                                :external-format :utf-8
                                                :element-type 'simple-char)
                          (read-char stream)))
512

CL-USER 22 > (with-open-file (stream "test" :direction :input
                                                :external-format :utf-8
                                                :element-type 'simple-char)
                          (stream-external-format stream))
(:UTF-8 :EOL-STYLE :CRLF)

CL-USER 23 > (with-open-file (stream "test" :direction :input
                                      :element-type 'simple-char)
                          (stream-external-format stream))
(:LATIN-1 :EOL-STYLE :CRLF)

CL-USER 24 >


Wade


Updated at: 2020-12-10 08:54 UTC