all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Christopher Allan Webber <cwebber@dustycloud.org>
To: Random832 <random832@fastmail.com>
Cc: emacs-tangents@gnu.org, emacs-devel@gnu.org
Subject: Re: Python vs Lisp (followups to -tangents)
Date: Wed, 16 Dec 2015 11:56:24 -0600	[thread overview]
Message-ID: <8737v2mfph.fsf@dustycloud.org> (raw)
In-Reply-To: <n4cugl$sb5$1@ger.gmane.org>

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



  parent reply	other threads:[~2015-12-16 17:56 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-28 23:29 First draft of the Emacs website Nicolas Petton
2015-11-28 23:51 ` Jean-Christophe Helary
2015-11-29  0:03 ` Daniel Pimentel
2015-11-29  1:02 ` Xue Fuqiao
2015-11-29  1:26   ` Nicolas Petton
2015-11-29  2:19     ` Alex Dunn
2015-11-29  3:31       ` Jean-Christophe Helary
2015-11-29  5:42         ` Random832
2015-11-29  8:15           ` David Caldwell
2015-11-29 14:25             ` Dmitry Gutov
2015-11-30 17:49             ` Emacs for Mac OS X bundle (was: First draft of the Emacs website) John Wiegley
2015-11-30 20:02               ` Emacs for Mac OS X bundle David Caldwell
2015-12-01  0:15                 ` Xue Fuqiao
2015-12-01  1:40                   ` David Caldwell
2015-11-30  0:02     ` First draft of the Emacs website Xue Fuqiao
2015-11-29  8:06 ` Przemysław Wojnowski
2015-11-29 10:27   ` Zack Piper
2015-11-29 12:36     ` Rasmus
2015-11-29 12:58       ` Nicolas Petton
2015-11-29 14:00       ` Marcin Borkowski
2015-11-29 10:15 ` David Engster
2015-11-29 12:56   ` Nicolas Petton
2015-11-29 15:17 ` Dmitry Gutov
2015-11-29 19:38   ` Nicolas Petton
2015-11-29 22:01     ` Dmitry Gutov
2015-11-29 22:11       ` Nicolas Petton
2015-11-29 16:21 ` Christopher Allan Webber
2015-11-29 19:39   ` Nicolas Petton
2015-11-29 21:45 ` Artur Malabarba
2015-11-29 22:11   ` Nicolas Petton
2015-11-30  0:04     ` Artur Malabarba
2015-11-30  1:29       ` Alex Dunn
2015-11-30  9:43         ` Artur Malabarba
2015-11-30 10:33           ` Dani Moncayo
2015-11-30 15:22             ` Drew Adams
2015-11-30 16:06   ` Nicolas Petton
2015-11-30 16:16     ` Yuri Khan
2015-11-30 16:23       ` Nicolas Petton
2015-12-01 14:37     ` Richard Stallman
2015-12-01 14:56       ` Nicolas Petton
2015-11-30 19:48 ` Milan Zamazal
2015-12-02 16:45   ` Drew Adams
2015-12-02 17:22     ` Nicolas Petton
2015-12-02 16:36 ` Random832
2015-12-02 17:12   ` Nicolas Petton
2015-12-02 18:07     ` Yuri Khan
2015-12-02 18:26       ` Nicolas Petton
2015-12-02 18:29       ` Nicolas Petton
2015-12-02 18:30         ` Yuri Khan
2015-12-02 23:47   ` Xue Fuqiao
2015-12-04  3:57     ` Random832
2015-12-04  5:17       ` License of the Emacs website (was: Re: First draft of the Emacs website) Chad Brown
2015-12-04  5:42         ` Random832
2015-12-05  0:19       ` First draft of the Emacs website Richard Stallman
2015-12-03 13:58 ` Clément Pit--Claudel
2015-12-03 22:17   ` John Yates
2015-12-03 22:30     ` Nicolas Petton
2015-12-03 22:57     ` Drew Adams
2015-12-03 23:26       ` John Yates
2015-12-04  0:58         ` Drew Adams
2015-12-08 13:05           ` Valentijn
2015-12-08 15:09             ` Drew Adams
2015-12-08 15:21               ` Spencer Boucher
2015-12-08 16:08                 ` David Kastrup
2015-12-08 20:52                 ` Marcin Borkowski
2015-12-08 21:51                   ` Drew Adams
2015-12-08 21:58                     ` Drew Adams
2015-12-09 21:00                     ` Marcin Borkowski
2015-12-10  5:28                     ` Richard Stallman
2015-12-10  9:10                       ` David Kastrup
2015-12-10  5:27                   ` Richard Stallman
2015-12-10 16:13                     ` Python vs Lisp (followups to -tangents) Random832
2015-12-10 18:40                       ` Sam Steingold
2015-12-10 22:31                         ` Random832
2015-12-16 15:57                           ` Sam Steingold
2015-12-16 16:32                             ` Random832
2015-12-16 17:56                           ` Christopher Allan Webber [this message]
2015-12-09  6:06                 ` First draft of the Emacs website Richard Stallman
2015-12-04  6:06         ` David Kastrup
2015-12-04  9:37           ` Eli Zaretskii
2015-12-04  9:42             ` David Kastrup
2015-12-04 10:11               ` Eli Zaretskii
2015-12-04 10:42                 ` Nicolas Petton
2015-12-04 10:44                 ` David Kastrup
2015-12-04 11:03                   ` Eli Zaretskii
2015-12-04 22:26                   ` Paul Eggert
2015-12-04 22:30                     ` David Kastrup
2015-12-04  8:42         ` Eli Zaretskii
2015-12-03 23:59     ` Clément Pit--Claudel

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=8737v2mfph.fsf@dustycloud.org \
    --to=cwebber@dustycloud.org \
    --cc=emacs-devel@gnu.org \
    --cc=emacs-tangents@gnu.org \
    --cc=random832@fastmail.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 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.