OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace commits / d15dfe5

Simplify ElementOfLink when returning one element
d15dfe5c978dea1ac5d3315598bc5674598fcecd
by Linas Vepštas <linasvepstas@gmail.com> · 2026-01-21T21:14:57.000Z

Changed files (1) +14 -0

opencog/atoms/reduct/ElementOfLink.cc +14 -0
……@@ -86,6 +86,10 @@ ValuePtr ElementOfLink::do_execute(const std::vector<double>& vindex,
8686 HandleSeq chopped;
8787 for (double d : vindex)
8888 chopped.push_back(oset.at((int)(d+0.5)));
89
90 // If user asked for just one thing, hand them that one thing.
91 if (1 == chopped.size())
92 return chopped[0];
8993 return createLink(std::move(chopped), vitype);
9094 }
9195
……@@ -96,6 +100,16 @@ ValuePtr ElementOfLink::do_execute(const std::vector<double>& vindex,
96100 std::vector<ValuePtr> chopped;
97101 for (double d : vindex)
98102 chopped.push_back(lvec.at((int)(d+0.5)));
103
104 // Special case "hack". This feels both ugly, and natural.
105 // Ugly, because it breaks with the rhythm below, where
106 // everything gets wrapped. Natural, because if the user
107 // asked for just one thing, we should give them ... just
108 // one thing. Re-wrapping it forces the user to then take
109 // another step to unwrap it. Anyway, this is an important
110 // enough design decision, that I write it up, here.
111 if (1 == chopped.size())
112 return chopped[0];
99113 return createLinkValue(std::move(chopped));
100114 }
101115