Hacker News new | past | comments | ask | show | jobs | submit login

In Common Lisp I might want to push elements to an array, and start with zero elements:

  CL-USER 9 > (make-array 0 :adjustable t :fill-pointer 0)
  #()

  CL-USER 10 > (vector-push-extend 'foobar *)
  0

  CL-USER 11 > **
  #(FOOBAR)



An adjustable vector probably doesn't qualify as an "array" in the Java sense of the term: it's closer to an ArrayList. However Lisp is perfectly comfortable making zero-length simple-vectors, which are arrays in the Java sense.


An ArrayList is not an Array?

> comfortable making zero-length simple-vectors

Btw., CL allows also zero-dimensional arrays:

  CL-USER 3 > (make-array '())
  #0ANIL


> An ArrayList is not an Array?

Not in Java, no.

An ArrayList is an object which represents a variable length random-access list and does not support basic types (int, double etc.) An array is fixed-length and supports basic types. It is not an object per se.

The closest analog to an ArrayList in Lisp is an extensible vector, and the closest analog to an array is a simple-vector.

> Btw., CL allows also zero-dimensional arrays:

As any decent language would!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: