unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Emanuel Berg <incal@dataswamp.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Passing optional arguments for use with internal functions
Date: Thu, 03 Aug 2023 17:46:39 +0200	[thread overview]
Message-ID: <875y5wku1s.fsf@dataswamp.org> (raw)
In-Reply-To: -3N3ToZTUg2mUqmpgTYmAX8LUtMKCkCb5CLWN1q1gJxpBpcd_18KWXjL7lh51B6NXfrXEBNmRo7SwK5AClT6M1-NjD2DP1oInylqklgCF9Y=@proton.me

Here are both programs. The first one is under lexical scope.
If you use it, function arguments are always lexical.

But the second program, under dynamic scope - yes, what does
that show exactly?

The case with (4 4) is the most interesting because it ignores
the global/dynamic gsdd - but its own gsdd is nevertheless
dynamic as well?

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/geh.el

(defvar gsd 1)

(defun test-gsd-gsd ()
  gsd)

(defun test-gsd (&optional gsd)
  (or gsd (setq gsd 2))
  gsd)

;; (test-gsd-gsd) ; 1 - global/dynamic gsd
;; (test-gsd)     ; 2 - lexical argument gsd
;; (test-gsd 3)   ; 3 - lexical argument gsd

;; byte compile:
;;   Warning: global/dynamic var ‘gsd’ lacks a prefix
;;   Warning: Lexical argument shadows the dynamic variable gsd

;;; -*- lexical-binding: nil -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/geh-dyn.el

(defvar gsdd 3)

(defun test-gsdd-gsdd ()
  gsdd)

(defun test-gsdd (&optional gsdd)
  (or gsdd (setq gsdd 4))
  (list (test-gsdd-gsdd) gsdd) )

;; (test-gsdd-gsdd) ; 3 - global/dynamic gsdd
;; (test-gsdd)      ; (4 4) - same
;; (test-gsdd 5)    ; (5 5) - same

(provide 'geh-dyn)

-- 
underground experts united
https://dataswamp.org/~incal




  parent reply	other threads:[~2023-08-03 15:46 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-27 23:45 Passing optional arguments for use with internal functions uzibalqa
2023-07-28 10:51 ` Emanuel Berg
2023-07-28 16:42   ` Heime
2023-07-28 17:11     ` Emanuel Berg
2023-07-30 16:09       ` uzibalqa
2023-07-31 12:27         ` Emanuel Berg
2023-08-02 18:01           ` uzibalqa
2023-08-02 18:20             ` Emanuel Berg
2023-08-02 19:24               ` uzibalqa
2023-08-02 19:53                 ` uzibalqa
2023-08-02 23:24                   ` Emanuel Berg
2023-08-03 15:25                   ` Emanuel Berg
2023-08-03 15:35                   ` Emanuel Berg
2023-08-03 15:46                   ` Emanuel Berg [this message]
2023-07-28 20:02   ` [External] : " Drew Adams
2023-07-28 20:42     ` uzibalqa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875y5wku1s.fsf@dataswamp.org \
    --to=incal@dataswamp.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).