unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: <tomas@tuxteam.de>
To: help-gnu-emacs@gnu.org
Subject: Re: Lisp Live buffer
Date: Wed, 28 Dec 2022 10:25:24 +0100	[thread overview]
Message-ID: <Y6wLhGQo6kn1J0LN@tuxteam.de> (raw)
In-Reply-To: <878rismkp7.fsf@dataswamp.org>

[-- Attachment #1: Type: text/plain, Size: 1154 bytes --]

On Wed, Dec 28, 2022 at 01:32:52AM +0100, Emanuel Berg wrote:
> Why doesn't this work?
> 
> For sure, there is a mistake somewhere but it seems now matter how
> I change it I get the same result ...
> 
> ;;; -*- 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 (zerop dim)
>       init
>     (make-list len (make-world (1- dim) len init)) ))

Heh. When you are making a higher-order world, you are
storing a ref to the same list in each of its slots.
So if you change something at a lower level *poof*
all are changed. Read the subsection "samenes and change"
in 3.1 of SICP [1] for a beautiful treatment (actually,
re-read SICP: a beautiful book)

Oh, I nearly forgot: if you want it to work, you'll
have to regenerate the lower-level worlds (or deep
copy them).

Cheers

[1] https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/6515/sicp.zip/full-text/book/book-Z-H-20.html
    (Sorry: fragment links seem to be disfunctional)
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

  parent reply	other threads:[~2022-12-28  9:25 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
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 [this message]
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=Y6wLhGQo6kn1J0LN@tuxteam.de \
    --to=tomas@tuxteam.de \
    --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).