Skip to content
stacksmith edited this page Feb 26, 2017 · 16 revisions

PRIN


PRIN is a convenient printing facility for SubText streams. During bulk text output it is painful to programmatically tag text runs. Even without tags and context, the format statements become bulky. PRIN form attempts to simplify the task of outputting values, whether constant or computed using the familiar parenthetical structure (to tag text insert a `(tg tagid ...) form, etc). In addition, arbitrary expressions may be executed without printing, as long as the form returns NIL.


(prin stream &rest forms)

  • stream evaluates to a subtext stream;
  • forms are evaluated in context and result is output, except for the following forms: nil and anything evaluating to nil
  • Nil is not printed. This may be used for conditional output, or for side effects of the expression. prog0 macro is provided to facilitate that.

(tg tagid &rest forms)

  • tagid resolves to a string or a gtk-text-tag

(context class init &rest forms)

  • class evaluates to a context class;
  • init is a list spliced into (make-instance 'class ...) form to create the context

Example

 (prin *buffer*                                           ;; buffer now bound to out 
   "ok," (tg tag1 " Test, ") 1 #\space 2 3 "!" #\newline  ;; anything princ-able goes
   (format nil "~%Hello ~A~&" "world")                    ;; format via string
   (tg tag2 (prog0 (format out "year ~A~&" year)))        ;; any output inside tg is tag2'ed
   (tg "blue" "hello" (tg tag2 " cruel") " world")        ;; nested tags
   (tag1 "hello" (+ 1 2))                                 ;; generate output
   1 2 (tg "blue" "hello") (context button (:code ...) "what") ;; ad-hoc contexts
   ok null "null does not print" )                        ;; (prog0 ... nil) works too.

Internally, prin subforms are either items to be printed, or a form that generates a list whose car is the promise (such as a tag), and the rest is items to be printed in that context. Nil is ignored by the printer. You can extend it by following these premises.

Clone this wiki locally