[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Passing optional arguments for use with internal functions
From: |
Emanuel Berg |
Subject: |
Re: Passing optional arguments for use with internal functions |
Date: |
Fri, 28 Jul 2023 19:11:33 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Heime wrote:
>> Optional arguments defaults to nil, if that is an
>> acceptable value you can use it as you do, if not you can
>> check if it is nil first thing in the function and if it
>> is, set it to something that works, e.g.
>>
>> (or arg (setq arg 0))
>
> Does the condition you specified work whether the binding is
> lexical or dynamic ?
If there is an optional argument with that name yes, since
formal parameters (function arguments) are always lexical.
;;; -*- lexical-binding: nil -*-
(defvar arg)
(setq arg 2)
(defun echo-arg (&optional arg)
(or arg (setq arg 1))
(message "%s" arg) )
;; (echo-arg)
This will still echo 1.
--
underground experts united
https://dataswamp.org/~incal