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

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1390
Joined: Sun Feb 14, 2010 7:11 pm

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

Post 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.
User avatar
jPV
Posts: 734
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

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

Post 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
Bugala
Posts: 1390
Joined: Sun Feb 14, 2010 7:11 pm

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

Post 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.
User avatar
airsoftsoftwair
Posts: 5830
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

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

Post 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.
Post Reply