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

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

Re: bounds for strings with - between subwords


From: Christopher Dimech
Subject: Re: bounds for strings with - between subwords
Date: Fri, 7 May 2021 01:58:43 +0200

> Sent: Friday, May 07, 2021 at 11:44 AM
> From: "Emanuel Berg via Users list for the GNU Emacs text editor" 
> <help-gnu-emacs@gnu.org>
> To: help-gnu-emacs@gnu.org
> Subject: Re: bounds for strings with - between subwords
>
> Christopher Dimech wrote:
>
> >> > (defun alpha-bounds ()
> >> >    "Gets bounds of a subword unit defined by regular expression 
> >> > [a-zA-Z]."
> >> >    (let ( ($bounds nil) $ma $mb )
> >> >       (skip-chars-backward "[:alpha:]")
> >> >       (setq $ma (point))
> >> >       (skip-chars-forward "[:alpha:]")
> >> >       (setq $mb (point))
> >> >       (setq $bounds (bounds-of-thing-at-point 'word))
> >> >       (cons $ma $mb) ))
> >>
> >> You can put all that in the `let' to avoid the use of `setq'.
> >>
> >> Also $bounds doesn't seem to do anything?
> >
> > bounds are used in another function. You can see there is
> > (cons $ma $mb) at the end,
> > which is used as output when you call "alpha-bounds".
>
> $bounds still isn't used anywhere else and cannot be, either.

You are right, the use of the function is merely to set $ma and $mb.
The last $bounds can be removed.

> >> And what's the purpose of the $?
> >
> > I use $ no tell me the variable is local and not being
> > modified from outside. It is coming from the $1, $2, $3, ...
> > function parameter idea.
>
> But they cannot be modified from the outside so no need to
> worry about that.

It is a question of readability, particularly for long functions so not
to get confused when making changes or debugging.  The function is very
short as you say.  It is simply a standard I put in anyway.

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



reply via email to

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