From: uzibalqa <uzibalqa@proton.me>
To: Drew Adams <drew.adams@oracle.com>
Cc: uzibalqa via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org>
Subject: RE: [External] : Swapping characters in a word inside elisp code
Date: Fri, 28 Jul 2023 20:48:42 +0000 [thread overview]
Message-ID: <YDeE8TsPV3We2SuGSbVpvXc9-D5GkdUvfNhxVf4sEz2V72mLfbA00k67BrCCXq30JBXHLb_B5d3kyIMU0tr4UxMaKEBXptoeFFrTSiWo8i8=@proton.me> (raw)
In-Reply-To: <Fa4y2GzUvqSJYsLTj8cESWic__zjL3W1ZsXsV3KJo4e0JichEVCYVvtilABHgwiAPXA-51tRrRwfWPzRGJxe2xGmisulzlKX8bvvEfaDKO0=@proton.me>
------- Original Message -------
On Saturday, July 29th, 2023 at 8:45 AM, uzibalqa <uzibalqa@proton.me> wrote:
> ------- Original Message -------
> On Saturday, July 29th, 2023 at 8:32 AM, Drew Adams drew.adams@oracle.com wrote:
>
>
>
> > > I have a word and want to swap characters at position i with position j.
> > >
> > > What would be a good way to do this ? Would I need to change structure
> > > (to array, vector or some other thing) ?
> >
> > (Homework?)
> >
> > Depends what you mean by swap chars in a word.
> > And whether your word is represented by a string,
> > a vector, a list... And how you want the result:
> > in a separate string, vector,... or in the same
> > one, modified.
>
>
> I have a word and want to generate permutations of it.
> And I need the ability to swap two characters at positions
> i and j in word.
>
> Just a toy project that does scrabble.
>
> > (Again, you don't make clear what you want.)
> >
> > Here's one way to swap chars in a string
> > destructively:
> >
> > (defun cswap (string p q)
> > "Swap chars in STRING at positions P and Q.
> > This is a destructive operation."
> > (aset string p (prog1 (aref string q)
> > (aset string q (aref string p))))
> > string)
I had made a function to do it but the changes were local (temporary)
because I was using setq.
> > (setq s1 "123456789")
> > (cswap s1 3 5) ; s1 = "123654789"
> > ; ^ ^
> >
> > `prog1' is often used to swap things.
> > A more typical use is swapping values
> > of two variables:
> >
> > (setq start (prog1 end (setq end start)))
prev parent reply other threads:[~2023-07-28 20:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-28 18:03 Swapping characters in a word inside elisp code uzibalqa
2023-07-28 19:44 ` uzibalqa
2023-07-28 20:45 ` Marcin Borkowski
2023-07-28 20:32 ` [External] : " Drew Adams
2023-07-28 20:45 ` uzibalqa
2023-07-28 20:48 ` uzibalqa [this message]
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='YDeE8TsPV3We2SuGSbVpvXc9-D5GkdUvfNhxVf4sEz2V72mLfbA00k67BrCCXq30JBXHLb_B5d3kyIMU0tr4UxMaKEBXptoeFFrTSiWo8i8=@proton.me' \
--to=uzibalqa@proton.me \
--cc=drew.adams@oracle.com \
--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).