#include <opencog/comprehension.h>
using namespace opencog;
std::vector<int> ivec = {1,2,3,4}; auto ovec = vector_comp(ivec, [](int x) { return (float)x + 1; });
// ovec == {2.0,3.0,4.0,5.0}
#include <opencog/util/comprehension.h>
using namespace opencog;
std::vector<int> ivec = {1,2,3,4}; auto ovec = vector_comp(ivec, [](int x) { return (float)x + 1; }, [](int x) { return x%2; });
// ovec == {2.0,4.0}
--
You received this message because you are subscribed to the Google Groups "opencog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to opencog+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/opencog?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Very cool!Why not put this in GitHub as a standalone library? It seems very desirable for all kinds of projects, not just opencog.
Very cool!Why not put this in GitHub as a standalone library? It seems very desirable for all kinds of projects, not just opencog.
Can I ask for a name change, from vector_comp to map_vector/map_set/map_list ?
This is to closer to the industry-standard naming convention for these functions; so for example, srfi-1 provides a details description of what they are and how they work for lisp, and it seemed like both CaML and Haskell use names that are very nearly identical to those used in srfi-1.so for example, the above describes:map proc clist1 clist2 ... -> list
proc is a procedure taking as many arguments as there are list arguments and returning a single value. map applies proc element-wise to the elements of the lists and returns a list of the results, in order.
Thus, in C++, it should be called map_vector, map_set, etc. (why not map<typename> where typename is a container?)
for-each proc clist1 clist2 ... -> unspecified
The arguments to for-each are like the arguments to map, but for-each calls proc for its side effects rather than for its values. Unlike map, for-each is guaranteed to call proc on the elements of the lists in order from the first element(s) to the last, and the value returned by for-each is unspecified.
Well, In C++, we already have something called for_each which is similar, not the same.What you are now describing is this:filter-map f clist1 clist2 ... -> listLike map, but only true values are saved.The below could be useful, I imagine.filter pred list -> listReturn all the elements of list that satisfy predicate pred. The list is not disordered -- elements that appear in the result list occur in the same order as they occur in the argument list.
which makes me unsure we need my hacking...
I'm confused about what to use at that point.
--linas
On Wed, May 15, 2013 at 8:38 PM, Linas Vepstas <linasv...@gmail.com> wrote:
Can I ask for a name change, from vector_comp to map_vector/map_set/map_list ?
This is to closer to the industry-standard naming convention for these functions; so for example, srfi-1 provides a details description of what they are and how they work for lisp, and it seemed like both CaML and Haskell use names that are very nearly identical to those used in srfi-1.so for example, the above describes:map proc clist1 clist2 ... -> list
proc is a procedure taking as many arguments as there are list arguments and returning a single value. map applies proc element-wise to the elements of the lists and returns a list of the results, in order.
Thus, in C++, it should be called map_vector, map_set, etc. (why not map<typename> where typename is a container?)+1 for map<typename>, ofc!!!!