[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: |
Thu, 03 Aug 2023 17:25:23 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
uzibalqa wrote:
> What I did not immediately realise was that within the
> context of function arguments, lexical binding is the
> default way to handle function arguments in Lisp and Emacs
> Lisp, notwithstanding the file binding specification.
Here, take a look at this code.
First the scope is set to lexical which you should always do,
but here it doesn't influence the code.
Then a global/special/dynamic variable is created with
`defvar'.
Then a lexical argument with the same name is created, and
that will be the boss for every mention in that function.
If you byte-compile it, you will get a warning, but that is
just to avoid confusion, the code will be more clear if the
argument is named something else.
Warning: global/dynamic var ‘gsd’ lacks a prefix
Warning: Lexical argument shadows the dynamic variable gsd
;;; -*- lexical-binding: t -*-
(defvar gsd 1)
(defun test-gsd (&optional gsd)
(or gsd (setq gsd 2))
gsd)
;; (test-gsd)
;; (test-gsd 3)
--
underground experts united
https://dataswamp.org/~incal
- Re: Passing optional arguments for use with internal functions, Emanuel Berg, 2023/08/02
- Re: Passing optional arguments for use with internal functions, uzibalqa, 2023/08/02
- Re: Passing optional arguments for use with internal functions, Emanuel Berg, 2023/08/02
- Re: Passing optional arguments for use with internal functions, uzibalqa, 2023/08/02
- Re: Passing optional arguments for use with internal functions, uzibalqa, 2023/08/02
- Re: Passing optional arguments for use with internal functions, Emanuel Berg, 2023/08/04
- Re: Passing optional arguments for use with internal functions,
Emanuel Berg <=
- Re: Passing optional arguments for use with internal functions, Emanuel Berg, 2023/08/04
- Re: Passing optional arguments for use with internal functions, Emanuel Berg, 2023/08/04