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

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

Re: List not getting filled up


From: Yuri Khan
Subject: Re: List not getting filled up
Date: Mon, 31 Jul 2023 15:55:12 +0700

On Mon, 31 Jul 2023 at 07:06, uzibalqa <uzibalqa@proton.me> wrote:

> Have done a non-destructive swap-chars which I use directly as follows
>
> (setq result
>           (permute (swap-chars string i j) (1+ i) length result))
>
> >  Hint 2: your second
> > ‘swap-chars’ call is only there to undo the modification made by the
> > first call, so it could be avoided by introducing a local variable to
> > hold the result of the modification.)
>
> For your second hint, I am unsure what to store.  Would I store the original
> string passed as an argument to the function as follows.  Then what would I
> do with copy of the string that war not swapped ?

If you pass the return value of ‘swap-chars’ directly into ‘permute’,
nothing additional is needed. You could alternatively use

    (let ((swapped (swap-chars string i j)))
      (setq result (permute swapped (1+ i) length result)))

in case you find that easier to read.



reply via email to

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