Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
;; This file:
;;   http://anggtwu.net/MAXIMA/ascii-rect.lisp.html
;;   http://anggtwu.net/MAXIMA/ascii-rect.lisp
;;          (find-angg "MAXIMA/ascii-rect.lisp")
;; Author: Eduardo Ochs <eduardoochs@gmail.com>
;; Supersedes: (find-angg "LISP/2025-rectangle.lisp")
;;
;; (defun e () (interactive) (find-angg "MAXIMA/ascii-rect.lisp"))
;;
;; An example:
;;
;;   (%i1) load("ascii-rect.lisp")$
;;   (%i2) my_rect_dimensions(-4,0, 4,4);
;;                                          |    
;;                                          |    
;;   (%o2)                                  |    
;;                                          |    
;;                                      ----+----
;;   (%i3) makelist(my_rect_set(x,x^2), x,-2,2)$
;;   (%i4) my_rect();
;;                                        o | o  
;;                                          |    
;;   (%o4)                                  |    
;;                                         o|o   
;;                                      ----o----
;;   (%i5) 
;;
;; «.myconcat»			(to "myconcat")
;; «.myconcat-tests»		(to "myconcat-tests")
;; «.ascii-rect»		(to "ascii-rect")
;; «.ascii-rect-tests»	(to "ascii-rect-tests")
;; «.barematrix»		(to "barematrix")
;; «.barematrix-tests»		(to "barematrix-tests")
;; «.maxima»			(to "maxima")
;; «.maxima-tests»		(to "maxima-tests")


;; «myconcat»  (to ".myconcat")
;; From: (find-es "lisp" "mapconcat")
(defun myconcat (strings &optional (sep ""))
  (let* ((firststring  (car strings))
	 (otherstrings (cdr strings))
         (pairs        (loop for string in otherstrings
                             collect sep
                             collect string))
         (items (cons firststring pairs)))
    (apply 'concatenate 'string items)))

