Racket/gui list-box% vs choice% append

Hi!

This is my first post, so I hope I don't violate something here. If this does not fit here I hope you tell me so I can adapt.

I enjoy programming small tools with Racket, and I really like the easy to use gui Racket offers out of the box. The "standard library" is impressive, it's useful and the documentation is top!

However, I stumbled across a small issue (well, I can sail around it, but I don't think that should be necessary). I can append data to a list-box%, but not to a choice%.

#lang racket
(require racket/gui)

(define frame (new frame% [label "Example"]))

; a simple listbox
(define my-list-box
  (new list-box%
       [parent frame]
       [label "my listbox:"]
       [choices '()]))

; i can append an entry and assign a value to this entry
(send my-list-box append "hello" 123)

; later on i can access this data:
(send my-list-box get-data 0) ; this will return 123

; now, a choice%
(define my-choice
 (new choice%
      [parent frame]
      [label "select something:"]
      [choices '()]))

#|

this does not work:

   (send my-choice append "other hello" 123)

it throws:

-append method in basic-list-control%: arity mismatch;
 the expected number of arguments does not match the given number
  expected: 1
  given: 2

I can only do (send my-choice append "whatever")

|#

(send frame show #t)

I like to use the appended data to store perhaps table id's.
At the moment I just use list-box% instead of choice%, because I'm lazy to sail around.
The UI gets a bit hideous, but that's no matter.

But I'm curious, now, my question:
How would you implement such a functionality?
A in memory table that maps values to choice items? Inherit choice% and do it there? That would be my first thoughts, but I would like to get other opinions too.

Thank you very much for your time!

The docs and the case-lambda in the library agree with your reasoning. You may want to open a GH issue at

https://github.com/racket/racket

(FIWI, if you right click on list-box% in DrRacket you can open the library. The bottom-most class is the one your code instantiates. The -append definition using case-lambda is the one your code is sending a message to. But, the second clause then dives into the wx layer and seems to call back the -append from the superclass, and that one takes only one argument.)

Ouch, I am silly.

(send my-list-box append "other hello" 123)

Your code sent the message to the wrong object. No issue needed.

I found

Overrides append in list-control<%>.

Adds a new item to the list box with an associated “data” object. The data object is not displayed in the list box; it is provided merely as a convenience for use with get-data, possibly allowing a programmer to avoid managing a separate item-to-data mapping in addition to the list box control.

See also append in list-control<%>.

It seems to me list-box% is the only widget that does have that functionality.
I try to implement the mentioned item-to-data mapping myself, shouldn't be hard to do.

Thank you, G!