opencog / atomspace

The OpenCog (hyper-)graph database and graph rewriting system
https://wiki.opencog.org/w/AtomSpace
Other
817 stars 229 forks source link

FloatValue Example gives exception #3022

Closed sikefield3 closed 1 year ago

sikefield3 commented 1 year ago

https://github.com/opencog/atomspace/blob/7518fd6368ac1334bb1e4b8ffa1eac2734e5b336/examples/atomspace/stream.scm#L32

If I try this demo (as suggested by pasting into the scheme prompt), I get the following exception:

scheme@(guile-user)> (define tym (Times (Plus vo (Number 6)) (Number 2)))
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Atomspace C++ exception:
(cog-new-link Types fail to agree, invalid Atom syntax: (PlusLink
  (ValueOfLink
    (Concept "my atom") ; [76add31d335f92fd][1]
    (Predicate "key") ; [4d3044146f8f9e][1]
  ) ; [be7c19b73ae377fb][1]
  (Number "6") ; [5cc45d477a189359][1]
) ; [eec16813a22c91ac][-1] (/home/opcwdir/repodock/atomspace/opencog/atoms/base/ClassServer.cc:179)
Function args:
((ValueOf
  (Concept "my atom")
  (Predicate "key"))
 (Number "6")
))

There is a similar line below this, which gives the same error.
It could be in my environment (missing library or something...), but it doesn't look like that, since I have only encountered one other issue: A segmentation fault in a demo that makes use of two atomspaces, which seems unrelated to me.

linas commented 1 year ago

Thanks! In this location, FloatValueOf should be used since values might also be strings, lists or other atoms. The strict type-checking was added after this example was written. The type checking error message should be improved, I guess...

I'm trying to fix all this now.

linas commented 1 year ago

The first half of the fix is in afce40e7f6863f4017eb10d35f6231c5e8d214e6 and this just changes the example to use FloatValueOf

The second half of the fix is in ded13fb1b8a884c178e6bb80e6c19ec97ef7daaf and this requires the AtomSpace to be recompiled and reinstalled. This one declares that StreamValueOf (lower down in the example) can return numbers, thus keeping the arithmetic links happy about the types they are getting.

Static typing seems like a great idea, but it sure does cause pain. On the other hand runtime typechecking is hard to debug, when the types are wrong. Pick your poison...