help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Optional Arguments


From: pietru
Subject: Re: Optional Arguments
Date: Mon, 7 Dec 2020 19:13:06 +0100

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
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]