implicit indexing on empty string

Q&A's, tips, howto's
Post Reply
jef
Posts: 11
Joined: Sun May 18, 2014 8:42 am

implicit indexing on empty string

Post by jef »

I'm surprised that implicit indexing doesn't raise an error
on an empty string (when called with 0 or -1), while it
does on an empty list:

> ("" 0)
""

> ("" -1)
""

With another index, we get an error as expected:
> ("" 1)

ERR: invalid string index

If we compare to implicit indexing on an empty list, we always
get an error:

> ('() 0)

ERR: invalid list index

>('() -1)

ERR: invalid list index

Any explanation for this?

(btw, thanks again Lutz, newLISP is a real pleasure to use)

Lutz
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: implicit indexing on empty string

Post by Lutz »

An empty string is not like an empy list:

Code: Select all

> (push "" "")
""
> (push '() '())
(())
> (atom? "")
true
> (atom? '())
nil
>
an empty list is still a container. The only alternative would be to return nil for ('() 0) - not the symbol nil but the boolaean value nil. This was done in early versions of newLISP. But while programming, it seemed to make more sense to throw an error message.

But still today:

Code: Select all

> (pop '())
nil
... practical for processing lists with pop.

There are other inconsistencies like this in newLISP: the function dup on lists and strings, nil as a boolean value and a symbol, treatment of () and nil - to name a few. When these conflicts occur in newLISP, they are normally decided by the occurrance of real world usage patterns and their practicality rather then trying to be consistent.

jef
Posts: 11
Joined: Sun May 18, 2014 8:42 am

Re: implicit indexing on empty string

Post by jef »

Lutz wrote:When these conflicts occur in newLISP, they are normally decided by the occurrance of real world usage patterns and their practicality rather then trying to be consistent.
Perfect, I see the point. Thanks for your detailed explanation!

Post Reply