summaryrefslogtreecommitdiffstats
path: root/struct.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-10-09 19:08:02 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-10-09 19:08:02 -0700
commit2d173febd859a05708e14273397df61f75bea895 (patch)
tree966808b96729f9f367301f88256376b66d1738f6 /struct.c
parent0bb1f829c745d94386f17f37ed5568a20c7243e9 (diff)
downloadtxr-2d173febd859a05708e14273397df61f75bea895.tar.gz
txr-2d173febd859a05708e14273397df61f75bea895.tar.bz2
txr-2d173febd859a05708e14273397df61f75bea895.zip
Support curried args in method and meth.
* share/txr/stdlib/struct.tl (meth): Take trailing arguments and pass them down to method, which now accepts them. * struct.c (struct_init): Register method intrinsic to the function method_args instead of the method function. (method_args_fun): New static function. (method_args): New function. Behaves like method function if args is empty, otherwise creates a function by means of method_args_fun. * struct.h (method_args_fun): Declared. * tests/012/oop.tl: New test case. * tests/012/oop.expected: Updated. * txr.1: Documented new features in method and meth, revising the documentation in the process.
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/struct.c b/struct.c
index 61ce4174..559dbb0e 100644
--- a/struct.c
+++ b/struct.c
@@ -151,7 +151,7 @@ void struct_init(void)
reg_fun(intern(lit("static-slot-p"), user_package), func_n2(static_slot_p));
reg_fun(intern(lit("structp"), user_package), func_n1(structp));
reg_fun(intern(lit("struct-type"), user_package), func_n1(struct_type));
- reg_fun(intern(lit("method"), user_package), func_n2(method));
+ reg_fun(intern(lit("method"), user_package), func_n2v(method_args));
reg_fun(intern(lit("super-method"), user_package), func_n2(super_method));
reg_fun(intern(lit("uslot"), user_package), func_n1(uslot));
reg_fun(intern(lit("umethod"), user_package), func_n1v(umethod));
@@ -1106,11 +1106,34 @@ static val method_fun(val env, varg args)
return generic_funcall(fun, args_copy);
}
+static val method_args_fun(val env, varg args)
+{
+ cons_bind (curried_args, fun_strct, env);
+ cons_bind (fun, strct, fun_strct);
+ cnum ca_len = c_num(length(curried_args));
+ args_decl(args_call, max(args->fill + 1 + ca_len, ARGS_MIN));
+ args_add(args_call, strct);
+ args_add_list(args_call, curried_args);
+ args_normalize(args_call, ca_len + 1);
+ args_cat_zap(args_call, args);
+ return generic_funcall(fun, args_call);
+}
+
val method(val strct, val slotsym)
{
return func_f0v(cons(slot(strct, slotsym), strct), method_fun);
}
+val method_args(val strct, val slotsym, struct args *args)
+{
+ if (!args_more(args, 0))
+ return func_f0v(cons(slot(strct, slotsym), strct), method_fun);
+ else
+ return func_f0v(cons(args_get_list(args),
+ cons(slot(strct, slotsym), strct)), method_args_fun);
+}
+
+
val super_method(val strct, val slotsym)
{
val super_slot = static_slot(super(struct_type(strct)), slotsym);