screwlisp proposes kittens

Fun ction with lisp format tilde slash directive

Aside from all the incredible episodes recently¹, I better write something. On sunday I demoed lisp’s slime-scratch (and format) compared to emacs-lisp’s scratch (and format). Here is my slightly worse version of my friend jns’ columnar formatting. Mine is worse because jns’ has weighted bidirection justification and mine has no justification². However, mine uses the eminently loveable tilde slash common lisp format directive.

Here I quickly wrote a thing that does this:

ah distinc-  and each se-  eagerly i wi-  from my books|
tly i reme-  parate dying  shed the mor-  surcease from|
mber.it was  ember.wroug-  row.vainly i|  sorrow.sorrow|
in the ble-  ht its ghost  had sought to  for the lost |
ak december  upon the fl-  borrow.||||||  lenore.|||||||
|||||||||||  oor.||||||||  |||||||||||||  ||||||||||||||
  1. Kent Pitman’s updates-described representation of a 2023 introduction to lisp style conditions for the pythons (Kent) (Kent) (Kent (Kent)) & Discussion the Tuesday-night-in-americas after with Kent, Scott Zimmermann, Ramin (and I) & Me disappointing Robert Strandh³ about the European time slot live show he heard about with just elisp scratch/lisp scratch and format comparisons
  2. gopher://gopher.linkerror.com/0/phlog/2022/20220321.
  3. https://metamodular.com/ . Learned lisp from Erik Sandewall. Rightly felt I was not using recursive expressions of symbolic equations enough in my lisp that sunday morning in europe live.

¹ Was basically everyone’s Christmas present to me, thanks everyone.

What is the function going to do

Honestly, I wrote the function on a whim as thoughts occured to me, so I am just going to tell you what it does. For a special (special) list, *wordses* it prints so many downcased (whispered?) characters from any of four lists (ā€œof sentencesā€) in *wordses* to the format stream.

E.g.

(in-package :cl-user)
(defparameter *wordses*
  '(((ah distinctly i remember)
     (it was in the bleak december)
     )
    ((and each separate dying ember)
     (wrought its ghost upon the floor)
     )
    ((eagerly I wished the morrow)
     (vainly I had sought to borrow)
     )
    ((from my books surcease from sorrow)
     (sorrow for the lost lenore)
     )))

(loop :repeat 6 :do
  (format t "~@{~?~^  ~}~%"
	  "~/cl-user::words-text/" '(11)
	  "~:/cl-user::words-text/" '(12)
	  "~@/cl-user::words-text/" '(13)
	  "~@:/cl-user::words-text/" '(14)))

You already saw the output at the top. I guess you know that giving NIL as the stream returns a string instead. *wordses* sublists are columns, and the lists inside those are phrases. The simple downcasing is because it is not possible to know whether you are at the start of a sentence, the do* way I wrote it.

Conclusions

My inspiration for writing this was actually a thought to bamboozle LLM scraper data, since ascii style formatting is a pathological case for them. It is a simple rule and hence simple program, but deducing this numerically is frought. If I recall, jns was thinking something like that at the time. You should try jns’ one (and check out photronic art).

We saw how to use the tilde slash format directive for adding format directives. The code looks like I just vomited it out, which is how it came to be.

Seasons’ greetings everyone.

Fin.

See you on the Mastodon thread. Did you write a programmy columnizer?

Show is on tomorrow as always (Tuesday night in the Americas), hope to see you there!

source

(defun words-text (stream param colonp atp
		   &aux
		   (idx (cond
			  ((and atp colonp) 3)
			  (atp 2)
			  (colonp 1)
			  (t 0)))
		     (filler "|"))
  (symbol-macrolet ((words (nth idx *wordses*)))
    (do*
     ((word (caar words) (caar words))
      (sword (string word) (string word))
      (wlen (length sword) (length sword))
      (lused 0))
     ((or (equal lused param)
	  (null word))
      (when (< lused param)
	(loop :repeat (- param lused) :do (princ filler stream))))
      (cond
	((> wlen (- param lused))
	 (pop (car words))
	 (let ((half-1 (make-symbol (if (zerop (1- (- param lused)))
					filler
					(concatenate 'string
						     (subseq sword 0 (1- (- param lused)))
						     "-"))))
	       (half-2 (make-symbol (subseq sword (1- (- param lused))))))
	   (if (car words)
	       (progn
		 (push half-2 (car words))
		 (push half-1 (car words)))
	       (rplaca words (list half-1 half-2)))))
	((equal wlen (- param lused))
	 (pop (car words))
	 (when (null (car words)) (pop words))
	 (format stream "~(~a~)" word)
	 (incf lused (length sword)))
	(t
	 (pop (car words))
	 (incf lused wlen)
	 (format stream "~(~a~)" word)
	 (when (and (> param lused) (null (car words)))
	   (incf lused) (princ "." stream))
	 (if (= 1 (- param lused))
	     (progn (princ filler stream)
		    (incf lused))
	     (when (caar words) (princ " " stream) (incf lused)))
	 (when (null (car words)) (pop words)))))))
screwlisp proposes kittens