| … | … | @@ -50,26 +50,14 @@ ValuePtr StreamValueOfLink::execute(AtomSpace* as, bool silent) |
| 50 | 50 | if (2 != ary) |
| 51 | 51 | throw SyntaxException(TRACE_INFO, "Expecting two atoms!"); |
| 52 | 52 | |
| 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)); | |
| 65 | 54 | if (nullptr == stream) |
| 66 | 55 | { |
| 67 | 56 | if (silent) |
| 68 | 57 | throw SilentException(); |
| 69 | 58 | |
| 70 | 59 | 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()); | |
| 73 | 61 | } |
| 74 | 62 | |
| 75 | 63 | if (stream->is_type(FLOAT_VALUE)) |
| … | … | @@ -104,9 +92,8 @@ ValuePtr StreamValueOfLink::execute(AtomSpace* as, bool silent) |
| 104 | 92 | throw SilentException(); |
| 105 | 93 | |
| 106 | 94 | 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()); | |
| 110 | 97 | } |
| 111 | 98 | |
| 112 | 99 | DEFINE_LINK_FACTORY(StreamValueOfLink, STREAM_VALUE_OF_LINK) |
| … | … | @@ -64,6 +64,19 @@ void ValueOfLink::init(void) |
| 64 | 64 | |
| 65 | 65 | // --------------------------------------------------------------- |
| 66 | 66 | |
| 67 | // ValueOf must work in the local AtomSpace. This includes | |
| 68 | // the evaluation of keys, as needed. | |
| 69 | Handle 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 | ||
| 67 | 80 | /// Return the literal value at the indicated key. |
| 68 | 81 | ValuePtr ValueOfLink::get_literal(AtomSpace* as, bool silent) |
| 69 | 82 | { |
| … | … | @@ -82,26 +95,8 @@ ValuePtr ValueOfLink::get_literal(AtomSpace* as, bool silent) |
| 82 | 95 | "Expecting AtomSpace, got null pointer for %s\n", |
| 83 | 96 | to_string().c_str()); |
| 84 | 97 | |
| 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])); | |
| 105 | 100 | |
| 106 | 101 | return ah->getValue(ak); |
| 107 | 102 | } |
| … | … | @@ -53,6 +53,7 @@ private: |
| 53 | 53 | void init(void); |
| 54 | 54 | |
| 55 | 55 | protected: |
| 56 | Handle localize(AtomSpace*, bool, const Handle&) const; | |
| 56 | 57 | ValuePtr get_literal(AtomSpace*, bool); |
| 57 | 58 | ValuePtr do_execute(AtomSpace*, bool); |
| 58 | 59 |