diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-03-12 12:27:57 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-03-12 12:27:57 -0700 |
commit | 6b7c80ff724f4f8baec2fc0984c6178f75fd9bcd (patch) | |
tree | 7d27494d2058e68d5a727387e810fbdd78a9237d | |
parent | 7809492815eb35df33e52aae72e03ce10349def5 (diff) | |
download | txr-6b7c80ff724f4f8baec2fc0984c6178f75fd9bcd.tar.gz txr-6b7c80ff724f4f8baec2fc0984c6178f75fd9bcd.tar.bz2 txr-6b7c80ff724f4f8baec2fc0984c6178f75fd9bcd.zip |
New: struct-from-plist and struct-from-args.
* struct.c (struct_init): Register new functions.
(struct_from_plist, struct_from_args): New functions.
* struct.h (struct_from_plist, struct_from_args): Declared.
* txr.1: Documented.
-rw-r--r-- | struct.c | 14 | ||||
-rw-r--r-- | struct.h | 2 | ||||
-rw-r--r-- | txr.1 | 45 |
3 files changed, 61 insertions, 0 deletions
@@ -131,6 +131,8 @@ void struct_init(void) reg_fun(intern(lit("struct-type-p"), user_package), func_n1(struct_type_p)); reg_fun(intern(lit("super"), user_package), func_n1(super)); reg_fun(intern(lit("make-struct"), user_package), func_n2v(make_struct)); + reg_fun(intern(lit("struct-from-plist"), user_package), func_n1v(struct_from_plist)); + reg_fun(intern(lit("struct-from-args"), user_package), func_n1v(struct_from_args)); reg_fun(intern(lit("make-lazy-struct"), user_package), func_n2(make_lazy_struct)); reg_fun(make_struct_lit_s, func_n2(make_struct_lit)); @@ -503,6 +505,18 @@ val make_struct(val type, val plist, struct args *args) return sinst; } +val struct_from_plist(val type, struct args *plist) +{ + val list = args_get_list(plist); + args_decl(boa, 0); + return make_struct(type, list, boa); +} + +val struct_from_args(val type, struct args *boa) +{ + return make_struct(type, nil, boa); +} + static void lazy_struct_init(val sinst, struct struct_inst *si) { val self = lit("make-lazy-struct"); @@ -33,6 +33,8 @@ val make_struct_type(val name, val super, val struct_type_p(val obj); val super(val type); val make_struct(val type, val plist, struct args *); +val struct_from_plist(val type, struct args *plist); +val struct_from_args(val type, struct args *boa); val make_lazy_struct(val type, val argfun); val make_struct_lit(val type, val plist); val copy_struct(val strct); @@ -23214,6 +23214,51 @@ invocation. Initialization of the structure proceeds as described in the description of .codn make-struct . +.coNP Functions @ struct-from-plist and @ struct-from-args +.synb +.mets (struct-from-plist < type >> { slot << value }*) +.mets (struct-from-arg < type << arg *) +.syne +.desc +The +.code struct-from-plist +and +.code struct-from-arg +are interfaces to the +.code make-struct +function. + +The +.code struct-from-plist +function passes its +.meta slot +and +.meta value +arguments as the +.meta slot-init-plist +argument of +.codn make-struct . +It passes no boa constructor arguments. + +The +.code struct-from-plist +function calls +.meta make-struct +with an empty +.metn slot-init-plist , +passing down the list of +.metn arg -s. + +The following equivalences hold: + +.cblk + (struct-from-plist a s0 v0 s1 v1 ...) + <--> (make-struct a (list s0 v0 s1 v1 ...)) + + (struct-from-args a v0 v1 v2 ...) + <--> (make-struct a nil v0 v1 v2 ...) +.cble + .coNP Function @ copy-struct .synb .mets (copy-struct << struct-obj ) |