summaryrefslogtreecommitdiffstats
path: root/txr.1
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-10-16 21:47:12 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-10-16 21:47:12 -0700
commit5fb5509d8d5a4bb0646b1beb083be6b6a6ec55d1 (patch)
tree2fdcd060e1efbf25fdf672da54056e73f02606b9 /txr.1
parentadeabf115e33a3a2efdf04c6a33fdebccb876ce9 (diff)
downloadtxr-5fb5509d8d5a4bb0646b1beb083be6b6a6ec55d1.tar.gz
txr-5fb5509d8d5a4bb0646b1beb083be6b6a6ec55d1.tar.bz2
txr-5fb5509d8d5a4bb0646b1beb083be6b6a6ec55d1.zip
Adding defmeth macro and static-slot-ensure.
* share/txr/stdlib/struct.tl (defmeth): New macro. * struct.c (struct struct_type): New member, dvtypes. (struct_init): Register static-slot-ensure intrinsic. (make_struct_type): Initialize dvtypes of newly instantiated struct_type struct. If a super is specified, add new type to the super's dvtypes. (struct_type_mark): Mark st->dvtypes. (static_slot_ensure): New function. * struct.h (static_slot_ensure): Declared. * txr.1: Documented defmeth and static-slot-ensure.
Diffstat (limited to 'txr.1')
-rw-r--r--txr.181
1 files changed, 81 insertions, 0 deletions
diff --git a/txr.1 b/txr.1
index b662380c..1072bb04 100644
--- a/txr.1
+++ b/txr.1
@@ -18246,6 +18246,40 @@ syntax.
(new (point 1) x 5 y 5) -> #S(point x 1 y 5)
.cble
+.coNP Macro @ defmeth
+.synb
+.mets (defmeth < type-name < name <> param-list << body-form *)
+.syne
+.desc
+The
+.code defmeth
+macro installs a function into the static slot named by the symbol
+.meta name
+in the struct type indicated by
+.metn type-name .
+
+If the structure type doesn't already have such a static slot, it is
+first added, as if by the
+.code static-slot-ensure
+function, subject to the same checks.
+
+If the function has at least one argument, it can be used as a method. In that
+situation, the leftmost argument passes the structure instance on which the
+method is being invoked.
+
+The function takes the arguments specified
+by the
+.meta param-list
+symbols, and its body consists of the
+.metn body-form -s.
+
+The
+.metn body-form -s
+are placed into a
+.code block
+named
+.codn name .
+
.coNP Macro @ new
.synb
.mets (new >> { name | >> ( name << arg *)} >> { slot << init-form }*)
@@ -19108,6 +19142,53 @@ argument must be a structure type, and
.meta name
must be a static slot of this type.
+.coNP Function @ static-slot-ensure
+.synb
+.mets (static-slot-ensure < type < name < new-value <> [ no-error-p ])
+.syne
+.desc
+The
+.code static-slot-ensure
+function is similar to
+.codn static-slot-set .
+
+It
+.meta new-value
+into the static slot named by symbol
+.meta name
+of the structure type
+.metn type ,
+if there already exists such a static slot.
+
+If the slot does not exist, it is first added to
+the struct type, provided that
+.meta name
+is a bindable symbol. Moreover,
+the struct type must not already have
+an instance slot by that name,
+unless the
+.meta no-error-p
+parameter is specified and true.
+If the
+.meta no-error-p
+parameter is true, then the function does
+not throw an error and does not create a
+static slot.
+
+The function returns
+.metn new-value .
+
+Note: if structure types already exist which are derived from
+.metn type ,
+.code static-slot-ensure
+is recursively invoked on each derived type to ensure that these
+types also have this static slot and it is given the specified value. The
+.meta no-error-p
+parameter is
+.code nil
+in these recursive calls, so that the static slot is only added
+to those structures which do not already have an instance slot.
+
.coNP Function @ call-super-method
.synb
.mets (call-super-method < struct-obj < name << argument *)