

A million lines of Lisp - muriithi
http://psung.blogspot.com/2008/06/million-lines-of-lisp.html

======
ajross
This kind of loses me towards the end. I mean, sure, emacs is a freakishly
large lisp program. I get that part. But, what's the point here?

The abstractions in emacs (modes and hooks are the ones discussed in the
linked post) really aren't that strange, or unique, or even lisp-specific. Nor
are they without analogs in other tools written in conventional imperative
languages. An emacs written in python, frankly, wouldn't look that different.
A mode by any other name would hook as smooth.

~~~
ken
You're right that the features he mentioned seemed to not be terribly unique
to Lisp.

But note that your claim wasn't really true before Python 2.5 (less than 2
years old). Imagine trying to write one of Emacs Lisp's most common special
forms, save-excursion, in Python without context managers.

Even (especially!) Python programmers would admit that Python 2.5 is more
powerful than Python 2.4. Emacs has a million lines of Lisp written with this
feature not easily emulated in Python 2.4. The Lisp in my Emacs here uses
save-excursion 9000 times; is there any Python program in the world that uses
context managers 9000 times yet?

I'm impressed that a 20+-year-old language can hold its own with a 21st-
century one under active development by somebody willing to (somewhat) break
backwards compatibility. That's not to say that Elisp was this great 20 years
ago -- it had, what, one kind of loop? -- but macros let it grow in directions
that its users wanted. You can't really add editing-specific features with
custom syntax to Python.

~~~
jrockway
save-excursion could just be a function though. Here's what the implementation
would look like. I don't know Python syntax, so I'll use Lisp, but I'll keep
Python's featureset in mind. No macros, no lambdas.

    
    
      (defun save-excursion (function)
          (let ((point (point))
                (mark (mark))
                ...)
            (funcall 'function)
            (set-mark mark)
            (goto-char point)))
    

Then you would say:

    
    
      (defun do-something nil (...))
      (save-excursion 'do-something)
    

Ideal, no. Possible, yes.

~~~
jrockway
That should be (funcall function). I shouldn't post code before I have coffee
:)

------
JesseAldridge
Ok, this is probably me being ignorant, but can't you do stuff like this to
get macros in Python:

    
    
        import os, subprocess
    
        def macro(string, filename="~/macro.py"):
            program_name = os.path.expanduser(filename)
            out = open(program_name, 'w')
            out.write(string)
            out.close()
            command = ["python"]
            command.append(program_name)
            subprocess.Popen(command)
    
        macro("print 'Hello macro!'")
    

It seems like with a bit of ingenuity you could achieve any level of
abstraction using a technique like that.

~~~
Hexstream
Nice Lisp macro features your naive scheme lacks:

\- Lisp macros are expanded implicitly at compile-time so you don't have a big
mess of temporary files;

\- Lisp macro calls look just like the built-in operators, unlike your
proposed "python macros" where all your macro invocations are a string

\- For all but the most trivial cases your string-based scheme will force you
to use concatenation and it will really get ugly really fast. In contrast,
with Lisp it's much easier to represent code as data. For example, (+ 1 2) is
the code to add 1 and 2 while '(+ 1 2) is a list representing the code to add
1 and 2 and you can then interpolate that easily in the generated code

\- And your example is really awesomely constrained, it works but it also
doesn't really help with anything. With Lisp, the macro facility scales from
trivial problems where the macro code fits in 4 lines to very complex ones
where the macro code spans 4 files.

~~~
gaius
This is one reason I like Tcl, it's not far off Lisp in the sense that it's a
"programmable programming language" and I can get away with using it at work
because they think it's just fancy shell-script :-)

For an example see <http://wiki.tcl.tk/917>

------
brandonkm
I've been really interested in Lisp lately, for someone that knows next to
nothing about this language, this is a pretty interesting read.

