From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.help Subject: Re: Setting variables, argumunts in defun Date: Sat, 13 Feb 2021 17:42:12 +0100 Message-ID: <87blcnq5qz.fsf@posteo.net> References: Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3342"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cc: Help Gnu Emacs , wael-zwaiter@gmx.com To: Christopher Dimech Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Feb 13 17:43:44 2021 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 1lAy1I-0000nJ-JK for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 13 Feb 2021 17:43:44 +0100 Original-Received: from localhost ([::1]:47586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lAy1H-0007ML-Me for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 13 Feb 2021 11:43:43 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57670) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lAxzy-0006cz-Gd for help-gnu-emacs@gnu.org; Sat, 13 Feb 2021 11:42:23 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]:33763) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lAxzt-0001A5-LV for help-gnu-emacs@gnu.org; Sat, 13 Feb 2021 11:42:20 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 40B182400FD for ; Sat, 13 Feb 2021 17:42:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1613234534; bh=hKyrvB0fk9O4xp34j6i+O0kky+kOq4Oa2qKMC0bvHxE=; h=From:To:Cc:Subject:Date:From; b=d0y9npceJCxPsQSBRWZyCwNn/X1yghZcNsVvc9aGb9EWwrTxjryc0XldRQbzOSGQE CdWtDWl/2eHzZgqlGsIn8LMDnC9V+q8nSybVfh32wE76vvq4eUkKLg8+Q9BRHp8XR5 ERMVmC0BGrPUVa+zA1sattNak8nwdqYsvxe/6KcNiZD6oLYkHtSOFdudq5n3cr3/em NqasuR0r4x1GUA75CJi43OE4Dgguo51T+GPdz2qpCdbYbUOgQEvcQR2mznhkGyiint w5qe1UNOmP3LoKLEyeE4JIggOFnNqcmClwcANzwvGxiUh5GBTUuJy1OIpJsvsOaNPp yLsiWRkpm6f0g== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4DdGP14hGBz9rxN; Sat, 13 Feb 2021 17:42:13 +0100 (CET) In-Reply-To: (Christopher Dimech's message of "Sat, 13 Feb 2021 17:33:21 +0100") Received-SPF: pass client-ip=185.67.36.66; envelope-from=philipk@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.io gmane.emacs.help:127960 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Christopher Dimech writes: > I am trying to use pcase on a string, but do need some direction > on how to use it. Pcase is usually used like this (pcase objv ("enable" (setq devi 0.18) (setq scal 0.2)) ("disable" (setq devi 0.18) (setq scal 1.0))) the first element it the expression that the execution depends on, and every possible branch starts with a case. What you are doing looks more like a cond-expression: (cond ((string-equal objv "enable") (setq devi 0.18) (setq scal 0.2)) ((string-equal objv "disable") (setq devi 0.18) (setq scal 1.0))) That being said, it's probably better to use a symbol ('enable and 'disable) or a boolean value write this. Exploiting the fact that setq can assign multiple variables at one, you could also write (if (eq objv 'enable) (setq devi 0.18 scal 0.2) (setq devi 0.18 scal 1.0)) though depending on what you are doing, it might be better to avoid setting global variables in the first place. > (pcase (string-match "enable" objv) > ( > (setq devi 0.18) > (setq scal 0.2) ) > > ( (string-match "disable" objv) > (setq devi 0.0) > (setq scal 1.0) ) > > ) > > >> Sent: Sunday, February 14, 2021 at 4:14 AM >> From: wael-zwaiter@gmx.com >> To: "Help Gnu Emacs" >> Subject: Setting variables, argumunts in defun >> >> I would like to set up devi and scal by selecting either one or >> the other. Wow can I do this in elisp. Should I pass parameters >> to the function. Can one pass a string, then check its contents? >> >> (defun deviscal () >> >> (setq devi 0.18) >> (setq scal 0.2) >> >> (setq devi 0.0) >> (setq scal 1.0) ) >> >> >> >> >> > > =2D-=20 Philip K. --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQHHBAEBCAAxFiEEbW+YL3e0aNnYosjIGB9bla4wszYFAmAoAWQTHHBoaWxpcGtA cG9zdGVvLm5ldAAKCRAYH1uVrjCzNsgMDADDKWwWa1h0Lwb3e6Fji4V2FnHhEEqV UkH+rc4gxmn4/hMavj4+hS2VMHwI0Vis9tcBaErr3tTyfGJZmv0zkICxCh1nIS39 IJib+GUHHOUVmouMl0ZpwfucS1oBqchCSIitg+hNbw4qeOoHtRAKrM3CcPrpEKdh pKAboga/aq01FCJRVBdneavWqbP4dCjFxjSdMspLwfrAOGD0r/uIDwJeVoOPo6aP 5cUbphpvOBoT3Jd79aAlllCw42hvk+9AkDaeSVwn3F/oTPt5X5jZvr3808H07+Ns UdXOzz7JbrtEckY04dC/jM/vB1BBV3GoMr7unLifbSxtC7lphDarbZgr9jiK40tq 8tFCyVH5wrXoiQUbnMPtwK8iL989mZj6hyo1R1YZvzYbCWHwxmIQuGkyMcDH4MGr fxOwFdE46uWvdWeVOQwc7X4647nUW3EamXBGNkP7AyoQTqUmAyzuNzHYuzKJsvp9 cMFUlPjurvzWCLah4j4Mz3myyezwPGYZBAg= =yGZl -----END PGP SIGNATURE----- --=-=-=--