Skip to content

remove-atom doesn't work when an atom contains a python object #1071

@bowen-xu

Description

@bowen-xu

Describe the bug
When an atom contains a python project, like (Item 1 2 <py-boject>), operationremove-atom doesn't work in some case.

See the code below.

!(bind! &my-space (new-space))

(= (add-item $x1 $x2)
    (add-atom &my-space (Item $x1 $x2 (py-tuple ($x1 $x2))))
)
(= (get-item $x1 $x2)
    (match &my-space (Item $x1 $x2 $x3) (Item $x1 $x2 $x3))
)
!(add-item 1 2)
!(get-item 1 2)
!(let $item (get-item 1 2)
    (remove-atom &my-space $item)
)
!(get-item 1 2)
!(remove-atom &my-space (Item 1 2 (py-tuple (1 2))))
!(get-item 1 2)

the output is

[()]
[()]
[(Item 1 2 (1, 2))]
[()]
[(Item 1 2 (1, 2))]
[()]
[]

This sentence !(let $item (get-item 1 2) (remove-atom &my-space $item)) does not really remove the item from the space.
Because !(get-item 1 2) after that produce [(Item 1 2 (1, 2))].

However, !(remove-atom &my-space (Item 1 2 (py-tuple (1 2)))) works well.

To compare, consider the following code

!(bind! &my-space (new-space))

(= (add-item $x1 $x2)
    (add-atom &my-space (Item $x1 $x2))
)
(= (get-item $x1 $x2)
    (match &my-space (Item $x1 $x2) (Item $x1 $x2))
)
!(add-item 1 2)
!(get-item 1 2)
!(let $item (get-item 1 2)
    (remove-atom &my-space $item)
)
!(get-item 1 2)

the output is

[()]
[()]
[(Item 1 2)]
[()]
[]

which shows that !(let $item (get-item 1 2) (remove-atom &my-space $item)) succesfully removes the item.
The only differnece is whether the atom contains a python object ((Item 1 2 (py-tuple (1 2))) vs (Item 1 2)).

In my application, I have to contain a python object in an atom. Is that a bug or not?

To Reproduce
Run the code snippets through https://metta-lang.dev/docs/playground/playground.html

Expected behavior
Given

!(bind! &my-space (new-space))

(= (add-item $x1 $x2)
    (add-atom &my-space (Item $x1 $x2 (py-tuple ($x1 $x2))))
)
(= (get-item $x1 $x2)
    (match &my-space (Item $x1 $x2 $x3) (Item $x1 $x2 $x3))
)
!(add-item 1 2)
!(get-item 1 2)
!(let $item (get-item 1 2)
    (remove-atom &my-space $item)
)
!(get-item 1 2)

the output should be

[()]
[()]
[(Item 1 2 (1, 2)]
[()]
[]

Actual behavior
However, the actual output is

[()]
[()]
[(Item 1 2 (1, 2))]
[()]
[(Item 1 2 (1, 2))]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions