summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--struct.c14
-rw-r--r--struct.h2
-rw-r--r--txr.145
3 files changed, 61 insertions, 0 deletions
diff --git a/struct.c b/struct.c
index 5a0e4734..91e6807c 100644
--- a/struct.c
+++ b/struct.c
@@ -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");
diff --git a/struct.h b/struct.h
index 2f97ee8a..27e13621 100644
--- a/struct.h
+++ b/struct.h
@@ -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);
diff --git a/txr.1 b/txr.1
index d22c16ba..c6915a8f 100644
--- a/txr.1
+++ b/txr.1
@@ -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 )