unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: "Basil L. Contovounesios" <basil@contovou.net>
Cc: Felician Nemeth <felician.nemeth@gmail.com>,  emacs-devel@gnu.org
Subject: Re: (byte-compile '(append '(1 2) '(3 4)))
Date: Sat, 16 Mar 2024 13:55:52 +0000	[thread overview]
Message-ID: <875xxmb7rr.fsf@posteo.net> (raw)
In-Reply-To: <87wmq2nweb.fsf@epfl.ch> (Basil L. Contovounesios's message of "Sat, 16 Mar 2024 14:23:08 +0100")

"Basil L. Contovounesios" <basil@contovou.net> writes:

> Philip Kaludercic [2024-03-16 12:46 +0000] wrote:
>
>> I am not sure what the danger is in the case of constant, quoted lists,
>> but I am not familiar with the byte compiler either.  It seems like this
>>
>> diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
>> index f75be3f71ad..e6f18590705 100644
>> --- a/lisp/emacs-lisp/byte-opt.el
>> +++ b/lisp/emacs-lisp/byte-opt.el
>> @@ -1599,6 +1599,12 @@ byte-optimize-append
>>                           (cdr args))
>>                     (cdr newargs)))
>>  
>> +            ;; (append '(C1...) ... '(C2...)) -> (append C1... ... C2...)
>> +            ((cl-loop for arg in args
>> +                      always (and (eq (car arg) 'quote)
>> +                                  (proper-list-p (cdr arg))))
>> +             `',(mapcan #'cadr args))
>> +
>>              ;; non-terminal arg
>>              ((cdr args)
>>               (cond
>>
>>
>> would do the trick, and the byte-code is even better:
>>
>> byte code:
>>   args: nil
>> 0	constant  (1 2 3 4)
>> 1	return	  
>
> Is this correct?  According to its docstring, append's last argument
> must be eq to the tail of its return value.

This little test indicates that it would still be eq:

((macro . (lambda (arg)
	    `(eq (cddadr (byte-optimize-append '(append '(1 2) ,arg)))
		 ,arg)))
 '(3 4)) ;=> t

since the mapcan or rather nconc makes the same promise.

-- 
	Philip Kaludercic on peregrine



  parent reply	other threads:[~2024-03-16 13:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87v8j28c2x.fsf@betli.tmit.bme.hu>
     [not found] ` <874jdipfp5.fsf@posteo.net>
     [not found]   ` <87cys6t734.fsf@betli.tmit.bme.hu>
     [not found]     ` <87r0gmnjq4.fsf@posteo.net>
     [not found]       ` <87o7bprr04.fsf@betli.tmit.bme.hu>
     [not found]         ` <87bk7p57yz.fsf@posteo.net>
2024-03-16 12:16           ` (byte-compile '(append '(1 2) '(3 4))) Felician Nemeth
2024-03-16 12:46             ` Philip Kaludercic
2024-03-16 13:23               ` Basil L. Contovounesios
2024-03-16 13:45                 ` Felician Nemeth
2024-03-16 13:55                 ` Philip Kaludercic [this message]
2024-03-16 23:42                   ` Basil L. Contovounesios

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=875xxmb7rr.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=basil@contovou.net \
    --cc=emacs-devel@gnu.org \
    --cc=felician.nemeth@gmail.com \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).