[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Sweeter Emacs Lisp
From: |
Dmitry Gutov |
Subject: |
Re: Sweeter Emacs Lisp |
Date: |
Wed, 17 Jul 2013 00:23:29 +0400 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 |
On 15.07.2013 9:03, Stephen J. Turnbull wrote:
If you find
(defun tag-desc-stripped (tag)
(upcase (replace-regexp-in-string "[<\\/> ]" "" (car tag))))
hard to read,
This is still a trivial example. And no, now I don't, having spent a
couple of years or so writing Elisp. But I still remember that reading
functions "from inside out" was one of the harder parts, especially with
the level of nesting that one can often observe in core Emacs packages.
Look, for example, at `calculate-lisp-indent'.
Here are some appreciative opinions with better examples:
http://blog.8thlight.com/colin-jones/2011/03/27/clojure-mad-science-an-evil-threading-macro-experiment.html
http://debasishg.blogspot.ru/2010/04/thrush-in-clojure.html
http://thecomputersarewinning.com/post/Clojure-Thrush-Operator/
And this breaks C-x C-e badly.
No more than using local variables, I'd say. Except when you're using
something like `edebug' in dynamic scoping mode (with lexical scoping,
`edebug' doesn't see local vars yet).
> This isn't just a matter of loss of
convenience; it's a symptom of a major syntax change. It breaks *any*
code analysis tool.
I don't see how. The analysis tools have to expand macros anyway, or
they would stumble and break when encountering any macro not from a
predefined set.
And it is unnecessary, except for saving some
keystrokes. You could imagine
(defun threaded-apply-to-1 (arg &rest list-of-fun)
;; actually, just `apply-to' is probably sufficiently mnemonic
(while list-of-fun
(setq arg (funcall (pop list-of-fun) arg)))
arg)
(defun tag-desc-stripped (tag)
(threaded-apply-to-1 tag
#'car
(lambda (x) (replace-regexp-in-string "[<\\/> ]" "" x))
#'upcase))
That style makes me slightly ill, but (1) it's more general than `->'
and `->>' combined, and (2) it doesn't turn malformed function calls
into curried functions implicitly. So it doesn't break C-x C-e and
other tools that depend on the simplicity of Lisp expression syntax.
True, that's also an option. Here's an implementation in Clojure[0]:
(defn thrush [a & args]
((apply comp (reverse args)) a))
Incidentally, Clojure has a shorter reader macro for anonymous
functions. Yours would look like this:
#(replace-regexp-in-string "[<\\/> ]" "" %)
And being a Lisp-1, it doesn't need the hash-quotes before the other
arguments.
[0] http://blog.fogus.me/2010/09/28/thrush-in-clojure-redux/
- Re: Sweeter Emacs Lisp, (continued)
Re: Sweeter Emacs Lisp, Miles Bader, 2013/07/15
Re: Sweeter Emacs Lisp, Josh, 2013/07/14
Re: Sweeter Emacs Lisp, Stefan Monnier, 2013/07/15