Lisp HUG Maillist Archive

Confusion/Bug with coerce 'simple-string


This seems like a bug, but I might just be confused.  I have an array
that is not a simple-string.  This array has elements in it which are
not of type base-char.  When I try to coerce this to a simple-string I
get an error:

    (let ((s (make-array 5 
                         :element-type 'character
                         :adjustable t
                         :fill-pointer 5
                         :initial-element (code-char 8217))))
      (coerce s 'simple-string))
    => #\’ is not of type BASE-CHAR. [Condition of type TYPE-ERROR]

It seems like there is a bug in coerce that assumes that the resulting
string must be made up of BASE-CHAR elements.  Can someone verify that
this is a bug?

FWIW, sbcl has no problem with this code.

(This bug is exercised when you use CL-PPCRE, since it uses
simple-strings internally.)

Cheers,
Chris Dean


Re: Confusion/Bug with coerce 'simple-string

On Wed, Dec 26, 2007 at 05:54:27PM -0800, Chris Dean wrote:
> This seems like a bug, but I might just be confused.  I have an
> array that is not a simple-string.  This array has elements in it
> which are not of type base-char.  When I try to coerce this to a
> simple-string I get an error:
> 
>     (let ((s (make-array 5 
>                          :element-type 'character
>                          :adjustable t
>                          :fill-pointer 5
>                          :initial-element (code-char 8217))))
>       (coerce s 'simple-string))
>     => #\??? is not of type BASE-CHAR. [Condition of type TYPE-ERROR]
> 
> It seems like there is a bug in coerce that assumes that the
> resulting string must be made up of BASE-CHAR elements.  Can someone
> verify that this is a bug?

I would agree:

CL-USER 8 > (code-char 8217)
#\U+2019

CL-USER 9 > (type-of *)
CHARACTER

>From the Hyperspec:

  A simple string is a specialized one-dimensional simple array whose
  elements are of type character or a subtype of type character. When
  used as a type specifier for object creation, simple-string means
  (simple-array character (size)).

I don't see anything that says a SIMPLE-STRING must be only
BASE-CHARs.

-- L


Re: Confusion/Bug with coerce 'simple-string

Hello Chris,

| This seems like a bug, but I might just be confused.  I have an array
| that is not a simple-string.  This array has elements in it which are
| not of type base-char.  When I try to coerce this to a simple-string I
| get an error:
|
|     (let ((s (make-array 5
|                          :element-type 'character
|                          :adjustable t
|                          :fill-pointer 5
|                          :initial-element (code-char 8217))))
|       (coerce s 'simple-string))
|     => #\’ is not of type BASE-CHAR. [Condition of type TYPE-ERROR]
|
| It seems like there is a bug in coerce that assumes that the resulting
| string must be made up of BASE-CHAR elements.  Can someone verify that
| this is a bug?

This is not a real bug but only a misuse :-).

You should either set

  (lw:set-default-character-element-type 'lw:simple-char)

beforehand, or specify the correct element type explicitly:

  (let ((s (make-array 5
             :element-type 'lw:simple-char
             :adjustable t
             :fill-pointer 5
             :initial-element (code-char 8217))))
     (coerce s 'simple-string))
--
Sincerely,
Dmitriy Ivanov
lisp.ystok.ru


Re: Confusion/Bug with coerce 'simple-string


"Dmitriy Ivanov" <divanov@aha.ru> writes:
> beforehand, or specify the correct element type explicitly:
>
>   (let ((s (make-array 5
>              :element-type 'lw:simple-char
>              :adjustable t
>              :fill-pointer 5
>              :initial-element (code-char 8217))))
>      (coerce s 'simple-string))

This gives the same error.

Not surprising since the original code was using an explicit
element-type of 'character and (subtypep 'lw:simple-char 'character) => T

>   (lw:set-default-character-element-type 'lw:simple-char)

This does work, but according to the LispWorks docs:

| If you write for a fat character implementation you should already be
| aware of these issues, and make some attempt to provide explicit
| types.

Since we are setting the type explicitly, I don't think we need to
change the default-character-type.

Cheers,
Chris Dean


Tabs in tab layout do not appear until interface is resized

I am adding tabs to a tab-layout after the interface is displayed.
Only the top edges of the tabs appear until the interface is resized.
Using capi:redisplay-interface does not make the tabs appear.  Here is
my example.  Thanks for any help.

Mitch

(capi:define-interface missing-tabs ()
  ()
  (:layouts
   (a-tab-layout
    capi:tab-layout
    '()
    :accessor a-tab-layout
    :print-function 'first
    :visible-child-function 'second)
   (seating-view
    capi:row-layout
    '(a-tab-layout))
   (main-layout
    capi:column-layout
    '(seating-view)))
  (:default-initargs
   :layout 'main-layout
   :best-height 300
   :best-width 300))

(defun initialize-tabs (tab-interface performances)
  (let ((tab-pinboards))
    (dotimes (i 4)
      (push (list
             (nth i performances)
             (make-instance 'capi:pinboard-layout))
            tab-pinboards))
    (setf (capi:collection-items (a-tab-layout tab-interface))
(reverse tab-pinboards))
    (setf (capi:choice-selection (a-tab-layout tab-interface)) 0)))

CL-USER> (setf d (capi:display (make-instance 'missing-tabs)))

CL-USER> (capi:apply-in-pane-process d 'initialize-tabs d '("1" "2"
"3" "4"))


Re: Tabs in tab layout do not appear until interface is resized

On mac, trying this code result on a crash : nothing happens when I evaluate
the display procedure (no interface is visible, the evaluation seems to
enter in a infinite loop), when I quit LW this crash occurs...

Error: Invoking a method "release" on a null pointer.
  1 Destroy element #<CAPI-INTERNALS:LIBRARY-TAB-LAYOUT #<CAPI:TAB-LAYOUT
A-TAB-LAYOUT [0 items] 2169E5FB> 2008F42B>.
  2 (continue) Ignore the error.
  3 (abort) Destroy interface "Untitled LispWorks Interface - 1" and its
representation.
  4 Restart top-level loop.

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


Denis


Le 29/12/07 7:32, « [NOM] » <[ADRESSE]> a écrit :

> 
> I am adding tabs to a tab-layout after the interface is displayed.
> Only the top edges of the tabs appear until the interface is resized.
> Using capi:redisplay-interface does not make the tabs appear.  Here is
> my example.  Thanks for any help.
> 
> Mitch
> 
> (capi:define-interface missing-tabs ()
>   ()
>   (:layouts
>    (a-tab-layout
>     capi:tab-layout
>     '()
>     :accessor a-tab-layout
>     :print-function 'first
>     :visible-child-function 'second)
>    (seating-view
>     capi:row-layout
>     '(a-tab-layout))
>    (main-layout
>     capi:column-layout
>     '(seating-view)))
>   (:default-initargs
>    :layout 'main-layout
>    :best-height 300
>    :best-width 300))
> 
> (defun initialize-tabs (tab-interface performances)
>   (let ((tab-pinboards))
>     (dotimes (i 4)
>       (push (list
>              (nth i performances)
>              (make-instance 'capi:pinboard-layout))
>             tab-pinboards))
>     (setf (capi:collection-items (a-tab-layout tab-interface))
> (reverse tab-pinboards))
>     (setf (capi:choice-selection (a-tab-layout tab-interface)) 0)))
> 
> CL-USER> (setf d (capi:display (make-instance 'missing-tabs)))
> 
> CL-USER> (capi:apply-in-pane-process d 'initialize-tabs d '("1" "2"
> "3" "4"))
> 

-------------------------------------------------------
Denis Pousseur
70 rue de Wansijn
1180 Bruxelles, Belgique

Tel : 32 (0)2 219 31 09
Mail :  denis.pousseur@gmail.com
-------------------------------------------------------



Re: Confusion/Bug with coerce 'simple-string

Unable to parse email body. Email id is 7380

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