OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace commits / 1fa8dbc

Bug-fix SetValue; keys were not being localized.
1fa8dbc5e1db54956b6e18254330b2c81013ee80
by Linas Vepštas <linasvepstas@gmail.com> · 2026-01-23T19:37:19.000Z

Changed files (2) +40 -6

opencog/atoms/flow/SetValueLink.cc +37 -6
……@@ -43,19 +43,50 @@ SetValueLink::SetValueLink(const HandleSeq&& oset, Type t)
4343
4444// ---------------------------------------------------------------
4545
46// SetValue must work in the local AtomSpace. This includes
47// the evaluation of keys, as needed.
48Handle SetValueLink::localize(AtomSpace* as, bool silent, const Handle& h) const
49{
50 if (not h->is_executable())
51 return as->add_atom(h);
52
53 ValuePtr pap(h->execute(as, silent));
54 if (pap and pap->is_atom())
55 return as->add_atom(HandleCast(pap));
56 return h;
57}
58
4659/// When executed, this will execute the third argument to obtain
4760/// a Value, and then set that Value at the indicated key on the
4861/// first argument. The computed value is returned.
4962/// The SetValueOn link returns the Atom, not the Value.
5063ValuePtr SetValueLink::execute(AtomSpace* as, bool silent)
5164{
65 // We cannot know the Value of the Atom unless we are
66 // working with the unique version that sits in the
67 // AtomSpace! It can happen, during evaluation e.g. of
68 // a PutLink, that we are given an Atom that is not in
69 // any AtomSpace. In this case, `as` will be a scratch
70 // space; we can add the Atom there, and things will
71 // trickle out properly in the end.
72 //
73 // Avoid null-pointer deref due to user error.
74 // This can happen with improperly built FilterLinks.
75 if (nullptr == as)
76 throw RuntimeException(TRACE_INFO,
77 "Expecting AtomSpace, got null pointer for %s\n",
78 to_string().c_str());
79
80 Handle ah(localize(as, silent, _outgoing[0]));
81 Handle ak(localize(as, silent, _outgoing[1]));
82
5283 // Default VoidValue
5384 if (2 == _outgoing.size())
5485 {
5586 ValuePtr pap(createVoidValue());
56 as->set_value(_outgoing[0], _outgoing[1], pap);
87 as->set_value(ah, ak, pap);
5788 if (SET_VALUE_ON_LINK == get_type())
58 return _outgoing[0];
89 return ah;
5990 return pap;
6091 }
6192
……@@ -68,10 +99,10 @@ ValuePtr SetValueLink::execute(AtomSpace* as, bool silent)
6899 else
69100 pap = _outgoing[2];
70101
71 as->set_value(_outgoing[0], _outgoing[1], pap);
102 as->set_value(ah, ak, pap);
72103
73104 if (SET_VALUE_ON_LINK == get_type())
74 return _outgoing[0];
105 return ah;
75106 return pap;
76107 }
77108
……@@ -99,10 +130,10 @@ ValuePtr SetValueLink::execute(AtomSpace* as, bool silent)
99130 else
100131 fsp = createFutureStream(exo);
101132
102 as->set_value(_outgoing[0], _outgoing[1], fsp);
133 as->set_value(ah, ak, fsp);
103134
104135 if (SET_VALUE_ON_LINK == get_type())
105 return _outgoing[0];
136 return ah;
106137 return fsp;
107138}
108139
opencog/atoms/flow/SetValueLink.h +3 -0
……@@ -37,6 +37,9 @@ namespace opencog
3737///
3838class SetValueLink : public FunctionLink
3939{
40protected:
41 Handle localize(AtomSpace*, bool, const Handle&) const;
42
4043public:
4144 SetValueLink(const HandleSeq&&, Type=SET_VALUE_LINK);
4245