Skip to content

Commit

Permalink
Merge pull request #217 from Kray-G/develop
Browse files Browse the repository at this point in the history
Updated Functional.
  • Loading branch information
Kray-G committed Mar 5, 2021
2 parents 935d0e5 + 5d3189f commit c93ad34
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
25 changes: 24 additions & 1 deletion lib/std/kxfunctional.kx
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,27 @@ _function _functional_enumerator(e) {
};
}

Functional.enumerable = Functional.Enumerator.create = _functional_enumerator;
Functional.methodMissing = _function(_instance, method, ...a) {
Functional[method] = _function(...args) {
return _function(obj) {
return obj[method](...args);
};
};
return Functional[method](...a);
};

// The methods in Array such as `map` have to be assigned to this object
// because Array.map will have been called directly instead of this.map
// and methodMissing will not be called.
Array.keySet(Array).filter({ => Array[_1].isFunction }).each { &(method)
Functional[method] = _function(...args) {
return _function(obj) {
return obj[method](...args);
};
};
};

Functional.enumerable
= Functional.Enumerator.create
= _functional_enumerator
;
10 changes: 5 additions & 5 deletions lib/std/kxstartup.kx
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ var Xml, Net;
Net = _import('kxnet');
SQLite = _import('kxsqlite');
Debugger = _import('kxdebugger');
using kxsysutil;
using kxstring;
using kxarray;
using kxbinary;
using kxnumeric;
using kxisolate;
using kxexception;
using kxsqlite;
using kxxml;
using kxnet;
using kxenumerable;
using kxfunctional;
using kxsysutil;
using kxstring;
using kxarray;
using kxbinary;
using kxnumeric;
using kxfile;
using kxgetopt;
Zip.create = File._zipCreate;
Expand Down
2 changes: 1 addition & 1 deletion src/ast_gencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ LOOP_HEAD:;
KX_CANNOT_BE_LVALUE(node, "Key-vaule");
if (node->lhs->type == KXOP_SPREAD) {
gencode_ast_hook(ctx, node->lhs->lhs, ana, 0);
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_APPENDA }));\
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_APPENDA }));
} else {
gencode_ast_hook(ctx, node->lhs, ana, 0);
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_APPENDK, .value1 = { .s = const_str(ctx, node->value.s) } }));
Expand Down
8 changes: 1 addition & 7 deletions src/extlib/kxarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,14 +447,8 @@ int Array_flatten(int args, kx_frm_t *frmv, kx_frm_t *lexv, kx_context_t *ctx)
{
kx_obj_t *obj = get_arg_obj(1, args, ctx);
if (obj) {
int level = -1;
kx_obj_t *ary = allocate_obj(ctx);
if (args > 1) {
kx_val_t val = kv_last_by(ctx->stack, 2);
if (val.type == KX_INT_T) {
level = get_arg_int(2, args, ctx);
}
}
int level = args > 1 ? get_arg_int(2, args, ctx) : -1;
int r = Array_flatten_impl(args, ctx, ary, obj, 0, level);
if (r > 0) {
KX_ADJST_STACK();
Expand Down
4 changes: 2 additions & 2 deletions src/ir_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -6432,7 +6432,7 @@ void kx_try_spread(kx_context_t *ctx, kx_code_t *cur, kx_val_t *v1)
kx_obj_t *obj = v1->value.ov;
int len = kv_size(obj->ary);
if (len == 0) {
push_undef((ctx)->stack);
ctx->spread_additional--;
} else {
ctx->spread_additional += --len;
for (int i = len; i >= 0; --i) {
Expand All @@ -6443,7 +6443,7 @@ void kx_try_spread(kx_context_t *ctx, kx_code_t *cur, kx_val_t *v1)
kvec_t(uint8_t) *bin = &(v1->value.bn->bin);
int len = kv_size(*bin);
if (len == 0) {
push_undef((ctx)->stack);
ctx->spread_additional--;
} else {
ctx->spread_additional += --len;
for (int i = len; i >= 0; --i) {
Expand Down

0 comments on commit c93ad34

Please sign in to comment.