all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stephen Berman <stephen.berman@gmx.net>
To: help-gnu-emacs@gnu.org
Subject: Re: help with regexp function
Date: Fri, 24 Nov 2017 17:28:25 +0100	[thread overview]
Message-ID: <878tev4p5i.fsf@gmx.net> (raw)
In-Reply-To: ov9bd00381@news4.newsguy.com

On Fri, 24 Nov 2017 08:46:59 -0600 "B. T. Raven" <btraven@nihilo.net> wrote:

> On 11/23/2017 09:20, Stephen Berman wrote:
>
>>> It sounded like (append #'string ... was recasting a list to a string.
>>                   ^^^^^^
>>                   apply
> Yes, because I tried to type rather than copypaste.
> I was distracted by the # (what does it mean?)

Together with the apostrophe it stands for `function'.  I can't explain
it better than the Elisp manual (info "(elisp) Anonymous Functions"):

 -- Special Form: function function-object
     This special form returns FUNCTION-OBJECT without evaluating it.
     In this, it is similar to ‘quote’ (*note Quoting::).  But unlike
     ‘quote’, it also serves as a note to the Emacs evaluator and
     byte-compiler that FUNCTION-OBJECT is intended to be used as a
     function.  Assuming FUNCTION-OBJECT is a valid lambda expression,
     this has two effects:

        • When the code is byte-compiled, FUNCTION-OBJECT is compiled
          into a byte-code function object (*note Byte Compilation::).

        • When lexical binding is enabled, FUNCTION-OBJECT is converted
          into a closure.  *Note Closures::.

   The read syntax ‘#'’ is a short-hand for using ‘function’.  The
following forms are all equivalent:

     (lambda (x) (* x x))
     (function (lambda (x) (* x x)))
     #'(lambda (x) (* x x))

>> I'm not sure it's helpful to think of it like that, since using a list
>> is an artefact of the function definition here: `string' takes one or
>> more characters but Emacs Lisp functions cannot return multiple values,
>> only single values such as a list of characters.  But you can dispense
>> with that intermediate step:
>>
>> (defun reverse-string (str)
>>    (let ((l (length str))
>> 	(nstr ""))
>>      (dotimes (i l nstr)
>>        (setq nstr (concat (string (aref str i)) nstr)))))
>>
>> In fact, this is essentially how `nreverse' (and 'reverse') operate on
>> strings (so there's no need for `reverse-string').  In any case, I don't
>> see what this has to do with match-string.
>
> That looks like it may be faster than what
> I have now. Is it? Everything is in C except dotimes and string-to-list
> according to the function docs.

I don't know if there's a measurable difference, but again, why do you
want `reverse-string' when you can just use `reverse' (or `nreverse')?

Steve Berman




      reply	other threads:[~2017-11-24 16:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-21 23:30 help with regexp function B. T. Raven
2017-11-22 11:15 ` Stephen Berman
2017-11-22 17:05 ` Kendall Shaw
     [not found] ` <mailman.4298.1511349362.27995.help-gnu-emacs@gnu.org>
2017-11-23  4:18   ` B. T. Raven
2017-11-23 15:20     ` Stephen Berman
     [not found]     ` <mailman.4372.1511450434.27995.help-gnu-emacs@gnu.org>
2017-11-24 14:46       ` B. T. Raven
2017-11-24 16:28         ` Stephen Berman [this message]

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

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

  git send-email \
    --in-reply-to=878tev4p5i.fsf@gmx.net \
    --to=stephen.berman@gmx.net \
    --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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.