chicken-janitors
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

#1780: wishlist: support keywords in coops (make <class> ...) form


From: Chicken Trac
Subject: #1780: wishlist: support keywords in coops (make <class> ...) form
Date: Wed, 25 Aug 2021 20:33:01 -0000

#1780: wishlist: support keywords in coops (make <class>  ...) form
---------------------------------------+------------------------
            Reporter:  Shawn Rutledge  |       Type:  defect
              Status:  new             |   Priority:  major
           Milestone:  someday         |  Component:  extensions
             Version:  5.2.0           |   Keywords:
Estimated difficulty:                  |
---------------------------------------+------------------------
 As described in SRFI-88, keywords are nice to have for widget
 constructors:

 (tcltk-frame relief: 'ridge
                  borderwidth: 4
                  height: "50px"
                  width: "100px")

 but if widgets are coops classes, it's natural to use the `make` form
 rather than a separate constructor procedure for each class:

 (make <widget> width: 100 height: 50 ...)

 I got it working with a quick hack (which no doubt could be more elegant):

 {{{
 Index: coops.scm
 ===================================================================
 --- coops.scm   (revision 40393)
 +++ coops.scm   (working copy)
 @@ -9,9 +9,9 @@

  (declare (disable-interrupts))

 -(import scheme matchable srfi-1 record-variants
 +(import scheme matchable srfi-1 record-variants symbol-utils
          (chicken condition) (chicken fixnum) (chicken format)
 -        (chicken syntax) (chicken sort)
 +        (chicken keyword) (chicken syntax) (chicken sort)
          (only miscmacros ensure))
  (import-for-syntax matchable (chicken plist) srfi-1)

 @@ -176,6 +176,7 @@
            (sv (make-vector (length slotnames) uninitialized))
            (i (make-coops-instance c sv)))
        (define (slot-index name)
 +        (when (keyword? name) (set! name (keyword->symbol name)))
         (or (position name slotnames)
             (error "no such slot in instances of given class" name c)))
        (let loop ((svsv svsv))
 }}}

 Then one might expect it to be possible for slot names to be keywords in
 every other use case too (such as slot accessors); but I have custom
 syntax implemented for those anyway, so far like this:

 (-> widget width) ; no colon, because it would look funny; no quote, for
 convenience
 (=> widget width: 50)

 I'd rather not have to wrap make in something custom, because it's already
 such a nice name.

 In Chicken 4 it wasn't an issue, because (symbol? foo:) is true.

-- 
Ticket URL: <https://bugs.call-cc.org/ticket/1780>
CHICKEN Scheme <https://www.call-cc.org/>
CHICKEN Scheme is a compiler for the Scheme programming language.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]