SoarGroup / Soar

Soar, a general cognitive architecture for systems that exhibit intelligent behavior.
http://soar.eecs.umich.edu
Other
332 stars 71 forks source link

SML API silently converts null attribute names to empty strings #485

Closed garfieldnate closed 1 month ago

garfieldnate commented 3 months ago

When you pass null as the attribute name when you create a WME via the SML API, it is automatically converted into the empty string ("") without issuing any warnings.

import Python_sml_ClientInterface as sml
k = sml.Kernel.CreateKernelInNewThread()
a = k.CreateAgent("foo")
link = a.GetInputLink()
link.CreateIntWME(None, 1)
a.ExecuteCommandLine("step")
a.ExecuteCommandLine("p -d 2 i2")

The output is (I2 ^ 1) (which is not great output syntax, see https://github.com/SoarGroup/Soar/issues/484).

On the one hand, the empty string is really the only logical possible value here, but on the other hand it is a silent conversion and has a high likelihood of being a bug of some sort. It would be difficult to throw an error now, because that would break existing code, but I think printing a warning is warranted.

PLatCIC commented 3 months ago

You could also make the attribute name be |nil|.

garfieldnate commented 1 month ago

I will go with converting to nil (plus printing a warning), based on the existing behavior exhibited below:

sp {foo
    (state <s> ^superstate nil ^superstate <sup>)
    -->
    (<s> ^<sup> hi)
}
step
p s1

The output is:

(S1 ^epmem E1 ^io I1 ^nil hi
       ^reward-link R1 ^smem L1 ^superstate nil ^type state)