My mistake - it’s getting late here in Sweden ;-)
It was the other way around…
LispWorks GUI on Mac OS X:
(stream-element-type *standard-output*) => CHARACTER
Delivered with LispWorks for Linux (32-bit) and running in terminal on Linux:
(stream-element-type *standard-output*) => BASE-CHAR
Ok, so my advice, when dealing with terminals, would be to test that, and restrict yourself to base-char when it cannot deal with all characters:
;; (beware of substituted typographical double quotes)
(let ((itemizer (if (subtypep ‘character (stream-element-type *standard-output*))
“•”
“*”)))
(dolist (item items)
(format t “~A ~A~%” itemizer item)))
And then, test whether export LC_ALL=sw_SW.UTF-8 makes your program use ‘character as element-type on the terminal. If not, then you will have to explicitely change the stream-element-type (if possible in LispWorks), by testing the environment variable yourself.
Unfortunately, I don’t have LispWork code, I can only show you ccl example:
(defun locale-terminal-encoding ()
"Returns the terminal encoding specified by the locale(7)."
#+(and ccl windows-target)
:iso-8859-1
;; ccl doesn't support :windows-1252.
;; (intern (format nil "WINDOWS-~A" (#_GetACP)) "KEYWORD")
#-(and ccl windows-target)
(dolist (var '("LC_ALL" "LC_CTYPE" "LANG")
:iso-8859-1) ; some random default…
(let* ((val (getenv var))
(dot (position #\. val))
(at (position #\@ val :start (or dot (length val)))))
(when (and dot (< dot (1- (length val))))
(return (intern (let ((name (string-upcase (subseq val (1+ dot)
(or at (length val))))))
(if (and (prefixp "ISO" name) (not (prefixp "ISO-" name)))
(concatenate 'string "ISO-" (subseq name 3))
name))
"KEYWORD"))))))
(defun set-terminal-encoding (encoding)
#-(and ccl (not swank)) (declare (ignore encoding))
#+(and ccl (not swank))
(mapc (lambda (stream)
(setf (ccl::stream-external-format stream)
(ccl:make-external-format :domain nil
:character-encoding encoding
:line-termination
(if (boolean-enval "LSE_TELNET" nil)
:windows
(or
#+unix :unix
#+windows :windows
#-(or unix windows) :unix)))))
(list (two-way-stream-input-stream *terminal-io*)
(two-way-stream-output-stream *terminal-io*)))
(values))
with:
(set-terminal-encoding (locale-terminal-encoding))
called in the main.
One thing we can learn from this example, is that we’re actually talking about the terminal, and that the actual CL stream is *TERMINAL-IO*; *standard-input* and *standard-output* may be indirect streams redirected to *TERMINAL-IO*. So you may have to actually modify *TERMINAL-IO*.
10 feb. 2017 kl. 22:37 skrev Pascal Bourguignon <
pjb@informatimago.com>:
On 10 Feb 2017, at 22:26, Burton Samograd <busfactor1@gmail.com> wrote:
Try (set-default-character-element-type 'character) at the top of your program.
Sent from my iPhone
On Feb 10, 2017, at 2:11 PM, Sven Emtell <sven.emtell@doremir.com> wrote:
Hello,
I have a piece of server code where I make some debug printouts using (format t ...) containing characters with cl:char-code > 256.
When I run it in LispWorks GUI on Mac OS X it outputs the characters nicely in the Listener,
but when I deliver the code using LispWorks for Linux (32-bit) and then run it in a Linux terminal it says:
Call to SIGerror #\U+2022 (of type CHARACTER) is not of type BASE-CHAR. while writing to error log, error not logged
I can see why when checking the element-type of *standard-output* on the two platforms.
LispWorks GUI on Mac OS X:
(stream-element-type *standard-output*) => BASE-CHAR
Delivered with LispWorks for Linux (32-bit) and running in terminal on Linux:
(stream-element-type *standard-output*) => CHARACTER
That’s suspicious, given that (subtypep ‘bash-char ‘character) must hold.
(I would expect a GUI to be able to display more characters than a terminal).
Furthermore, it’s not consistent with the error above.
Are you lying to us?
Is it possible to change the element type of *standard-output*?
Any other suggestions?
I would first check how the LC_ALL environment variable is set in both environment.
(check also the other LC_* environment variables if LC_ALL is not set).
Of course, normally LC_ALL should be set in function of the capabilities of your terminal.
Perhaps you should check (stream-element-type *standard-output*) before sending to the terminal characters that it won’t be able to render?
I mean, if it gives a meaningfully different result for an ASCII terminal than for a GUI?