mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-09 22:54:03 +09:00
basic: 'barely working' foldl function
This commit is contained in:
@@ -1057,18 +1057,38 @@ if no arg text were given (e.g. "10 NEXT"), args will have zero length
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
"DATA" : function() { /*DATA must do nothing when encountered; they must be pre-processed*/ },
|
"DATA" : function() { /*DATA must do nothing when encountered; they must be pre-processed*/ },
|
||||||
|
/* Syopsis: MAP function, functor
|
||||||
|
*/
|
||||||
"MAP" : function(lnum, args) {
|
"MAP" : function(lnum, args) {
|
||||||
return twoArg(lnum, args, (fn, functor) => {
|
return twoArg(lnum, args, (fn, functor) => {
|
||||||
// TODO test only works with DEFUN'd functions
|
// TODO test only works with DEFUN'd functions
|
||||||
if (fn.astLeaves === undefined) throw lang.badFunctionCallFormat("Only works with DEFUN'd functions yet");
|
if (fn.astLeaves === undefined) throw lang.badFunctionCallFormat("Only works with DEFUN'd functions yet");
|
||||||
if (functor.toArray === undefined && !isArray(functor)) throw lang.syntaxfehler(lnum, functor);
|
if (functor.toArray === undefined && !Array.isArray(functor)) throw lang.syntaxfehler(lnum, functor);
|
||||||
|
|
||||||
// generator?
|
// generator?
|
||||||
if (functor.toArray) functor = functor.toArray();
|
if (functor.toArray) functor = functor.toArray();
|
||||||
|
|
||||||
return functor.map(it => bStatus.getDefunThunk(lnum, fn)(lnum, [it]));
|
return functor.map(it => bStatus.getDefunThunk(lnum, fn)(lnum, [it]));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
/* Synopsis: FOLD function, init_value, functor
|
||||||
|
* a function must accept two arguments, of which first argument will be an accumulator
|
||||||
|
*/
|
||||||
|
"FOLD" : function(lnum, args) {
|
||||||
|
return threeArg(lnum, args, (fn, init, functor) => {
|
||||||
|
// TODO test only works with DEFUN'd functions
|
||||||
|
if (fn.astLeaves === undefined) throw lang.badFunctionCallFormat("Only works with DEFUN'd functions yet");
|
||||||
|
if (functor.toArray === undefined && !Array.isArray(functor)) throw lang.syntaxfehler(lnum, functor);
|
||||||
|
// generator?
|
||||||
|
if (functor.toArray) functor = functor.toArray();
|
||||||
|
|
||||||
|
let akku = init;
|
||||||
|
functor.forEach(it => {
|
||||||
|
akku = bStatus.getDefunThunk(lnum, fn)(lnum, [akku, it]);
|
||||||
|
});
|
||||||
|
|
||||||
|
return akku;
|
||||||
|
});
|
||||||
|
},
|
||||||
"OPTIONDEBUG" : function(lnum, args) {
|
"OPTIONDEBUG" : function(lnum, args) {
|
||||||
return oneArgNum(lnum, args, (lh) => {
|
return oneArgNum(lnum, args, (lh) => {
|
||||||
if (lh != 0 && lh != 1) throw lang.syntaxfehler(line);
|
if (lh != 0 && lh != 1) throw lang.syntaxfehler(line);
|
||||||
|
|||||||
Reference in New Issue
Block a user