[Top][All Lists]

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

Re: (interactive) and &optional

From: Emanuel Berg
Subject: Re: (interactive) and &optional
Date: Fri, 24 Mar 2023 22:07:30 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Philip Kaludercic wrote:

> The issue here is that the function is difficult to re-use
> from other scripts. If the interactive stuff is encapsulated
> within an (interactive) form then you avoid the issue.

`interactive' is the right place for everything interactive,
so unless there is a specific reason why it is impractical to
put it there, that's where one should put the
interactive stuff.

But I do get the feeling one could improve `interactive' ...

Note that you can also use `cl-defun' to put the default
values there, as in

;;; -*- lexical-binding: t -*-
;; this file:

(require 'cl-lib)

(cl-defun dice (&optional (sides 6) (num 1))
    repeat num
    with sum = 0
    do (cl-incf sum (1+ (random sides)))
    finally return sum) )

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

(provide 'dice)

underground experts united

reply via email to

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