unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: fatiparty--- via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: Sergey Organov <sorganov@gmail.com>
Cc: Help Gnu Emacs <help-gnu-emacs@gnu.org>
Subject: Elisp function that performs numeric computations
Date: Fri, 21 Jan 2022 10:04:48 +0100 (CET)	[thread overview]
Message-ID: <MtvsOH2--3-2@tutanota.com> (raw)
In-Reply-To: <sscp5u$u4q$1@ciao.gmane.io>

Jan 21, 2022, 10:53 by sorganov@gmail.com:

> fatiparty--- via Users list for the GNU Emacs text editor
> <help-gnu-emacs@gnu.org> writes:
>
>> Jan 19, 2022, 23:29 by mbork@mbork.pl:
>>
>>>
>>> (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)) )
>>>>  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?
> -- Sergey Organov
>
I have done as follows,  which seems to be working correctly.

(defun test (dcur dmax drpt)
  "Compute brace depth used for brace colouring."
  (interactive)

  (if (<= dcur dmax)

      (let ( (n dcur) )
    (message "dcur <= dmax | Typeface: %d" n)
    n)

    (let* ( (j drpt)
            (w (- dmax j))
            (p (+ w 1))
            (r (mod (- dcur dmax 1) p) )
            (n (+ j r)) )
    (message "dcur > dmax | Typeface: %d" n)
    n) ))







  parent reply	other threads:[~2022-01-21  9:04 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-19  7:20 Elisp function that performs numeric computations fatiparty--- via Users list for the GNU Emacs text editor
     [not found] ` <MtlCLWs--3-2@tutanota.com-MtlItBn----2>
2022-01-19  9:03   ` fatiparty--- via Users list for the GNU Emacs text editor
2022-01-19 10:14     ` tomas
2022-01-19 11:29       ` Marcin Borkowski
2022-01-19 22:52         ` fatiparty--- via Users list for the GNU Emacs text editor
2022-01-20 22:53           ` Sergey Organov
2022-01-21  8:23             ` fatiparty--- via Users list for the GNU Emacs text editor
2022-01-21 11:39               ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-01-21 13:03                 ` Sergey Organov
2022-01-21 15:32                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-01-21 17:13                     ` Sergey Organov
2022-01-21  9:04             ` fatiparty--- via Users list for the GNU Emacs text editor [this message]
2022-01-21 11:51               ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-01-21 12:25                 ` fatiparty--- via Users list for the GNU Emacs text editor
     [not found]         ` <MtoXj5p--3-2@tutanota.com-MtoXrZH----2>
2022-01-20 18:17           ` fatiparty--- via Users list for the GNU Emacs text editor
2022-01-19 10:24     ` Manuel Giraud
2022-01-19 17:31     ` Eduardo Ochs
2022-01-19 15:31 ` Michael Heerdegen
2022-01-19 18:41   ` H. Dieter Wilhelm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=MtvsOH2--3-2@tutanota.com \
    --to=help-gnu-emacs@gnu.org \
    --cc=fatiparty@tutanota.com \
    --cc=sorganov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).