empty intervals Alex Shinn (21 Apr 2022 11:02 UTC)
Re: empty intervals Bradley Lucier (21 Apr 2022 16:30 UTC)
Re: empty intervals Bradley Lucier (21 Apr 2022 16:37 UTC)
Re: empty intervals Per Bothner (21 Apr 2022 19:23 UTC)
Re: empty intervals Bradley Lucier (21 Apr 2022 21:59 UTC)
Re: empty intervals Per Bothner (21 Apr 2022 22:11 UTC)
Re: empty intervals Bradley Lucier (23 Apr 2022 17:56 UTC)
Re: empty intervals Per Bothner (23 Apr 2022 19:44 UTC)
Re: empty intervals Alex Shinn (24 Apr 2022 05:03 UTC)
Re: empty intervals John Cowan (21 Apr 2022 22:56 UTC)
Re: empty intervals Alex Shinn (22 Apr 2022 09:03 UTC)

Re: empty intervals Per Bothner 21 Apr 2022 19:22 UTC

On 4/21/22 09:30, Bradley Lucier wrote:
> 1.  Empty lists, strings, vectors, etc., can be empty in only one way: they always have one "dimension", but there could be zero elements in that one dimension.  Arrays can be "degenerate" in at least two ways: there may be no dimensions, or there may be no indices in one or more dimensions.
>
> 2.  The case of zero dimensions seems easier to integrate into this proposal.  A zero-dimensional array would have one value.  But would a value be (uplifted to) a zero-dimensional array?  When would you return a zero-dimensional array containing a value, and when the value itself?  And would this definition be recursive?  Would a zero-dimensional array containing a zero-dimensional array containing ... a value be the same as that value?  Even numpy isn't consistent in how it handles these things.  (I'm not criticizing numpy for this, I'm just saying that I'd like to have a consistent semantics for this SRFI.)

I think it make sense to think of 'vector' as a special care of 'array', with dimension (rank) one.
This is what numerous languages do, including Kawa, Common Lisp, and APL.

If a vector is an array, and if we need to support 0-length vectors (and we do), then
arrays that have zero indices in more or more dimensions needs to be handled some some
more-or-less logically consistent way.

I claim SRFI-164 does this pretty well.

Zero dimensions is somewhat less useful and has its own issues.  As you indicate,
a rank-0 array has a single value which is one-to-one "similar" to that value.
APL treats them the same.  However, if the array is mutable, then note you can modify
the array but not the value.  So I think it makes sense to think of a 0-rank array
as equivalent to a "box" containing a value: A box is an array of dimension 0.
--
	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/