Skip to content

Commit c93ad34

Browse files
authored
Merge pull request #217 from Kray-G/develop
Updated Functional.
2 parents 935d0e5 + 5d3189f commit c93ad34

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

lib/std/kxfunctional.kx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,27 @@ _function _functional_enumerator(e) {
114114
};
115115
}
116116

117-
Functional.enumerable = Functional.Enumerator.create = _functional_enumerator;
117+
Functional.methodMissing = _function(_instance, method, ...a) {
118+
Functional[method] = _function(...args) {
119+
return _function(obj) {
120+
return obj[method](...args);
121+
};
122+
};
123+
return Functional[method](...a);
124+
};
125+
126+
// The methods in Array such as `map` have to be assigned to this object
127+
// because Array.map will have been called directly instead of this.map
128+
// and methodMissing will not be called.
129+
Array.keySet(Array).filter({ => Array[_1].isFunction }).each { &(method)
130+
Functional[method] = _function(...args) {
131+
return _function(obj) {
132+
return obj[method](...args);
133+
};
134+
};
135+
};
136+
137+
Functional.enumerable
138+
= Functional.Enumerator.create
139+
= _functional_enumerator
140+
;

lib/std/kxstartup.kx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ var Xml, Net;
2222
Net = _import('kxnet');
2323
SQLite = _import('kxsqlite');
2424
Debugger = _import('kxdebugger');
25+
using kxsysutil;
26+
using kxstring;
27+
using kxarray;
28+
using kxbinary;
29+
using kxnumeric;
2530
using kxisolate;
2631
using kxexception;
2732
using kxsqlite;
2833
using kxxml;
2934
using kxnet;
3035
using kxenumerable;
3136
using kxfunctional;
32-
using kxsysutil;
33-
using kxstring;
34-
using kxarray;
35-
using kxbinary;
36-
using kxnumeric;
3737
using kxfile;
3838
using kxgetopt;
3939
Zip.create = File._zipCreate;

src/ast_gencode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ LOOP_HEAD:;
11501150
KX_CANNOT_BE_LVALUE(node, "Key-vaule");
11511151
if (node->lhs->type == KXOP_SPREAD) {
11521152
gencode_ast_hook(ctx, node->lhs->lhs, ana, 0);
1153-
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_APPENDA }));\
1153+
kv_push(kx_code_t, get_block(module, ana->block)->code, ((kx_code_t){ FILELINE(ana), .op = KX_APPENDA }));
11541154
} else {
11551155
gencode_ast_hook(ctx, node->lhs, ana, 0);
11561156
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) } }));

src/extlib/kxarray.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,14 +447,8 @@ int Array_flatten(int args, kx_frm_t *frmv, kx_frm_t *lexv, kx_context_t *ctx)
447447
{
448448
kx_obj_t *obj = get_arg_obj(1, args, ctx);
449449
if (obj) {
450-
int level = -1;
451450
kx_obj_t *ary = allocate_obj(ctx);
452-
if (args > 1) {
453-
kx_val_t val = kv_last_by(ctx->stack, 2);
454-
if (val.type == KX_INT_T) {
455-
level = get_arg_int(2, args, ctx);
456-
}
457-
}
451+
int level = args > 1 ? get_arg_int(2, args, ctx) : -1;
458452
int r = Array_flatten_impl(args, ctx, ary, obj, 0, level);
459453
if (r > 0) {
460454
KX_ADJST_STACK();

src/ir_util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6432,7 +6432,7 @@ void kx_try_spread(kx_context_t *ctx, kx_code_t *cur, kx_val_t *v1)
64326432
kx_obj_t *obj = v1->value.ov;
64336433
int len = kv_size(obj->ary);
64346434
if (len == 0) {
6435-
push_undef((ctx)->stack);
6435+
ctx->spread_additional--;
64366436
} else {
64376437
ctx->spread_additional += --len;
64386438
for (int i = len; i >= 0; --i) {
@@ -6443,7 +6443,7 @@ void kx_try_spread(kx_context_t *ctx, kx_code_t *cur, kx_val_t *v1)
64436443
kvec_t(uint8_t) *bin = &(v1->value.bn->bin);
64446444
int len = kv_size(*bin);
64456445
if (len == 0) {
6446-
push_undef((ctx)->stack);
6446+
ctx->spread_additional--;
64476447
} else {
64486448
ctx->spread_additional += --len;
64496449
for (int i = len; i >= 0; --i) {

0 commit comments

Comments
 (0)