all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg <incal@dataswamp.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Functions with multiple optional arguments
Date: Tue, 25 Oct 2022 07:25:15 +0200	[thread overview]
Message-ID: <87ilk8eapw.fsf@dataswamp.org> (raw)
In-Reply-To: 87sfjdkjhh.fsf@dataswamp.org

> `cl-defun' is Elisp, if you need it or not is up to you ...

Here is an example how it's done in Elisp only.

Hey, never to late to return to the old pen-and-paper RPGs!

Actually I don't want to do that ...

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/dice.el

(require 'cl-lib)

(cl-defun dice (&optional (sides 6) (num 1))
  (let ((sum 0))
    (dotimes (_ num) (cl-incf sum (1+ (random sides))))
    sum) )

;; (dice)     ; 1D6, 1-6
;; (dice 3)   ; 1D3, 1-3
;; (dice 3 2) ; 2D3, 2-6

-- 
underground experts united
https://dataswamp.org/~incal




  reply	other threads:[~2022-10-25  5:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-16 21:04 Functions with multiple optional arguments Heime via Users list for the GNU Emacs text editor
2022-10-17  1:48 ` Emanuel Berg
2022-10-17  4:05 ` Jean Louis
2022-10-17  4:18   ` Emanuel Berg
2022-10-17 21:12     ` Jean Louis
2022-10-17 21:36       ` Emanuel Berg
2022-10-20 21:00         ` Jean Louis
2022-10-21  3:29           ` Emanuel Berg
2022-10-23  4:47             ` Jean Louis
2022-10-24  3:07               ` Emanuel Berg
2022-10-25  5:25                 ` Emanuel Berg [this message]
2022-10-17  5:42   ` Heime
2022-10-17 16:24     ` Heime
2022-10-17 16:52       ` [External] : " Drew Adams
2022-10-17 17:28         ` Heime
2022-10-17 17:38           ` Drew Adams

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

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

  git send-email \
    --in-reply-to=87ilk8eapw.fsf@dataswamp.org \
    --to=incal@dataswamp.org \
    --cc=help-gnu-emacs@gnu.org \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.