From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.devel Subject: Re: pure-fns in byte-opt.el Date: Fri, 28 Jul 2017 17:45:48 +0000 Message-ID: References: <20170725020650.GA12601@holos.localdomain> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a1134fab2fab57c05556440f0" X-Trace: blaine.gmane.org 1501263995 23783 195.159.176.226 (28 Jul 2017 17:46:35 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 28 Jul 2017 17:46:35 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jul 28 19:46:31 2017 Return-path: Envelope-to: ged-emacs-devel@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 1db9LL-0005yY-3R for ged-emacs-devel@m.gmane.org; Fri, 28 Jul 2017 19:46:31 +0200 Original-Received: from localhost ([::1]:49396 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1db9LQ-0007Sm-U3 for ged-emacs-devel@m.gmane.org; Fri, 28 Jul 2017 13:46:36 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57876) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1db9Ks-0007SU-OQ for emacs-devel@gnu.org; Fri, 28 Jul 2017 13:46:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1db9Kr-0001yZ-Gs for emacs-devel@gnu.org; Fri, 28 Jul 2017 13:46:02 -0400 Original-Received: from mail-oi0-x22e.google.com ([2607:f8b0:4003:c06::22e]:33448) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1db9Kr-0001ww-79 for emacs-devel@gnu.org; Fri, 28 Jul 2017 13:46:01 -0400 Original-Received: by mail-oi0-x22e.google.com with SMTP id a9so139227911oih.0 for ; Fri, 28 Jul 2017 10:45:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XVGZ11Axab5Rc69nNWidwj9JmtavivfJNsAxSfiF1r0=; b=Iy/ogjQPumjFBXm00wkx7zSsFzhWo9/bEqJDwWN9G1KnljgWz/4+odK5QZYDfoiORE kPnwcx7M/EXxG5Mqw06Sx7W3YfUZCbMSjC8F9xI8AnpifXPAhVCE1oaVLUfyJtIAnXP+ K7eMfIKn9oOzz8OIjG3zEUf8kYymZrCb7DdsfudSn9TmuWeaCiWbEa2/Q5m0q9EuUffw GqPD882hO13bJZYTmf1esDX8pPaXl1Bm/qdJnxhetN0qUldjq4WrF9yJdYpOjbkamsw2 7QM/30vx2dyC8NZQjwvOtUldccMCOUR0Sje1sioeFhgxchkpylzFHr9bNwiWRcu24SSB zthQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XVGZ11Axab5Rc69nNWidwj9JmtavivfJNsAxSfiF1r0=; b=Dyj7PeGb+j+iagYy4aNQtoOGxQWI8ZZO621am7cVPzw1XRbTy+gL86Kj5ShTJJKgP3 eQ7ie4MNEu28oZxCchrzfsN42WB0e3Tp6DigT68NnVbDDU8q67qzDvi5SOVw96r+jiT0 kqahGOmbmb7DIRADRExYesyDqFwth9kKdxpn856K/+HNjChNUIwaz6Ga+1CiB+y4mJxX RSuKQdQcksDUqsOutqN7Gm8Yhsx7gGxK8w1EzqHC4qhQ2zXeoyHJjHS2V6vIrzVSu6F4 rpS+T5f/L9hH/Diw4X7y0TUcXAYE4KmSx4nVZ28vWjJPWplsXXJkn02oMGrcKwu2WBTb OjEA== X-Gm-Message-State: AIVw1104GjdJDz19O1aGdwYNfSGI+L0mFEN/UNPz9R8E2ZI2cvHvcrcA ml00uX41Iwc8XLzjwmRhGeqieJlHAA== X-Received: by 10.202.74.68 with SMTP id x65mr6996120oia.301.1501263958814; Fri, 28 Jul 2017 10:45:58 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::22e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:217108 Archived-At: --001a1134fab2fab57c05556440f0 Content-Type: text/plain; charset="UTF-8" Stefan Monnier schrieb am Di., 25. Juli 2017 um 23:27 Uhr: > > Why? Its return value clearly only depends on its argument, and it > doesn't > > change any global state. It's the poster child of a pure function! > > (let ((s (make-string 5 ?a))) > (list (string-to-char s) > (progn > (aset s 0 ?b) > (string-to-char s)))) > > If string-to-char were a pure function, it would return the same value > in both calls (since the arguments are `eq'). > > Hmm. I get the argument, but wouldn't that mean that only a tiny set of builtins were pure? If the definition is "A function is pure if applying it to the same objects (in the sense of `eq') always gives the same result", then I think only eq, eql, null, and the type predicates (integerp etc.) are pure. Even the arithmetic functions aren't pure because they can act on (mutable) markers. The list in byte-opt, however, is noticeably different, and none of the functions marked pure there are actually pure. The same applies to third-party libraries such as dash.el. In any case, the precise definition of "pure" and "side effect free" needs to be in the manual, and functions that are wrongly declared as pure or side effect free need to be fixed. --001a1134fab2fab57c05556440f0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


Stefan= Monnier <monnier@iro.umontr= eal.ca> schrieb am Di., 25. Juli 2017 um 23:27=C2=A0Uhr:
> Why? Its return value clearly only depend= s on its argument, and it doesn't
> change any global state. It's the poster child of a pure function!=

=C2=A0 (let ((s (make-string 5 ?a)))
=C2=A0 =C2=A0 (list (string-to-char s)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (progn
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (aset s 0 ?b)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (string-to-char s))))

If string-to-char were a pure function, it would return the same value
in both calls (since the arguments are `eq').


Hmm. I get the argument, but wouldn= 9;t that mean that only a tiny set of builtins were pure? If the definition= is "A function is pure if applying it to the same objects (in the sen= se of `eq') always gives the same result", then I think only eq, e= ql, null, and the type predicates (integerp etc.) are pure. Even the arithm= etic functions aren't pure because they can act on (mutable) markers. T= he list in byte-opt, however, is noticeably different, and none of the func= tions marked pure there are actually pure. The same applies to third-party = libraries such as dash.el.
In any case, the precise definition of= "pure" and "side effect free" needs to be in the manua= l, and functions that are wrongly declared as pure or side effect free need= to be fixed.=C2=A0
--001a1134fab2fab57c05556440f0--