• (pop coll)
For a list or queue, returns a new list/queue without the first
item, for a vector, returns a new vector without the last item. If
the collection is empty, throws an exception. Note - not the same
as next/butlast.

1 Example top

  • user=> (peek [1 2 3])
    3
    user=> (pop [1 2 3])
    [1 2]
    user=> (peek '(1 2 3))
    1
    user=> (pop '(1 2 3))
    (2 3)
Log in to add / edit an example.

See Also top

  • 1
    clojure.core/peek

    For a list or queue, same as first, for a vector, same as, but much

  • 0
    clojure.core/rest

    Returns a possibly empty seq of the items after the first. Calls seq

  • 0
    clojure.core/conj

    conj[oin]. Returns a new collection with the xs 'added'. (conj ni

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:1366 top

(defn pop
  "For a list or queue, returns a new list/queue without the first
  item, for a vector, returns a new vector without the last item. If
  the collection is empty, throws an exception.  Note - not the same
  as next/butlast."
  {:added "1.0"
   :static true}
  [coll] (. clojure.lang.RT (pop coll)))
Vars in clojure.core/pop:
Used in 0 other vars

Comments top

1 comment(s) for pop.

Small reminder:


Do not work for arbitrary seq but just for persistent types implementing clojure.lang.IPersistentStack (like clojure.lang.Persistent*).


Example:

user> (pop (cons 1 '()))
; Evaluation aborted.

do not work because type is clojure.lang.Cons but

user> (pop (conj '() 1))
()

works because type is clojure.lang.PersistentList.

Log in to add a comment.