From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: help with regexp function Date: Fri, 24 Nov 2017 17:28:25 +0100 Message-ID: <878tev4p5i.fsf@gmx.net> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1511540974 27610 195.159.176.226 (24 Nov 2017 16:29:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 24 Nov 2017 16:29:34 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 24 17:29:30 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eIGr3-0006tC-NF for geh-help-gnu-emacs@m.gmane.org; Fri, 24 Nov 2017 17:29:29 +0100 Original-Received: from localhost ([::1]:50056 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eIGr9-0004TW-H7 for geh-help-gnu-emacs@m.gmane.org; Fri, 24 Nov 2017 11:29:35 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35547) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eIGqV-0004Rq-EF for help-gnu-emacs@gnu.org; Fri, 24 Nov 2017 11:28:56 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eIGqS-0002Aw-6a for help-gnu-emacs@gnu.org; Fri, 24 Nov 2017 11:28:55 -0500 Original-Received: from [195.159.176.226] (port=37165 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eIGqR-0001wO-VO for help-gnu-emacs@gnu.org; Fri, 24 Nov 2017 11:28:52 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1eIGq7-0003NP-KL for help-gnu-emacs@gnu.org; Fri, 24 Nov 2017 17:28:31 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 58 Original-X-Complaints-To: usenet@blaine.gmane.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:115081 Archived-At: On Fri, 24 Nov 2017 08:46:59 -0600 "B. T. Raven" 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