On Tue, Oct 9, 2012 at 10:33 AM, Tassilo Horn <[email protected]> wrote:
> Larry Travis <[email protected]> writes:
>
>> and the definition of _list*_ seems to me to be complete without it.
>
> No. It makes
>
> (list* 1 2 3 4 5 [6 7] [8 9]) => (1 2 3 4 5 [6 7] 8 9)
>
> else it would result in (1 2 3 4 5 [6 7] [8 9]), i.e., it implements the
> special meaning of list*'s last parameter.
I took Larry's comment to mean that one could implement list* without
spread, which is true; you just need to change (spread more) to (apply
list* more). In fact apply is defined just below list* and makes use
of both spread and list*, but that's ok:
user> (declare list+)
#'user/list+
user> (defn apply+
([^clojure.lang.IFn f args]
(. f (applyTo (seq args))))
([^clojure.lang.IFn f x args]
(. f (applyTo (list+ x args))))
([^clojure.lang.IFn f x y args]
(. f (applyTo (list+ x y args))))
([^clojure.lang.IFn f x y z args]
(. f (applyTo (list+ x y z args))))
([^clojure.lang.IFn f a b c d & args]
(. f (applyTo (cons a (cons b (cons c (cons d (apply+ list+ args)))))))))
#'user/apply+
user> (defn list+
([args] (seq args))
([a args] (cons a args))
([a b args] (cons a (cons b args)))
([a b c args] (cons a (cons b (cons c args))))
([a b c d & more]
(cons a (cons b (cons c (cons d (apply+ list+ more)))))))
#'user/list+
user> (list+ 1 2 3 4 5 [6 7] [8 9])
(1 2 3 4 5 [6 7] 8 9)
list+ is slower than list*, though.
--
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks,
which may be sweet, aromatic, fermented or spirit-based. ... Family
and social life also offer numerous other occasions to consume drinks
for pleasure." [Larousse, "Drink" entry]
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en