unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Emanuel Berg <incal@dataswamp.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Lisp Live buffer
Date: Mon, 26 Dec 2022 21:26:12 +0100	[thread overview]
Message-ID: <87bknpgbdn.fsf@dataswamp.org> (raw)
In-Reply-To: Y6VjlJStJwFRfCeC@protected.localdomain

> (setq ttt-board
>   (list
>     '(x o o)
>     '(· x ·)
>     '(· · x) ))

I have tried to do a MVC Elisp demo but the function 'world-set' is
incorrect, I still didn't get past that step. See below, it's line
32-38. The result is visible in the test function and it's
output, last.

What is needed is essentially a multidimensional array and then
getters and setters (based on indexes or coordinates) to operate
on that.

Ideas?

;;; -*- 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 (= dim 1)
      (make-list len init)
    (make-list len (make-world (1- dim) len init)) ))

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

(defun make-world-test ()
  (let ((tests (list (list "cell"  (make-world 1 1)  1)
                     (list "ttt"   (make-world 2 3)  9)
                     (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))
      (setcar (nthcdr (car pos) world) to)
    (setcar
      (nthcdr (car pos) world)
      (world-set (car (nthcdr (car pos) world)) (cdr pos) to) ))
  world)

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

;; (world-set-test) ; (("." "a" ".") ("." "a" ".") ("." "a" "."))

(provide 'model)

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




  reply	other threads:[~2022-12-26 20:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-06 15:44 Lisp Live buffer Emanuel Berg
2022-12-07  3:06 ` Jean Louis
2022-12-07  3:54   ` Emanuel Berg
2022-12-23  8:15     ` Jean Louis
2022-12-26 20:26       ` Emanuel Berg [this message]
2022-12-27  1:12         ` Emanuel Berg
2022-12-28  0:32           ` Emanuel Berg
2022-12-28  2:04             ` Emanuel Berg
2022-12-28  2:08             ` Emanuel Berg
2022-12-28  9:25             ` tomas
2022-12-28 19:53               ` Emanuel Berg
2022-12-28 23:20               ` Emanuel Berg
2022-12-08 11:32 ` Madhu
2022-12-23  8:23   ` Jean Louis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bknpgbdn.fsf@dataswamp.org \
    --to=incal@dataswamp.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).