The function sunrise-sunset is an interactive function takes a numeric prefix argument as a parameter. It does not take the latitude and longitude as parameters, which is what you're trying to pass into it. I suggest reading this emacs wiki article as well as of course the manual itself to learn more about prefix arguments. Also checking out the interactive ...
A simple way to differentiate between value nil and a missing optional argument is to use &rest instead of &optional.
I demonstrate that with the following test function:
(defun testfun (arg &rest optArgs)
"Do something with ARG, OPT1, and OPT2.
OPT1 and OPT2 can be nil, 1, and 2.
The default of OPT1 is 1 and the default of 2 is 2.
\(fn ARG &...
You can use func-arity added in 26.1. C-h f func-arity:
func-arity is a built-in function in `C source code'.
Return minimum and maximum number of args allowed for FUNCTION.
FUNCTION must be a function of some kind.
The returned value is a cons
cell (MIN . MAX).
MIN is the minimum number of args.
MAX is the
Not exactly. Function buffer-substring requires two arguments. Function - will accept a single argument, but in that case it just returns the negative of that numeric argument. What you want to do is, in effect, apply such functions to a list of arguments. You can use higher-order function apply to do that.
What you can do, if you want, is have a macro or ...
It looks like you can call it like this:
(let ((calendar-latitude 40.1)
(calendar-location-name "Urbana, IL"))
This does not prompt you for the latitude and longitude, and puts a message in the minibuffer for those variable values.
There is the general rule that any widely used programming language such as R has an Emacs language mode and those modes also have functions that parse function arguments. For R there is the huge package Emacs Speaks Statistics.
There is a parser ess-r-syntax. The comment marks it as "not yet stable". But, there are 4 people working on it including senior ...
cl-defun from cl-macs.el allows you to specify default values (beside much other mind-blowing stuff).
(cl-defun testfun (arg &optional (opt1 1) (opt2 2))
"Process normal ARG and optional args OPT1 and OPT2 with defaults 1 and 2, respectively."
(list arg opt1 opt2))
Test 1: Set opt2 explicitly to nil:
(testfun 1 'a nil)
(1 a nil)
Test 2: Setting ...
The cleanest way IMO is to define an additional variable in the argument list that indicates if the argument was supplied by the caller. This can be done using cl-defun since it supports Common Lisp style argument lists. For example,
(cl-defun test (&optional (x nil supplied-p))
(list x supplied-p))
(test) => (nil nil)
Under the theory that some answer is better than none, I've posted my hacky solution to this, however I would welcome a better answer than this one.
(defun find-next-fcn-arg-separator ()
"Find the next argument separator in a function call.
Move point to the next function argument separator. Point is
expected to be at the opening parenthesis of the ...