Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
;; This file:
;;   http://anggtwu.net/LISP/2025-rectangle.lisp.html
;;   http://anggtwu.net/LISP/2025-rectangle.lisp
;;          (find-angg "LISP/2025-rectangle.lisp")
;; Author: Eduardo Ochs <eduardoochs@gmail.com>
;;
;; An example:
;;
;;   (%i1) load("2025-rectangle.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")
;; «.my-rectangle»		(to "my-rectangle")
;; «.my-rectangle-tests»	(to "my-rectangle-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 "2025-rectangle.lisp")
(myconcat '("a" "bc" "def"))
(myconcat '("a" "bc" "def") "_")

|#


;; «my-rectangle»  (to ".my-rectangle")
;; See: (find-es "lisp" "defclass")
(defclass my-rectangle ()
  ((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 my-rectangle) &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-my-rectangle (&rest args)
  (let ((rect (apply 'make-instance 'my-rectangle args)))
    (initialize-array rect)
    rect))

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

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

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

(defmethod get-line-as-string ((rect my-rectangle) 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 my-rectangle))
  (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 my-rectangle) &optional indent)
  (myconcat (get-lines-as-strings rect)
		(format nil "~%~a" (or indent " "))))

(defmethod draw-axes ((rect my-rectangle))
  (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 my-rectangle) x y)
  (set-cell rect x y (+ (* 10 x) y)))

(defmethod set-cells-with-10x+y ((rect my-rectangle))
  (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)))))

#|
** «my-rectangle-tests»  (to ".my-rectangle-tests")
* (eepitch-sbcl)
* (eepitch-kill)
* (eepitch-sbcl)
(load "2025-rectangle.lisp")

(defvar myr)
(setq myr (make-my-rectangle :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-my-rectangle :maxx 4 :maxy 3))
(get-lines-as-strings myr)
(draw-axes myr)
(get-lines-as-bigstring myr)

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

(setq myr (make-instance 'my-rectangle :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("2025-rectangle.lisp");
M1 : barematrix([a,b],[c,d]);
M2 : matrix([M1,e],[f,g]);

|#



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

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

(defun $my_rect_dimensions (minx miny maxx maxy)
  (setq my-rect (make-instance 'my-rectangle
			       :minx minx :miny miny :maxx maxx :maxy maxy))
  (initialize-array my-rect)
  (draw-axes my-rect)
  ($my_rect))

(defun $my_rect_set (x y &optional (elt "o"))
  (set-cell my-rect x y elt)
  ($my_rect))

#|
** «maxima-tests»  (to ".maxima-tests")
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("2025-rectangle.lisp")$
my_rect_dimensions(-4,0, 4,4);
makelist(my_rect_set(x,x^2), x,-2,2)$
my_rect();

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

|#









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