[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:
;; https://dataswamp.org/~incal/emacs-init/dice.el
(require 'cl-lib)
(cl-defun dice (&optional (sides 6) (num 1))
(cl-loop
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
https://dataswamp.org/~incal
- Re: (interactive) and &optional, (continued)
Re: (interactive) and &optional, Emanuel Berg, 2023/03/23
Re: (interactive) and &optional, Jean Louis, 2023/03/24
Re: (interactive) and &optional,
Emanuel Berg <=
RE: [External] : Re: (interactive) and &optional, Drew Adams, 2023/03/26
Re: [External] : Re: (interactive) and &optional, John Yates, 2023/03/26
Re: (interactive) and &optional, Dr Rainer Woitok, 2023/03/25