Clojure

interleave should accept 1 or 0 arguments

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Trivial Trivial
  • Resolution: Completed
  • Affects Version/s: Release 1.3
  • Fix Version/s: Release 1.6
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

interleave should handle 0 and 1 arguments in the same way that concat does (i.e., 0 args --> empty seq, 1 args --> identity).

Activity

Hide
Andy Fingerhut added a comment -

Patch clj-863-make-interleave-handle-odd-args-like-concat-patch-v1.txt dated Jan 1 2013 is identical to Joe Gallo's 0001-make-interleave-handle-odd-arugments-in-the-same-man.patch patch dated Oct 24 2011, except it returns () instead of (lazy-seq nil) as per Rich's comment. If concat should also return () instead of (lazy-seq nil), perhaps another ticket should be created to fix that. Also presumptuously changing ticket state from Incomplete back to Vetted, since the reason it was marked Incomplete should now be addressed, and it was Screened before.

Show
Andy Fingerhut added a comment - Patch clj-863-make-interleave-handle-odd-args-like-concat-patch-v1.txt dated Jan 1 2013 is identical to Joe Gallo's 0001-make-interleave-handle-odd-arugments-in-the-same-man.patch patch dated Oct 24 2011, except it returns () instead of (lazy-seq nil) as per Rich's comment. If concat should also return () instead of (lazy-seq nil), perhaps another ticket should be created to fix that. Also presumptuously changing ticket state from Incomplete back to Vetted, since the reason it was marked Incomplete should now be addressed, and it was Screened before.
Hide
Marc Dzaebel added a comment -

Yes, but my solution is too slow, as it uses "apply".

Show
Marc Dzaebel added a comment - Yes, but my solution is too slow, as it uses "apply".
Hide
Matthew O. Smith added a comment -

Marc's definition doesn't work for no arguments. Maybe:

(defn interleave
([] ())
([& s] (apply mapcat list s)))

Show
Matthew O. Smith added a comment - Marc's definition doesn't work for no arguments. Maybe: (defn interleave ([] ()) ([& s] (apply mapcat list s)))
Hide
Marc Dzaebel added a comment -

(defn interleave [& s] (apply mapcat list s))

Show
Marc Dzaebel added a comment - (defn interleave [& s] (apply mapcat list s))
Hide
Joe Gallo added a comment -

Hey Rich, if you're talking about the first line of the diff:

+ ([] (lazy-seq nil))

Then that's the implementation, not the tests – given an empty vector of arguments, return (lazy-seq nil), which I just copied from the existing definition of concat.

Cheers,
Joe

Show
Joe Gallo added a comment - Hey Rich, if you're talking about the first line of the diff: + ([] (lazy-seq nil)) Then that's the implementation, not the tests – given an empty vector of arguments, return (lazy-seq nil), which I just copied from the existing definition of concat. Cheers, Joe
Hide
Rich Hickey added a comment -

(lazy-seq nil) should be ()

Show
Rich Hickey added a comment - (lazy-seq nil) should be ()

People

Vote (5)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: