Page 1 of 1

In RemoveItem() and InsertItem() NIL = 0, Is this a feature or a bug?

Posted: Thu Nov 14, 2024 5:32 pm
by Bugala
I know that NIL often is 0, but since I am quite often using a system where I put args to function with idea that some of them might not exist, like as example something like this:

Code: Select all

Function My_InsertItem(Table, Item, Pos)
InsertItem(Table, Item, Pos)
EndFunction
then in practice mostly meant to be used:

Code: Select all

My_InsertItem(Table, Item)
Leaving the POS completely out, and only used when needed.

This have worked quite well in my functions but now that the InsertItem and RemoveItem treat NIL as 0, it makes me need to make an extra check of if it really is Nil first, I am therefore wondering that is this actually a supposed behavior or accidental, for after all, quite many commands in Hollywood are using NIL as an option, like MakeButton(NIL...), and if you put instead 0, then it doesn't do same as NIL.

Re: In RemoveItem() and InsertItem() NIL = 0, Is this a feature or a bug?

Posted: Fri Nov 15, 2024 9:22 am
by jPV
Hmm yeah.. it seems that InsertItem takes the last one as a given argument even if it would be Nil. I guess the argument count is based on commas rather than contents... maybe generally too and not just with these special cases?

I guess you should do something like this (assign a default value if its Nil):

Code: Select all

Function My_InsertItem(Table, Item, Pos)
	If IsNil(Pos) Then Pos = -1
	InsertItem(Table, Item, Pos)
EndFunction

Re: In RemoveItem() and InsertItem() NIL = 0, Is this a feature or a bug?

Posted: Sat Nov 16, 2024 1:43 pm
by Bugala
Yeah, did that.

Was just wondering if this is supposed behavior or accidental, since it seemed a bit odd when considering that Nil is often an option in other commands.

Re: In RemoveItem() and InsertItem() NIL = 0, Is this a feature or a bug?

Posted: Sat Nov 23, 2024 12:18 am
by airsoftsoftwair
Bugala wrote: Sat Nov 16, 2024 1:43 pm Was just wondering if this is supposed behavior or accidental, since it seemed a bit odd when considering that Nil is often an option in other commands.
Actually, the rule of thumb is that Nil evaluates to 0. Explicitly using Nil as a parameter is only used very rarely, for example in the context of automatic ID selection.