OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace commits / deca4eb

Localize consistently
deca4eb0b5fe808c12e9ab6e1e81e27f3cd60203
by Linas Vepštas <linasvepstas@gmail.com> · 2026-01-23T22:02:24.000Z

Changed files (3) +20 -37

opencog/atoms/flow/StreamValueOfLink.cc +4 -17
……@@ -50,26 +50,14 @@ ValuePtr StreamValueOfLink::execute(AtomSpace* as, bool silent)
5050 if (2 != ary)
5151 throw SyntaxException(TRACE_INFO, "Expecting two atoms!");
5252
53 // We cannot know the Value of the Atom unless we are
54 // working with the unique version that sits in the
55 // AtomSpace! It can happen, during evaluation e.g. of
56 // a PutLink, that we are given an Atom that is not in
57 // any AtomSpace. In this case, `as` will be a scratch
58 // space; we can add the Atom there, and things will
59 // trickle out properly in the end.
60 //
61 Handle ah(as->add_atom(_outgoing[0]));
62 Handle ak(as->add_atom(_outgoing[1]));
63
64 ValuePtr stream = ah->getValue(ak);
53 ValuePtr stream(get_literal(as, silent));
6554 if (nullptr == stream)
6655 {
6756 if (silent)
6857 throw SilentException();
6958
7059 throw InvalidParamException(TRACE_INFO,
71 "No value at key %s on atom %s",
72 ak->to_string().c_str(), ah->to_string().c_str());
60 "No value for %s", to_string().c_str());
7361 }
7462
7563 if (stream->is_type(FLOAT_VALUE))
……@@ -104,9 +92,8 @@ ValuePtr StreamValueOfLink::execute(AtomSpace* as, bool silent)
10492 throw SilentException();
10593
10694 throw InvalidParamException(TRACE_INFO,
107 "Expecting a stream at key %s on atom %s, got %s",
108 ak->to_string().c_str(), ah->to_string().c_str(),
109 stream->to_string().c_str());
95 "Expecting a stream for %s, got %s",
96 to_string().c_str(), stream->to_string().c_str());
11097}
11198
11299DEFINE_LINK_FACTORY(StreamValueOfLink, STREAM_VALUE_OF_LINK)
opencog/atoms/flow/ValueOfLink.cc +15 -20
……@@ -64,6 +64,19 @@ void ValueOfLink::init(void)
6464
6565// ---------------------------------------------------------------
6666
67// ValueOf must work in the local AtomSpace. This includes
68// the evaluation of keys, as needed.
69Handle ValueOfLink::localize(AtomSpace* as, bool silent, const Handle& h) const
70{
71 if (not h->is_executable())
72 return as->add_atom(h);
73
74 ValuePtr pap(h->execute(as, silent));
75 if (pap and pap->is_atom())
76 return as->add_atom(HandleCast(pap));
77 return h;
78}
79
6780/// Return the literal value at the indicated key.
6881ValuePtr ValueOfLink::get_literal(AtomSpace* as, bool silent)
6982{
……@@ -82,26 +95,8 @@ ValuePtr ValueOfLink::get_literal(AtomSpace* as, bool silent)
8295 "Expecting AtomSpace, got null pointer for %s\n",
8396 to_string().c_str());
8497
85 Handle ah(as->add_atom(_outgoing[0]));
86 Handle ak(as->add_atom(_outgoing[1]));
87
88 // Get the concrete Atom
89 if (ah->is_executable())
90 {
91 ValuePtr pap(ah->execute(as, silent));
92 if (pap and pap->is_atom())
93 ah = as->add_atom(HandleCast(pap));
94 }
95
96 // It seems extremely unlikely (to me, at this time) that
97 // the key will arrive as the result of some kind of execution.
98 // But predicting the future is hard, so ...
99 if (ak->is_executable())
100 {
101 ValuePtr pap(ak->execute(as, silent));
102 if (pap and pap->is_atom())
103 ak = as->add_atom(HandleCast(pap));
104 }
98 Handle ah(localize(as, silent, _outgoing[0]));
99 Handle ak(localize(as, silent, _outgoing[1]));
105100
106101 return ah->getValue(ak);
107102}
opencog/atoms/flow/ValueOfLink.h +1 -0
……@@ -53,6 +53,7 @@ private:
5353 void init(void);
5454
5555protected:
56 Handle localize(AtomSpace*, bool, const Handle&) const;
5657 ValuePtr get_literal(AtomSpace*, bool);
5758 ValuePtr do_execute(AtomSpace*, bool);
5859