trueagi-io / hyperon-experimental

MeTTa programming language implementation
https://metta-lang.dev
MIT License
153 stars 50 forks source link

Unexpected behavior which seems to be caused by caching. #553

Closed astroseger closed 10 months ago

astroseger commented 10 months ago

Let's define function which generate random number. For example via python binding.

from hyperon.atoms import OperationAtom
from hyperon.ext import register_atoms
import random

@register_atoms
def my_atoms():
    return {
        'random': OperationAtom('random', random.random),
    }

Save this in random_binding.py Now let's run the following metta script

!(extend-py! random_binding)

; will print False as expected
!(println! (== (random) (random)))

; will print False as expected
!(let $a (random) (let $b (random) (println! (== $a $b))))

(= (aa) (random)) 

; will print True... Seems to be a bug
!(println! (== (aa) (aa)))

; will print True... Seems to be a bug
!(let $a (aa) (let $b (aa) (println! (== $a $b))))

!(bind! a1 (aa))
!(bind! a2 (aa))

; will print False as expected 
!(println! (== a1 a2))
vsbogd commented 10 months ago

After discussion we decided leave caching as is as it may decrease performance. Caching is not used by minimal MeTTa interpreter and it will be more flexible on adding or removing it so I am closing it for now.