> >> > Does elisp support function arguments optional default values ? > >> I solve that problem with following: > >> (defun my-function (arg &optional other-arg) > >> (let* ((other-arg (or other-arg my-default))) > >> other-arg)) > > Simpler - no reason for another binding, > > just change the value (it's a local var). > > > > (defun my-function (arg &optional other-arg) > > (setq other-arg (or other-arg my-default)) > > ...) > > FWIW, assuming you're using `lexical-binding` (which you should), this > tends to result in less efficient byte-code. > > The difference is marginal in most cases (and efficiency of ELisp code > is irrelevant in most cases as well), but the point is that bindings > don't "cost" as much as mutation. > > Here is how this usually plays out: with (setq x (or x )) the > evaluation pushes the result of (or x ) on the stack, does the > `setq` which consumes the value on the stack and modifies the value of > `x`, which itself lives on the stack. > > With (let ((x1 (or x ))) ...), the beginning is the same, > pushing the result of (or x ) on the stack, but then the > execution of the `let` is the "free" act of keeping that value on the > stack (i.e. doing nothing), and instead of referring to the stack > element that holds `x`, we will simply refer to the stack element that > holds `x1`. > [ There is still a cost to `let` in the fact that the stack grows a bit > more, of course, but it's usually of no consequence. ] > ... > > The difference is more drastic when the variable is captured by > a closure because our closure conversion is too naïve to understand that > the `setq` happens "once and forall" before we capture the variable, so > it presumes that the var may still be mutated after the closure is > constructed, which means that the closure can't just hold a copy of the > var's value but really needs to hold a "reference to the variable", > which we do by storing the variable's value inside a cons-cell: > ... Interesting! Thanks. I wonder what the case is with various Common Lisp implementations.