unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Let* binding for running commands with a default value
@ 2024-07-07 13:55 Heime
  2024-07-07 14:25 ` CToID
  0 siblings, 1 reply; 4+ messages in thread
From: Heime @ 2024-07-07 13:55 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

I aw setting a default when an optional argument is missing 
with a let* binding.

(defun mtj-requisites (&optional act)

   (let* ( (act (or act 'go)) )
      (when (eq act 'go) (require 'clipper)) ))

Do the commands dependent on act have to be placed in the 
let* body ?  Or can one also do

(let* ( (act (or act 'go)) ) )
(when (eq act 'go) (require 'clipper))





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Let* binding for running commands with a default value
  2024-07-07 13:55 Let* binding for running commands with a default value Heime
@ 2024-07-07 14:25 ` CToID
  2024-07-07 15:05   ` Heime
  0 siblings, 1 reply; 4+ messages in thread
From: CToID @ 2024-07-07 14:25 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

On 2024-07-07 Sun 21:55 UTC+0800, Heime <heimeborgia@protonmail.com> said:

> Or can one also do
> 
> (let* ( (act (or act 'go)) ) )
> (when (eq act 'go) (require 'clipper))

No, the `(eq act 'go)` outside doesn't know the value of `act` inside 
`let*`.  So depends on situation, the result may or may not be the same.

-- 
Best,
ID




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Let* binding for running commands with a default value
  2024-07-07 14:25 ` CToID
@ 2024-07-07 15:05   ` Heime
  2024-07-07 15:10     ` CToID
  0 siblings, 1 reply; 4+ messages in thread
From: Heime @ 2024-07-07 15:05 UTC (permalink / raw)
  To: CToID; +Cc: Heime via Users list for the GNU Emacs text editor

On Sunday, July 7th, 2024 at 2:25 PM, CToID <funk443@yahoo.com.tw> wrote:

> On 2024-07-07 Sun 21:55 UTC+0800, Heime heimeborgia@protonmail.com said:
> 
> > Or can one also do
> > 
> > (let* ( (act (or act 'go)) ) )
> > (when (eq act 'go) (require 'clipper))
> 
> 
> No, the `(eq act 'go)` outside doesn't know the value of `act` inside
> `let*`. So depends on situation, the result may or may not be the same.
 
The let* is then applying a different local variable, than the local variable
of the function argument.  But without the overhead associated with using setq
as

(or act (setq act 'go)) 
(when (eq act 'go) (require 'clipper))




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Let* binding for running commands with a default value
  2024-07-07 15:05   ` Heime
@ 2024-07-07 15:10     ` CToID
  0 siblings, 0 replies; 4+ messages in thread
From: CToID @ 2024-07-07 15:10 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

https://en.wikipedia.org/wiki/Variable_shadowing

-- 
Best,
ID




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-07-07 15:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-07 13:55 Let* binding for running commands with a default value Heime
2024-07-07 14:25 ` CToID
2024-07-07 15:05   ` Heime
2024-07-07 15:10     ` CToID

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).