[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Elisp function that performs numeric computations
From: |
Emanuel Berg |
Subject: |
Re: Elisp function that performs numeric computations |
Date: |
Fri, 21 Jan 2022 12:39:20 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
fatiparty--- via Users list for the GNU Emacs text editor wrote:
>>>>> "Compute depth to use."
>>>>> (interactive)
>>>>>
>>>>> (let* ( (j rptdepth)
>>>>> (w (- maxdepth j))
>>>>> (p (+ w 1))
>>>>> (r (mod (- depth maxdepth 1) p) )
>>>>> (o (+ j r)) )
>>>>> o))
>>>>>
>>>
>>> I would like to adapt the function a little bit more. If
>>> depth <= maxdepth I want to set o=depth instead of
>>> performing the computation shown for the variable o.
>>>
>>
>> Did I get it right, I wonder?
>>
>> (defun test (depth maxdepth rptdepth)
>> (if (<= depth maxdepth)
>> depth
>> (+ rptdepth
>> (mod (- depth maxdepth 1)
>> (- maxdepth rptdepth -1)))))
>>
>> Is it how true (E)Lisp'er would write it?
>>
>
> What you have done is good. But although you have got to
> a simple solution, I want to code the more complicated
> solution for the case where let* is involved (within which
> local variables are defined).
The reason there is no `let' (or `let*') in his code is
because there is no repitition of computation patterns ...
As for "Is it how true (E)Lisp'er would write it?" I'd write
it, whatever it is, like this:
(defun organov (dep top rep)
(if (<= dep top)
dep
(+ rep
(mod (1- (- dep top))
(1+ (- top rep)) ))))
Elispers at work!
--
underground experts united
https://dataswamp.org/~incal
- Elisp function that performs numeric computations, fatiparty, 2022/01/19
- Message not available
- Elisp function that performs numeric computations, fatiparty, 2022/01/19
- Re: Elisp function that performs numeric computations, tomas, 2022/01/19
- Re: Elisp function that performs numeric computations, Marcin Borkowski, 2022/01/19
- Elisp function that performs numeric computations, fatiparty, 2022/01/19
- 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 <=
- 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, 2022/01/19
- Re: Elisp function that performs numeric computations, Eduardo Ochs, 2022/01/19
- Re: Elisp function that performs numeric computations, Michael Heerdegen, 2022/01/19