|
From: Eduardo O. <edu...@gm...> - 2025-10-21 20:28:54
|
Hi list,
long story very short: the code below produces this,
(%i4) VB1 : verbatimbox("ab", "cdef", "g");
(%o4) ab
cdef
g
but it has some bugs.
Here's how to test it. Save the code below to
/tmp/verbatimbox.lisp,
--snip--snip--
(defclass verbatimbox ()
((result :initarg :result :initform nil)
(lastwidth :initarg :lastwidth :initform nil)
(maxwidth :initarg :maxwidth :initform nil)
(depth :initarg :depth :initform nil)))
(defun make-verbatimbox-from-string (str)
(let* ((chars (exploden str))
(width (length chars)))
(make-instance 'verbatimbox
:maxwidth width
:lastwidth width
:depth 0
:result (reverse chars))))
(defmethod verbatimbox-add-line-at-bottom ((vb verbatimbox) str)
(with-slots (result lastwidth maxwidth (dp depth)) vb
(let* ((chars (exploden str))
(width (length chars)))
(setq dp (1+ dp))
(setq result `((,(- lastwidth) ,(- dp) ,@(reverse chars)) ,@result))
(setq lastwidth width)
(setq maxwidth (max maxwidth width))
vb)))
(defun make-verbatimbox-from-strings (strs)
(let ((vb (make-verbatimbox-from-string (car strs))))
(loop for str in (cdr strs)
do (verbatimbox-add-line-at-bottom vb str))
vb))
(defmethod verbatimbox-setqs ((vb verbatimbox))
(with-slots (lastwidth maxwidth (dp depth)) vb
`(setq depth ,dp
maxdp ,dp
width ,maxwidth)))
(defmethod verbatimbox-result ((vb verbatimbox))
(with-slots (result) vb result))
(defun dim-verbatimbox (form result)
(let* ((strings (cdr form))
(vb (make-verbatimbox-from-strings strings))
(setqs (verbatimbox-setqs vb))
(vbresult (verbatimbox-result vb)))
(eval setqs)
(append vbresult result)))
(setf (get '$verbatimbox 'dimension) 'dim-verbatimbox)
--snip--snip--
...and then run either one, or both, of these blocks in a Maxima REPL:
--snip--snip--
load("/tmp/verbatimbox.lisp");
display2d_unicode : false;
linel : 50;
VB : verbatimbox("ab", "cdef", "g");
M : matrix([VB]);
matrix([2, VB, 3]);
matrix([2, M, 3]);
to_lisp();
(load "/tmp/verbatimbox.lisp")
(defvar myvb)
(setq myvb (make-verbatimbox-from-strings '("ab" "cdef" "g")))
(describe myvb)
(verbatimbox-setqs myvb)
(verbatimbox-result myvb)
(to-maxima)
--snip--snip--
Here are the relevant parts of their outputs:
(%i4) VB : verbatimbox("ab", "cdef", "g");
(%o4) ab
cdef
g
(%i5) M : matrix([VB]);
[ ab]
(%o5) [ cdef]
[ g ]
(%i6) matrix([2, VB, 3]);
[ 2 ab 3 ]
(%o6) [ cdef ]
[ g ]
(%i7) matrix([2, M, 3]);
[ [ ab] ]
(%o7) [ 2 [ cdef] 3 ]
[ [ g ] ]
(%i8)
MAXIMA> (describe myvb)
Slots with :INSTANCE allocation:
RESULT = ((-4 -2 #\g) (-2 -1 #\f #\e #\d #\c) #\b #\a)
LASTWIDTH = 1
MAXWIDTH = 4
DEPTH = 2
MAXIMA> (verbatimbox-setqs myvb)
(SETQ DEPTH 2
MAXDP 2
WIDTH 4)
It seems that doing "(setq width 4)" is not enough...
Suggestions, please?
Cheers,
Eduardo...
http://anggtwu.net/eev-maxima.html
P.S.: this is related to these two posts, that I sent
to the list a few hours ago...
https://sourceforge.net/p/maxima/mailman/message/59249515/
https://sourceforge.net/p/maxima/mailman/message/59249497/
|