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

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

Re: Lisp Live buffer


From: tomas
Subject: Re: Lisp Live buffer
Date: Wed, 28 Dec 2022 10:25:24 +0100

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: signature.asc
Description: PGP signature


reply via email to

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