[Top][All Lists]

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

Re: Replace element in list

From: Andreas Röhler
Subject: Re: Replace element in list
Date: Mon, 2 Sep 2019 16:00:30 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

Am 02.09.19 um 15:43 schrieb
On Mon, Sep 02, 2019 at 09:29:39AM -0400, Stefan Monnier wrote:
is there a recommended way to replace element x at index i of somelist
y by newelement?
What Thomas is hinting at with his "copy-list" and "functional sector"
is that if you need to do that, there's a problem upstream.
E.g. could you use a struct instead of a list?
Thanks for putting my mumbling into civilised words :-)

-- t

Hmm, what means struct here?

Tried a little program to answer a quiz in

;; If the head is in state A at the position shown below, what would the final output of this Turing machine be?

;; |0|0|0|0|1|1|0|0|0|
;;                ^

Started that way:

[leaving out here z_B - z_E]

(defun z_A (zeichen pos)

  ;; Char: 1 (49, #o61, #x31)
  (when (eq 49 (aref zeichen pos))
    (aset zeichen pos 48)
    (z_B zeichen (1- pos))))

(defun zeichenmachine ()
  (let ((zeichen "000011000")
    (pos 5))
    (message "%s" zeichen)
    (z_A zeichen pos)))

But that was easier to read:

[leaving out here state_B - state_E]

(defun state_A (elist pos)
  (if (eq 1 (nth pos elist))
    (setf (nth pos elist) 0)
    (state_B elist (1- pos)))
    (message "Fertig %s" elist)))

(defun statemachine ()
  (let ((elist (list 0 0 0 0 1 1 0 0 0))
    (pos 5))
    (state_A elist pos)))

reply via email to

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