(defun mapconcat (f list sep)
  (myconcat (map 'list f list) sep))

#|
** «myconcat-tests»  (to ".myconcat-tests")
* (eepitch-sbcl)
* (eepitch-kill)
* (eepitch-sbcl)
(load "ascii-rect.lisp")
(myconcat '("a" "bc" "def"))
(myconcat '("a" "bc" "def") "_")

|#


;; «ascii-rect»  (to ".ascii-rect")
;; See: (find-es "lisp" "defclass")
(defclass ascii-rect ()
  ((minx  :initarg :minx :initform 0)
   (miny  :initarg :miny :initform 0)
   (maxx  :initarg :maxx)
   (maxy  :initarg :maxy)
   (fmt   :initarg :fmt :initform "~a")
   (array)))

(defmethod initialize-array ((rect ascii-rect) &optional (elt " "))
  (with-slots (minx maxx miny maxy array) rect
    (setq array (make-array
		 (list (1+ (- maxy minx)) (1+ (- maxx minx)))
		 :initial-element elt))))

(defun make-ascii-rect (&rest args)
  (let ((rect (apply 'make-instance 'ascii-rect args)))
    (initialize-array rect)
    rect))

(defmethod set-cell ((rect ascii-rect) x y newvalue)
  (with-slots (array minx miny) rect
    (setf (aref array (- y miny) (- x minx)) newvalue)))

(defmethod get-cell ((rect ascii-rect) x y)
  (with-slots (array minx miny) rect
    (aref array (- y miny) (- x minx))))

(defmethod get-cell-as-string ((rect ascii-rect) x y)
  (with-slots (fmt) rect
    (format nil fmt (get-cell rect x y))))

(defmethod get-line-as-string ((rect ascii-rect) y)
  (with-slots (minx maxx fmt) rect
    (myconcat (loop for x from minx to maxx
		    collect (get-cell-as-string rect x y)))))

(defmethod get-lines-as-strings ((rect ascii-rect))
  (with-slots (miny maxy) rect
    (loop for y from maxy downto miny
	  collect (get-line-as-string rect y))))

(defmethod get-lines-as-bigstring ((rect ascii-rect) &optional indent)
  (myconcat (get-lines-as-strings rect)
		(format nil "~%~a" (or indent " "))))

(defmethod draw-axes ((rect ascii-rect))
  (with-slots (minx miny maxx maxy) rect
    (loop for x from minx to maxx
	  do (set-cell rect x 0 "-"))
    (loop for y from miny to maxy
	  do (set-cell rect 0 y "|"))
    (set-cell rect 0 0 "+"))
  rect)

(defmethod set-cell-with-10x+y ((rect ascii-rect) x y)
  (set-cell rect x y (+ (* 10 x) y)))

(defmethod set-cells-with-10x+y ((rect ascii-rect))
  (with-slots (minx miny maxx maxy array) rect
    (loop for y from miny to maxy
	  do (loop for x from minx to maxx
		   do (set-cell-with-10x+y rect x y)))))

#|
** «ascii-rect-tests»  (to ".ascii-rect-tests")
* (eepitch-sbcl)
* (eepitch-kill)
* (eepitch-sbcl)
(load "ascii-rect.lisp")

(defvar myr)
(setq myr (make-ascii-rect :maxx 4 :maxy 3 :fmt "~2a"))

myr
(describe myr)
(set-cell-with-10x+y myr 2 3)
(set-cells-with-10x+y myr)
(describe myr)
(get-cell-as-string myr 0 0)
(get-line-as-string myr 0)
(get-line-as-string myr 1)
(get-lines-as-strings myr)
(get-lines-as-bigstring myr)
(get-lines-as-bigstring myr " ")
(get-lines-as-bigstring myr ":")
(get-lines-as-bigstring myr "")

(setq myr (make-ascii-rect :maxx 4 :maxy 3))
(get-lines-as-strings myr)
(draw-axes myr)
(get-lines-as-bigstring myr)

;; (defmethod print-object ((rect ascii-rect) stream)
;;   (format stream "~s" (get-lines-as-bigstring rect)))

(setq myr (make-ascii-rect :minx -2 :maxx 4 :miny -1 :maxy 3))
(initialize-array myr)
(get-lines-as-strings myr)
(draw-axes myr)
(get-lines-as-bigstring myr)

|#


;; «barematrix»  (to ".barematrix")
;; Taken from: (find-angg "MAXIMA/2025-displa-tex.lisp")
(when (find-package "MAXIMA")
  ;;
  (setf (get '$barematrix 'dimension) 'dim-$barematrix)
  ;;
  (defun dim-$barematrix (form result)
    (let (($display_matrix_brackets nil))
      (dim-$matrix form result)))
  ;;
  )

#|
** «barematrix-tests»  (to ".barematrix-tests")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("ascii-rect.lisp");
M1 : barematrix([a,b],[c,d]);
M2 : matrix([M1,e],[f,g]);

|#


;; «maxima»  (to ".maxima")
(defvar ascii-rect)

(defun $ascii_rect ()
  (cons '($barematrix simp)
	(loop for line in (get-lines-as-strings ascii-rect)
	      collect `((mlist simp) ,line))))

(defun $ascii_rect_dimensions (minx miny maxx maxy)
  (setq ascii-rect (make-ascii-rect
		    :minx minx :miny miny :maxx maxx :maxy maxy))
  (initialize-array ascii-rect)
  (draw-axes ascii-rect)
  ($ascii_rect))

(defun $ascii_rect_set (x y &optional (elt "o"))
  (set-cell ascii-rect x y elt)
  ($ascii_rect))

#|
** «maxima-tests»  (to ".maxima-tests")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("ascii-rect.lisp")$
ascii_rect_dimensions(-4,0, 4,4);
makelist(ascii_rect_set(x,x^2), x,-2,2)$
ascii_rect();

* (eepitch-sbcl)
* (eepitch-kill)
* (eepitch-sbcl)
(load "ascii-rect.lisp")
(defvar myr)
(setq myr (make-ascii-rect :minx -2 :maxx 4 :miny -1 :maxy 3))
(draw-axes myr)
(get-lines-as-bigstring myr)

|#



;; Local Variables:
;; coding:  utf-8-unix
;; End: