FAQ
Hi,

Why keep both butlast and drop-last in clojure.core? The latter has the
advantage that it's lazy and can drop off more than one element from the
end of a seq. In contrast, I can't think of any advantage of butlast,
except that it seems to be slightly (ca 20%) faster than (doall (drop-last
x)). Wrapping drop-last in a doall should not be normally necessary, though.

Should butlast be deprecated?

Thanks,
Daniel

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Search Discussions

  • Nils Bertschinger at Nov 23, 2011 at 10:42 pm
    Hi,

    you're right that drop-last is more general than butlast. So why does
    butlast exist at all?
    I would say, that it is there for a very good reasons. It solves a
    common problem, namely to drop the last element of a sequence and
    reads better in this case than the equivalent idiom using drop-last.
    Thus, it is a perfect example for a useful abstraction and capturing
    common abstractions should be the main reason for defining functions
    (macros) in the first place. Obviously, any function (macro) could
    always be replaced by its definition, so it has to justify its
    existence by being reusable and improving readability. This also
    applies if it only captures a very special use case as long as it is
    common enough. I would say that butlast is well justified according to
    these criteria.

    Best,

    Nils
    On Nov 22, 12:54 pm, Daniel Janus wrote:
    Hi,

    Why keep both butlast and drop-last in clojure.core? The latter has the
    advantage that it's lazy and can drop off more than one element from the
    end of a seq. In contrast, I can't think of any advantage of butlast,
    except that it seems to be slightly (ca 20%) faster than (doall (drop-last
    x)). Wrapping drop-last in a doall should not be normally necessary, though.

    Should butlast be deprecated?

    Thanks,
    Daniel
    --
    You received this message because you are subscribed to the Google
    Groups "Clojure" group.
    To post to this group, send email to clojure@googlegroups.com
    Note that posts from new members are moderated - please be patient with your first post.
    To unsubscribe from this group, send email to
    clojure+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Daniel Janus at Nov 24, 2011 at 10:04 am

    On Wednesday, November 23, 2011 10:42:13 PM UTC, Nils Bertschinger wrote:


    It solves a
    common problem, namely to drop the last element of a sequence and
    reads better in this case than the equivalent idiom using drop-last.
    I don't quite get it. How does (butlast x) read better than (drop-last x)?

    (Granted, these two calls have slightly different semantics, the difference
    being laziness. However, the non-lazy version should not normally be
    required, or else we should have non-lazy versions of map, filter etc.)

    --
    You received this message because you are subscribed to the Google
    Groups "Clojure" group.
    To post to this group, send email to clojure@googlegroups.com
    Note that posts from new members are moderated - please be patient with your first post.
    To unsubscribe from this group, send email to
    clojure+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Nils Bertschinger at Nov 24, 2011 at 12:16 pm
    You're right. I still think to much in Common Lisp where butlast is
    quite handy, but basically resembles drop-last from clojure. I agree
    that the non-lazy semantics is probably not wanted in most cases. To
    stress this aspect a better name might be all-butlast or something
    like that.
    Feel free to not use butlast any more ...
    On Nov 24, 11:04 am, Daniel Janus wrote:
    On Wednesday, November 23, 2011 10:42:13 PM UTC, Nils Bertschinger wrote:
    It solves a
    common problem, namely to drop the last element of a sequence and
    reads better in this case than the equivalent idiom using drop-last.
    I don't quite get it. How does (butlast x) read better than (drop-last x)?
    PS: To me it reads slightly better (maybe more used to it), but the
    difference is minor and highly subjective. It sure reads better than
    (doall (drop-last x)) if that's what you want, but the name does not
    describe the laziness semantics (see above)
    (Granted, these two calls have slightly different semantics, the difference
    being laziness. However, the non-lazy version should not normally be
    required, or else we should have non-lazy versions of map, filter etc.)
    --
    You received this message because you are subscribed to the Google
    Groups "Clojure" group.
    To post to this group, send email to clojure@googlegroups.com
    Note that posts from new members are moderated - please be patient with your first post.
    To unsubscribe from this group, send email to
    clojure+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupclojure @
categoriesclojure
postedNov 22, '11 at 11:55a
activeNov 24, '11 at 12:16p
posts4
users2
websiteclojure.org
irc#clojure

2 users in discussion

Daniel Janus: 2 posts Nils Bertschinger: 2 posts

People

Translate

site design / logo © 2022 Grokbase