help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Lisp Live buffer


From: Emanuel Berg
Subject: Re: Lisp Live buffer
Date: Wed, 28 Dec 2022 20:53:22 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

tomas wrote:

> all are changed

No kidding!

It was a misunderstanding of `make-list' - in actuality,
a built-in/C _function_, so not a macro, i.e. the argument
INIT is evaluated and just once so - but I got it to work now:

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/mvc/model.el

(require 'cl-lib)

(defun make-world (dim len &optional init)
  (or init (setq init "."))
  (if (= 1 dim)
      (make-list len init)
    (let ((wrld '()))
      (dotimes (_ len)
        (push (make-world (1- dim) len init) wrld) )
      wrld) ))

;; (make-world 1 1)
;; (make-world 1 2)
;; (make-world 2 3)

(defun world-size (world)
  (length (flatten-list world)) )

(defun make-world-test ()
  (let ((tests (list (list "cell"  (make-world 1 1)  1)
                     (list "chess" (make-world 2 8) 64)
                     (list "cube"  (make-world 3 3) 27) )))
    (cl-loop
      for (name world expected) in tests
      and num-tests from 0 do
        (let ((size (world-size world)))
          (unless (= size expected)
            (error "World %s has size %s, expected %s" name size expected) ))
      finally return (= num-tests (length tests)) )))

;; (make-world-test)

(defun world-set (world pos to)
  (if (= 1 (length pos))
      (setf (nth (car pos) world) to)
    (world-set (nth (car pos) world) (cdr pos) to) ))

(defun world-set-test ()
  (let ((ttt (make-world 2 3)))
    (world-set ttt '(1 2) "o")
    ttt) )

;; (world-set-test)
;;     0   1   2
;; ( ("." "." ".")   0
;;   ("." "." "o")   1
;;   ("." "." ".") ) 2

(provide 'model)

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]