From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: uzibalqa Newsgroups: gmane.emacs.help Subject: RE: [External] : Swapping characters in a word inside elisp code Date: Fri, 28 Jul 2023 20:45:33 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28389"; mail-complaints-to="usenet@ciao.gmane.io" Cc: uzibalqa via Users list for the GNU Emacs text editor To: Drew Adams Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jul 28 22:50:51 2023 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qPUQE-000787-CG for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 28 Jul 2023 22:50:50 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qPULH-00089s-Hw; Fri, 28 Jul 2023 16:45:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qPULG-00089g-GO for help-gnu-emacs@gnu.org; Fri, 28 Jul 2023 16:45:42 -0400 Original-Received: from mail-40132.protonmail.ch ([185.70.40.132]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qPULE-0006e5-Jm for help-gnu-emacs@gnu.org; Fri, 28 Jul 2023 16:45:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=3q6erqyo2zehhkj56v3rg74qma.protonmail; t=1690577137; x=1690836337; bh=ZhGzMWYT+FXEPS9q/z63YRETrNrmWzJkRaYYpm7Zbw0=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=VQmeEUeakXe0w8Cefc1ln8eRmDmu+Ll/dCOq6TmC3RN16zZEEohCsx0GCp9ACfPX8 vbZyPFOQ8UiyUPHU9E6tQuY2iFxXLPZ95FyD/k98qhGAoG/IdR5rxqRZOXAJp0NBnR FRLAXgLD/8vkGzNfSgELHL7WRbeEONQlMlmNkDJYyXFbovvrEYbTvCS/8NbOZeE5oy t6POsLhWF/UZbLoXiE47D0qW0ouxpeqDKU86kOxP/CYgoapFs1GKBEwDEANxhqF+FB 7379yVmT1YfRV/5waaY9l5S3wFr/am6vpdPlbBfGxwQhu5SH6Bv86VROms+uv7JvGm YcGIZzL9HHtBg== In-Reply-To: Feedback-ID: 52887082:user:proton Received-SPF: pass client-ip=185.70.40.132; envelope-from=uzibalqa@proton.me; helo=mail-40132.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:144488 Archived-At: ------- Original Message ------- On Saturday, July 29th, 2023 at 8:32 AM, Drew Adams = wrote: > > I have a word and want to swap characters at position i with position j= . > >=20 > > What would be a good way to do this ? Would I need to change structure > > (to array, vector or some other thing) ? >=20 >=20 > (Homework?) >=20 > 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. =20 > (Again, you don't make clear what you want.) >=20 > Here's one way to swap chars in a string > destructively: >=20 > (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) >=20 > (setq s1 "123456789") > (cswap s1 3 5) ; s1 =3D "123654789" > ; ^ ^ >=20 > `prog1' is often used to swap things. > A more typical use is swapping values > of two variables: >=20 > (setq start (prog1 end (setq end start)))