[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Optional Arguments
From: |
Alexis Roda |
Subject: |
Re: Optional Arguments |
Date: |
Mon, 7 Dec 2020 20:51:06 +0100 |
https://www.gnu.org/software/emacs/manual/html_node/eintr/Parts-of-let-Expression.html
According to that, your let expression defines a variable called 'ma'
initialized with the value given by 'mb', which is not defined at that
point.
Try with:
(defun word-markers ()
(let ((ma nil)
(mb nil))
(skip-chars-backward "[:alpha:]")
(setq ma (point))
(skip-chars-forward "[:alpha:]")
(setq mb (point))
(cons ma mb)))
or
(defun word-markers ()
(let (ma
mb)
(skip-chars-backward "[:alpha:]")
(setq ma (point))
(skip-chars-forward "[:alpha:]")
(setq mb (point))
(cons ma mb)))
In the second example 'ma' and 'mb' are initialized implicitly with nil.
Also variables '$mu' and '$mv' aren't defined.
Missatge de l'adreça <pietru@caramail.com> del dia dl., 7 de des. 2020 a
les 19:18:
> I'm having a go at returning the two values from a function
>
> (defun word-markers ()
> (let ((ma mb))
> (skip-chars-backward "[:alpha:]")
> (setq ma (point))
> (skip-chars-forward "[:alpha:]")
> (setq mb (point))
> (cons ma mb) ))
>
> (defun test ()
> (interactive)
>
> (let ((deactivate-mark nil) bounds $ma $mb)
> (if (use-region-p)
> (setq $ma (region-beginning) $mb (region-end))
> (save-excursion
> (setq bounds (word-markers))
> (setq $mu (car bounds))
> (setq $mv (car bounds)) ))
>
> (message "Bounds: %s" $bounds)
> (message "Region: [%s, %s]" $ma $mb) ))
>
> But something's not right.
>
>
> > Sent: Monday, December 07, 2020 at 4:38 PM
> > From: tomas@tuxteam.de
> > To: pietru@caramail.com
> > Cc: "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> > Subject: Re: Optional Arguments
> >
> > On Mon, Dec 07, 2020 at 03:24:36PM +0100, pietru@caramail.com wrote:
> >
> > [...]
> >
> > > > => "ma: 15 mb: 26"
> > >
> > > Hmmm. Variables local to function.
> >
> > Yes. "Local" meaning here either dynamical extent (called functions
> > "see" the variables up the call chain, think Unix shells) or
> > lexical extent (code contexts "see" the variables of enclosing
> > code contexts (think C or Java or...), depending on whether you
> > chose lexical binding [1].
> >
> > [...]
> >
> > > > ...would you expect it to change the number 15 to whatever the word's
> > > > beginning position is? You would mess up maths with that :)
> > >
> > > Yes, it would mess up.
> >
> > Gödel's nothing against that :-D
> >
> > Cheers
> >
> > [1] Cf. Chapter "Lexical Binding" in the Elisp manual, or here
> >
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Lexical-Binding.html
> >
> > - t
> >
>
>
- Re: Optional Arguments, (continued)
- Re: Optional Arguments, Anders Dalskov, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, tomas, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, Arthur Miller, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, Michael Heerdegen, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, Arthur Miller, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments,
Alexis Roda <=
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, tomas, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, Arthur Miller, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, Stefan Monnier, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, Christopher Dimech, 2020/12/07