help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Functions with multiple optional arguments


From: Emanuel Berg
Subject: Re: Functions with multiple optional arguments
Date: Tue, 25 Oct 2022 07:25:15 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

> `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 via email to

[Prev in Thread] Current Thread [Next in Thread]