Skip to content

clojure.core/list*

View this page on ClojureDocs

Type: function Added: Clojure 1.0 Examples: 5 Runnable: 3
([args] [a args] [a b args] [a b c args] [a b c d & more])

Creates a new seq containing the items prepended to the rest, the last of which will be treated as a sequence.

Examples

by Dimagog on . May have evaluation errors.
by Manishapillai on
by smnplk on
by arlicle on
by Chandrama1 on . May have evaluation errors.

Note by miner

The doc string mentions returning a new list, but it should say a new sequence. Surprisingly, list* typically does not return an actual list. Instead, it usually returns a Cons, which works as a seq, but is not strictly a list.

(list? (list* 1 '(2 3)))
;=> false

(type (list* 1 '(2 3)))
;=> clojure.lang.Cons

(first (list* 1 '(2 3)))
;=> 1

(peek (list* 1 '(2 3)))
ClassCastException clojure.lang.Cons cannot be cast to clojure.lang.IPersistentStack

(list? (list* '(2 3)))
;=> true

(list? (into () (list* 1 '(2 3))))
;=> true

I think seq* would have been a better name for this function.


Content from the matching ClojureDocs page, with authors credited on each contribution.