[Gambas-user] Collections and 0 values.
Jussi Lahtinen
jussi.lahtinen at gmail.com
Mon Nov 16 23:10:47 CET 2020
You can give null or 0 value for collection, just not null key. Just like
you cannot give a null index for an array.
All these are valid:
Dim hCol As New Collection
hCol.Add(0, "foo1")
hCol.Add(Null, "foo2")
hCol.Add(123, 0) ''The same as hCol.Add(123, "0")
Jussi
On Mon, Nov 16, 2020 at 9:35 PM Martin <mbelmonte at belmotek.net> wrote:
> Hi Tobias,
>
> Yes I actually use JSONCollection for that, my question was in a
> philosophical sense, just I want to know why is like this.
>
> Anyway, I will prepare a small sample project for fun.
>
> Regards.
>
> Martín.
>
> On 16/11/20 10:10, Tobias Boege wrote:
> > On Mon, 16 Nov 2020, Martin wrote:
> >> Hi,
> >>
> >> I'm using collecions to storage spatial data of some CAD entitites like
> >> lines, text, etc. one of the tags are the angle, in radians, then when
> if i
> >> want to storage non 0 values no problem, but when the angle is 0 the
> tag :
> >> value is not added.
> >>
> >> I have seen this behavior before in collections with null values and of
> >> course with 0 values, like the one I am trying to use now.
> >> The question is why is this defined like this? What sense does it make?
> >> Would it be possible to support 0 values by changing something in the
> >> configuration?
> >> If 0 is a valid value to start counting an array, why is it not valid to
> >> define a 0 value?
> >> Another related issue is settings, since it has the same behavior, what
> is
> >> the logic of this? the set of names of the variables that have value ""
> is
> >> lost.
> >> Thanks.
> >>
> > In Gambas, Null and the empty string are equivalent. Assigning Null to
> > a Collection key is the same as removing it. To emulate languages which
> > treat their analogues of "" and Null differently, you have to invent
> > your own sentinel Null value like it was done for JSON [1]. If you need
> > a Collection which stores Gambas Null values instead of taking this as
> > a cue to delete the key, you can use JSONCollection, despite its name.
> >
> > Null and the integer zero are not equivalent in Gambas and I doubt that
> > assigning coll[key] = 0 will delete key. Can you isolate the code you
> > have problems with into a very small test, which clearly shows what
> > you put it and what you expect to get out, without a great big project
> > and UI attached?
> >
> > Best,
> > Tobias
> >
> > [1] http://gambaswiki.org/wiki/comp/gb.web/json/null
> >
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201117/cf43eace/attachment-0001.htm>
More information about the User
mailing list