noxdafox / clipspy

Python CFFI bindings for the 'C' Language Integrated Production System CLIPS
BSD 3-Clause "New" or "Revised" License
177 stars 32 forks source link

No gensym #24

Closed slozovsky closed 5 years ago

slozovsky commented 5 years ago

It looks like "gensym" is not exposed through API.

When an instance is created in CLIPS, instance name is optional.

$ clips
         CLIPS (6.30 3/17/15)
CLIPS> (defclass MyClass (is-a USER)
  (slot One (type INTEGER)(default 222))
  (slot Two))
CLIPS> (make-instance of MyClass)
[gen1]
CLIPS>

If instance name is not supplied, CLIPS calls (gensym) and generates a name ([gen1] in the example). It would be nice to have exactly the same behavior in clipspy.

As of now:

instance = klass.new_instance('')

would create an instance with an empty name. Pyclips would generate name in such case. Another option is use None as an indicator that clipspy should call (gensym).

There are work arounds for sure - it's easy for a user to generate some symbols by himself, but that would duplicate the feature already present in CLIPS.

noxdafox commented 5 years ago

As mentioned in issue #25, it is not possible to set a default name in CLIPS 6.30 classes C API.

In clipspy 6.40 I switched the instance name to keyword a argument. It now works as expected.

In [1]: import clips

In [2]: env = clips.Environment()

In [3]: env.build('(defclass MyClass (is-a USER) (slot Slot))')

In [4]: defclass = env.find_class('MyClass')

In [5]: defclass.make_instance(Slot=1)
Out[5]: Instance: [gen1] of MyClass (Slot 1)