From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Manuel Giraud Newsgroups: gmane.emacs.help Subject: Re: Elisp function that performs numeric computations Date: Wed, 19 Jan 2022 11:24:00 +0100 Message-ID: <87sftk6n27.fsf@elite.giraud> 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="7313"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (berkeley-unix) Cc: Fatiparty To: fatiparty--- via Users list for the GNU Emacs text editor Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jan 19 11:47:50 2022 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 1nA8VK-0001hV-2z for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 19 Jan 2022 11:47:50 +0100 Original-Received: from localhost ([::1]:53732 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nA8VI-0000Ze-TI for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 19 Jan 2022 05:47:48 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:60250) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nA88O-0006Gg-My for help-gnu-emacs@gnu.org; Wed, 19 Jan 2022 05:24:10 -0500 Original-Received: from ledu-giraud.fr ([51.159.28.247]:11742) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nA88M-00082q-5s for help-gnu-emacs@gnu.org; Wed, 19 Jan 2022 05:24:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=vScIsyMc4GR/2ANv ahmigBxZvuc2dW2jz9EL3LAaMzk=; h=in-reply-to:date:references:subject: cc:to:from; d=ledu-giraud.fr; b=wOHVGzZXa1CSrY7D3g+MroxmbHESIbjt0bEAod oBBSESd9tU2bYLJtkOkS1pZRXd1OCmuhwFLlARovHQcw6/6MK0krFL7J0Sb8/O1YT2LE2Q qDO4CUaZxuWKvi68lM4dAiJjZ+bRvng8VT8GAFwzlpl+LC6ANo6O64pfgTLCZPGQza1wXz SCep1sL+hByT/zoCpNLMbUTPwH0clz2TNWTPfKdj2ewQGqq9oGJdG18a5yaLt/GYx9mR5z uGyyNOh/KcmLupKlFbPTAx2vuqwDoRazz4O9mYsIjrcAob8cr6QFSFRcLMcReKoOid2Qls qD9lZyllD1pcIwRAf/d2fm6A== Original-Received: from elite.giraud ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id 5852eec2 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Wed, 19 Jan 2022 11:24:01 +0100 (CET) In-Reply-To: (fatiparty's message of "Wed, 19 Jan 2022 10:03:28 +0100 (CET)") Received-SPF: pass client-ip=51.159.28.247; envelope-from=manuel@ledu-giraud.fr; helo=ledu-giraud.fr 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, SPF_HELO_PASS=-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.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" Xref: news.gmane.io gmane.emacs.help:135442 Archived-At: fatiparty--- via Users list for the GNU Emacs text editor writes: > Jan 19, 2022, 19:20 by help-gnu-emacs@gnu.org: > >> >> I would like to construct an elisp function that performs numeric >> computations and outputs the result. >> >> j =3D rptdepth >> w =3D maxdepth - j >> p =3D w + 1 >> >> output =3D j + ( (depth - maxdepth - 1) mod p ) >> > I have done as follows.=C2=A0 But one problem is: How do I use the output > in another elisp function? > > (defun test (depth maxdepth rptdepth) > =C2=A0 "Compute depth to use." > =C2=A0 (interactive) > =C2=A0=20 > =C2=A0 (let* ( (j rptdepth) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (w (- maxdepth j)) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (p (+ w 1)) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (r (mod (- depth m= axdepth 1) p) ) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (o (+ j r)) ) > > =C2=A0=C2=A0=C2=A0 (message "usedepth: %d" o) )) Hi, A `let' form returns the value of the last expression of its body. In your function, it is "(message=E2=80=A6)" which returns the string of the message. If you want your function to return `o' just append it as the last expression: (defun test (depth maxdepth rptdepth) "Compute depth to use." (interactive) (let* ( (j rptdepth) (w (- maxdepth j)) (p (+ w 1)) (r (mod (- depth maxdepth 1) p) ) (o (+ j r))) (message "usedepth: %d" o) o)) Then, you can use `test' directly: (* (test 8 1000 9) (test 8 1000 9)) --=20 Manuel Giraud