From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Christopher Allan Webber Newsgroups: gmane.emacs.devel,gmane.emacs.tangents Subject: Re: Python vs Lisp (followups to -tangents) Date: Wed, 16 Dec 2015 11:56:24 -0600 Message-ID: <8737v2mfph.fsf@dustycloud.org> References: <87io4lem98.fsf@petton.fr> <56604A9C.7080508@gmail.com> <20151208130529.GA28682@HAL9000> <1c367763-4ba1-4c65-80d1-be1b365c3b35@default> <87lh94hde0.fsf@mbork.pl> <86oadyjgew.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1450289185 7570 80.91.229.3 (16 Dec 2015 18:06:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 16 Dec 2015 18:06:25 +0000 (UTC) Cc: emacs-tangents@gnu.org, emacs-devel@gnu.org To: Random832 Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Dec 16 19:06:12 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1a9GSp-0001Ch-9i for ged-emacs-devel@m.gmane.org; Wed, 16 Dec 2015 19:06:11 +0100 Original-Received: from localhost ([::1]:48662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9GSn-0007z0-VX for ged-emacs-devel@m.gmane.org; Wed, 16 Dec 2015 13:06:09 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57957) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9GSa-0007yr-N9 for emacs-devel@gnu.org; Wed, 16 Dec 2015 13:05:57 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9GSX-00075m-Gv for emacs-devel@gnu.org; Wed, 16 Dec 2015 13:05:56 -0500 Original-Received: from dustycloud.org ([50.116.34.160]:46451) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9GSX-00075h-Dk; Wed, 16 Dec 2015 13:05:53 -0500 Original-Received: from earlgrey (localhost [127.0.0.1]) by dustycloud.org (Postfix) with ESMTPS id 5526C26799; Wed, 16 Dec 2015 13:05:52 -0500 (EST) In-reply-to: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 50.116.34.160 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:196393 gmane.emacs.tangents:50 Archived-At: Random832 writes: >> The point Richard is making is that Python lacks macros, i.e., you >> cannot easily write code which writes code. >> You have to either operate at the level of strings (which is hard to get >> right) or at the level of AST (which is even harder). > > I don't see how operating at the level of AST is harder than > operating at the level of lists (backquote operates above the > level of lists; it automatically searches the code you give it > for placeholders to substitute values in. It probably wouldn't > be hard to write an equivalent in Python.) So, I think this thread is getting fairly off topic for the list, but I can't resist chiming in here. A project I've contributed to occasionally is Hy, which is sort of a lisp that uses s-expressions (yes, you do need them if you want homoiconic properties) which compiles down to Python's AST. It's pretty cool, because you can now write macros for Python and do other sorts of lispy things that are impossible otherwise. See: http://hy.readthedocs.org/en/latest/tutorial.html Doing this required building a lisp like system on top of Python though. To add new operations to the language meant making the language homoiconic in some way, and yes, that meant using Python lists to make s-expressions. And yeah, you could compose with Python then. I think in most ways, Hy was a real lisp, just one that used cpython as a virtual machine. However, there are downsides to using a lisp on top of something that was never intended to be a lisp, which I learned the hard way. I tried writing a serious system in Hy, and eventually had to move to Guile instead. Why? Because once you have macros, it becomes very difficult to tell what line number you're on in (the level of transformations we did made it so we couldn't keep around that information by the time we got to the AST, and it was hard to reason about what was going on there). This meant debugging was nearly impossible, because when debugging in Python, line numbers is your primary context for determining where you are. I'm not just talking about pdb.set_trace() (though that too); even tracebacks became impossible to deal with. Thus Hy is a pretty cool toy to play with, and kind of nice for writing a quick DSL on top of Python. And it *has* proven that you could treat the Python AST as something to compile down to and have macros. But even there, it looked like lisp, and even once you had that, underlying decisions about the implementation you're building on top of can make things difficult. Still fun to work on though! Also a great community and a great route for Python type people who want to dip their toe into lisp-land. And a good chance to learn the above lessons the hard way. :) - Chris