X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginsh%2Fginsh_parser.yy;h=16601cee15d2e6792ec74446bcc37f77a5a6e070;hp=10383e8eb3fc81b05fa3f36d7c898fe6f9b01fef;hb=69ec860812569dbbfb9216907abbd22ff36ce54f;hpb=e6b8c3caae6f9877f27b67522390290ae936a112 diff --git a/ginsh/ginsh_parser.yy b/ginsh/ginsh_parser.yy index 10383e8e..16601cee 100644 --- a/ginsh/ginsh_parser.yy +++ b/ginsh/ginsh_parser.yy @@ -375,6 +375,13 @@ static ex f_evalf2(const exprseq &e) return e[0].evalf(ex_to(e[1]).to_int()); } +static ex f_find(const exprseq &e) +{ + lst found; + e[0].find(e[1], found); + return found; +} + static ex f_inverse(const exprseq &e) { CHECK_ARG(0, matrix, inverse); @@ -387,6 +394,19 @@ static ex f_is(const exprseq &e) return (bool)ex_to(e[0]) ? ex(1) : ex(0); } +class apply_map_function : public map_function { + ex apply; +public: + apply_map_function(const ex & a) : apply(a) {} + ex operator()(const ex & e) { return apply.subs(wild() == e, true); } +}; + +static ex f_map(const exprseq &e) +{ + apply_map_function fcn(e[1]); + return e[0].map(fcn); +} + static ex f_match(const exprseq &e) { lst repl_lst; @@ -510,6 +530,7 @@ static const fcn_init builtin_fcns[] = { {"evalf", fcn_desc(f_evalf2, 2)}, {"evalm", fcn_desc(f_evalm, 1)}, {"expand", fcn_desc(f_expand, 1)}, + {"find", fcn_desc(f_find, 2)}, {"gcd", fcn_desc(f_gcd, 2)}, {"has", fcn_desc(f_has, 2)}, {"inverse", fcn_desc(f_inverse, 1)}, @@ -518,6 +539,7 @@ static const fcn_init builtin_fcns[] = { {"lcoeff", fcn_desc(f_lcoeff, 2)}, {"ldegree", fcn_desc(f_ldegree, 2)}, {"lsolve", fcn_desc(f_lsolve, 2)}, + {"map", fcn_desc(f_map, 2)}, {"match", fcn_desc(f_match, 2)}, {"nops", fcn_desc(f_nops, 1)}, {"normal", fcn_desc(f_normal1, 1)},