unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
To: help-gnu-emacs@gnu.org
Subject: Re: Replace element in list
Date: Mon, 2 Sep 2019 16:00:30 +0200	[thread overview]
Message-ID: <fe022e54-9c09-60a9-af05-95e2be169e9a@easy-emacs.de> (raw)
In-Reply-To: <20190902134342.GG1466@tuxteam.de>


Am 02.09.19 um 15:43 schrieb tomas@tuxteam.de:
> 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 :-)
>
> Cheers
> -- t


Hmm, what means struct here?

Tried a little program to answer a quiz in

https://www.futurelearn.com/courses/how-computers-work/4/steps/551852/questions/3:

;; 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 ()
   (interactive)
   (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))
       (progn
     (setf (nth pos elist) 0)
     (state_B elist (1- pos)))
     (message "Fertig %s" elist)))

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





  reply	other threads:[~2019-09-02 14:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-02  9:44 Replace element in list Andreas Röhler
2019-09-02 10:37 ` tomas
2019-09-02 10:41   ` tomas
2019-09-02 10:46     ` tomas
2019-09-02 11:03       ` Michael Heerdegen
2019-09-02 11:05         ` tomas
2019-09-02 13:38           ` Andreas Röhler
2019-09-02 13:29 ` Stefan Monnier
2019-09-02 13:43   ` tomas
2019-09-02 14:00     ` Andreas Röhler [this message]
2019-09-02 14:57       ` Stefan Monnier
2019-09-02 20:29         ` Andreas Röhler
2019-09-02 21:32           ` Stefan Monnier
2019-09-03  5:37             ` Andreas Röhler
  -- strict thread matches above, loose matches on Subject: below --
2018-11-22  4:42 replace " edgar
2018-11-22  5:18 ` Eric Abrahamsen
2018-11-22  5:39   ` Drew Adams
2018-11-22  6:04     ` Eric Abrahamsen
2018-11-22 13:19 ` Stefan Monnier
     [not found] ` <mailman.4442.1542892802.1284.help-gnu-emacs@gnu.org>
2018-11-23 12:05   ` Robert Munyer
2018-11-24  3:01 ` edgar
2018-11-24  5:27   ` Drew Adams
2018-11-24  7:22     ` edgar

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=fe022e54-9c09-60a9-af05-95e2be169e9a@easy-emacs.de \
    --to=andreas.roehler@easy-emacs.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).