implicit indexing on empty string

Started by jef, October 13, 2014, 12:51:54 PM

Previous topic - Next topic

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

#1
An empty string is not like an empy list:



> (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:

> (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

#2
Quote from: "Lutz"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!