[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Elisp function that performs numeric computations
From: |
Manuel Giraud |
Subject: |
Re: Elisp function that performs numeric computations |
Date: |
Wed, 19 Jan 2022 11:24:00 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (berkeley-unix) |
fatiparty--- via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> 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 = rptdepth
>> w = maxdepth - j
>> p = w + 1
>>
>> output = j + ( (depth - maxdepth - 1) mod p )
>>
> I have done as follows. But one problem is: How do I use the output
> in another elisp function?
>
> (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) ))
Hi,
A `let' form returns the value of the last expression of its body. In
your function, it is "(message…)" 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))
--
Manuel Giraud
- Re: Elisp function that performs numeric computations, (continued)
- Re: Elisp function that performs numeric computations, Sergey Organov, 2022/01/20
- Elisp function that performs numeric computations, fatiparty, 2022/01/21
- Re: Elisp function that performs numeric computations, Emanuel Berg, 2022/01/21
- Re: Elisp function that performs numeric computations, Sergey Organov, 2022/01/21
- Re: Elisp function that performs numeric computations, Emanuel Berg, 2022/01/21
- Re: Elisp function that performs numeric computations, Sergey Organov, 2022/01/21
- Elisp function that performs numeric computations, fatiparty, 2022/01/21
- Re: Elisp function that performs numeric computations, Emanuel Berg, 2022/01/21
- Elisp function that performs numeric computations, fatiparty, 2022/01/21
- Message not available
- Elisp function that performs numeric computations, fatiparty, 2022/01/20
- Re: Elisp function that performs numeric computations,
Manuel Giraud <=
- Re: Elisp function that performs numeric computations, Eduardo Ochs, 2022/01/19
Re: Elisp function that performs numeric computations, Michael Heerdegen, 2022/01/19