[racket] Scribble pain-point: itemlist
> 2. The item structure itself does not lend itself well to
> immediate styling, nor does it really serve any role other than
> gathering pre-flow together. But there are already mechanisms in the
> language for bundling pre-flow content together, such as para, nested,
> etc. If itemlist were to be generalized to consume these structures,
> it would be much more pleasant to work with.
Followup: in my own project, I'm replacing the implementation of
itemlist with a custom one that is easier to work with.
I guess that the motivation for @item is to mimic LaTeX's "\item".
However, since we're dealing with real functions that can consume
multiple values, each item is already conceptually distinct as an
argument to itemlist.
@item makes the @itemlist construct difficult to work with. So I'm
doing something like this now in my customized Scribble language, and
am happier for it:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(provide [rename-out [itemlist/splicing itemlist] [fake-item item]])
;; itemlist/splicing is like itemlist, but also cooperates with the
;; splice form to absorb arguments. We also treat each item
;; automatically with an @item if it's missing.
(define (itemlist/splicing #:style [style #f] . items)
(define spliced-items
(reverse
(let loop ([items items]
[acc '()])
(foldl (lambda (i acc)
(cond
[(splice? i)
(loop (splice-run i) acc)]
[(item? i)
(cons i acc)]
[else
(cons (item i) acc)]))
acc
items))))
(apply itemlist spliced-items #:style style))
;; fake-item: (listof any) -> (listof any)
;; We try to make itemlist more pleasant to work with.
Itemlist/splicing automatically
;; wraps items around every argument, so there's no need to call item
explicitly.
;; We provide a fake definition for fake-item that just returns the identity.
(define (fake-item . args)
args)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;