emacs-devel
[Top][All Lists]
Advanced

[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: Mon, 15 Jul 2013 07:20:07 +0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (windows-nt)

Lars Magne Ingebrigtsen <address@hidden> writes:

>>   (setq tag (cons "<p>" "</p>"))
>>
>>   (defun tag-desc (tag)
>>     (concat (upcase (car tag)) "."))
>>
>>   (defun tag-desc-stripped (tag)
>>     (upcase (replace-regexp-in-string "[<\\/> ]" "" (car tag))))
>>
>>   ;; with threading macros
>>   (defun tag-desc (tag)
>>     (-> (car tag) (upcase) (concat ".")))
>>
>>   (defun tag-desc-strip (tag)
>>     (->> (car tag) (replace-regexp-in-string "[<\\/> ]" "") (upcase)))
>
> It's not clear what the point of these are.  Just to make the code more
> obscure and cool?  The new forms (as demonstrated here) even leads to
> longer code, in addition to being pretty opaque.  While the "old" code
> is obvious and easy to read.

They're most useful with larger sequences of transformations. You may be
used to reading the code "inside out" by now, but threading operators
are easy to understand, and they make the flow of information much
more obvious.

>>   + make `let` work like `let*`: "let's" stop confusing newcomers.
>
> I don't think it's that confusing.  It would be more confusing having
> let and let* work differently in Emacs Lisp than in other Lisps, I
> think. 

I'd be willing to bet that Emacs Lisp newcomers originating from other
Lisp backgrounds are a distinct minority.

>>   + hash-tables: how come that working with hash-tables is such a pain?
>>     I love how they are function of themselves in clojure and that
>>     there's reader syntax for them.
>>
>>   (setq tags (make-hash-table))
>>   (puthash tags :p "</p>")
>>   (puthash tags :span "</span>")
>>   (gethash :span tags) ; -> "</p>"
>
> That's painful?  It seems clear and nice to me.
>
>>   ;; clojuresque version
>>   (setq tags {:p "</p>" :span "</span>"})
>>   (:p tags) ; -> "</p>"
>>   (tags :p) ; -> "</p>"
>>   (:html tags) ; -> nil
>
> This just seems like a "neat" way to write opaque code.  Did the Clojure
> people come from a Perl or Scheme background, by any chance?

Most of the adopters come from Java and Ruby, AFAIK. And JavaScript,
especially lately.

But, FYI, the first version of Clojure was written in Common Lisp.

I think the OP is missing the point here, though. While the combination
of Lisp-1 and virtual dispatch looks pretty, it's a non-starter for a
Lisp-2, which Emacs Lisp is.

Clojure's standard library is great even without those, for example take
a look at functions dealing with maps:
http://clojure.org/data_structures#Data Structures-Maps (IPersistentMap)

The API is quite dependent on maps being immutable, though, so it
wouldn't be easy to bring them to Emacs either.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]