formlets icon indicating copy to clipboard operation
formlets copied to clipboard

Rework show API

Open PuercoPop opened this issue 9 years ago • 4 comments

Have you considered modifying the generic function showto take a stream to print to instead of returning strings?

PuercoPop avatar Nov 09 '16 18:11 PuercoPop

Hadn't, no. It doesn't sound like it would be hard to implement. I'm assuming this makes some common idiom easier?

inaimathi avatar Nov 09 '16 21:11 inaimathi

I'm assuming this makes some common idiom easier?

Not really, just that using streams to delegate rendering to sub-components is less clunky and generates less intermediate garbage as there is no need to concatenate the strings of sub-components (fields in this case).

PuercoPop avatar Nov 09 '16 21:11 PuercoPop

So, in order to implement this, it looks like we'd need to

  1. Introduce a new argument to show (the stream to be accepted)
  2. Modify html-to-str and html-to-stout macros to take their streams as arguments
  3. Pass the show argument to the output macro internally
  4. Modify define-show appropriately to handle the additional argument
  5. Modify calls to show in show-formlet

inaimathi avatar Nov 14 '16 01:11 inaimathi

I was thinking that show could be similar to print-object, except that it doesn't have to print unreadable objects between #< and >. In retrospect that is not the best choice for formlets as its API takes values and errors as arguments, adding a stream optional argument would be clunky. Also cl-who, unlike spinneret, doesn't export a special-variable that points to the stream it uses to write.

PuercoPop avatar Nov 14 '16 15:11 PuercoPop