diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-02-09 07:45:05 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-02-09 07:45:05 -0800 |
commit | a52a10871b45806db86476fc17092368bcc5b1c3 (patch) | |
tree | e03fdd4f1ed7dd123fb3e55f4c23ecbae17c2c71 | |
parent | a824ded1de5099e860e119bec1d3a2ed5e12a1ba (diff) | |
download | txr-a52a10871b45806db86476fc17092368bcc5b1c3.tar.gz txr-a52a10871b45806db86476fc17092368bcc5b1c3.tar.bz2 txr-a52a10871b45806db86476fc17092368bcc5b1c3.zip |
struct: changing meaning of obj.[fun ...] syntax.
Until now, the obj.[fun ...] syntax has uselessly denoted
exactly the same thing as [obj.fun ...]. This latter syntax
is what should be used for that meaning.
The new meaning of obj.[fun ...] will be that it performs
method dispatch, where obj is passed to obj.fun as
the leftmost argument: obj.[fun ...] is [obj.fun obj ...],
with obj evaluated once.
* share/txr/stdlib/struct.tl (qref): Expansion change done
here, with backward compat switch.
* share/txr/stdlib/termios.tl (termios (go-raw, go-cbreak)):
Some a.[b c] turned to [a.b c] here.
* tests/012/oop.tl (animal print): Likewise.
* tests/012/struct.tl: Likewise, and some expansion tests
updated to reflect the new expansion.
* txr.1: Documentation revised in multiple places and compat
note added.
-rw-r--r-- | share/txr/stdlib/struct.tl | 14 | ||||
-rw-r--r-- | share/txr/stdlib/termios.tl | 8 | ||||
-rw-r--r-- | tests/012/oop.tl | 2 | ||||
-rw-r--r-- | tests/012/struct.tl | 10 | ||||
-rw-r--r-- | txr.1 | 46 |
5 files changed, 55 insertions, 25 deletions
diff --git a/share/txr/stdlib/struct.tl b/share/txr/stdlib/struct.tl index 64cd2e76..2eecfbc7 100644 --- a/share/txr/stdlib/struct.tl +++ b/share/txr/stdlib/struct.tl @@ -223,11 +223,21 @@ :)) (((dw sym . args)) (if (eq dw 'dwim) - ^[(slot ,obj ',(sys:check-slot form sym)) ,*args] + (let ((osym (gensym))) + (sys:check-slot form sym) + ^(slet ((,osym ,obj)) + ,(if (and (plusp sys:compat) (<= sys:compat 251)) + ^[(slot ,osym ',sym) ,*args] + ^[(slot ,osym ',sym) ,osym ,*args]))) :)) (((dw sym . args) . more) (if (eq dw 'dwim) - ^(qref [(slot ,obj ',(sys:check-slot form sym)) ,*args] ,*more) + (let ((osym (gensym))) + (sys:check-slot form sym) + ^(qref (slet ((,osym ,obj)) + ,(if (and (plusp sys:compat) (<= sys:compat 251)) + ^[(slot ,osym ',sym) ,*args] + ^[(slot ,osym ',sym) ,osym ,*args])) ,*more)) :)) (((sym . args)) (let ((osym (gensym))) diff --git a/share/txr/stdlib/termios.tl b/share/txr/stdlib/termios.tl index 93fcc958..5d2423dc 100644 --- a/share/txr/stdlib/termios.tl +++ b/share/txr/stdlib/termios.tl @@ -56,15 +56,15 @@ (if (boundp 'iexten) tio.(clear-lflags iexten)) tio.(set-cflags cs8) - (set tio.[cc vmin] 1) - (set tio.[cc vtime] 0)) + (set [tio.cc vmin] 1) + (set [tio.cc vtime] 0)) (defmeth termios go-cbreak (tio) tio.(clear-iflags icrnl) tio.(clear-lflags icanon) tio.(set-lflags isig) - (set tio.[cc vmin] 1) - (set tio.[cc vtime] 0)) + (set [tio.cc vmin] 1) + (set [tio.cc vtime] 0)) (defmeth termios string-encode (tio) (let ((*print-base* 16)) diff --git a/tests/012/oop.tl b/tests/012/oop.tl index 51dadbf3..ac93790f 100644 --- a/tests/012/oop.tl +++ b/tests/012/oop.tl @@ -2,7 +2,7 @@ (defstruct animal nil (:function whoami () "n/a") - (:method print (self stream : pretty-p) (put-string self.[whoami] stream))) + (:method print (self stream : pretty-p) (put-string [self.whoami] stream))) (defstruct dog animal (:function whoami () "dog")) diff --git a/tests/012/struct.tl b/tests/012/struct.tl index 9de3f832..88f37e4d 100644 --- a/tests/012/struct.tl +++ b/tests/012/struct.tl @@ -31,9 +31,9 @@ (test (expand 's.a) (slot s 'a)) (test (expand 's.[a]) - [(slot s 'a)]) + [(slot s 'a) s]) (test (expand 's.[a b c]) - [(slot s 'a) b c]) + [(slot s 'a) s b c]) (set *gensym-counter* 0) (stest (ignwarn (expand 's.(a))) @@ -44,9 +44,9 @@ "(call (slot s 'a)\n \ \ s b c)") (test (expand 's.[a].d) - (slot [(slot s 'a)] 'd)) + (slot [(slot s 'a) s] 'd)) (test (expand 's.[a b c].d) - (slot [(slot s 'a) b c] 'd)) + (slot [(slot s 'a) s b c] 'd)) (set *gensym-counter* 0) (stest (ignwarn (expand 's.(a).d)) "(slot (call (slot s 'a)\n \ @@ -104,7 +104,7 @@ (stest bz "#S(baz array #(1 2 3) increment #<interpreted fun: lambda (self which delta)>)") -(test bz.[array 2] 3) +(test [bz.array 2] 3) (test bz.(increment 0 42) 43) (test bz.array #(43 2 3)) (test [(meth bz increment) 1 5] 7) @@ -26727,9 +26727,9 @@ is visible. Consequently, may be used to terminate the execution of the function and return a value. Such functions are called using the -.code "instance.[name arg ...]" -syntax which doesn't insert the instance into -the argument list. +.code "(call instance.name arg ...)" +or else the DWIM brackets syntax +.codn "[instance.name arg ...]" . The remarks about inheritance and overriding in the description of @@ -27422,13 +27422,18 @@ is evaluated only once: (qref o (n arg ...)) <--> (call (slot o 'n) o arg ...) .brev -A DWIM designator indicates that the named slot is a function or an -indexable or callable object. The following equivalence applies: +A DWIM designator similarly indicates that the named slot is a function, +and arguments are to be applied to it. The following equivalence applies: .verb - (qref obj [name arg ...]) <--> [(slot obj 'name) arg ...] + (qref obj [name arg ...]) <--> [(slot obj 'name) o arg ...] .brev +Therefore, under this equivalence, this syntax provides the usual Lisp-1-style +evaluation rule via the +.code dwim +operator. + If the .meta object-form has the syntax @@ -27468,7 +27473,7 @@ is the slot not accessed, but the argument expressions are not evaluated. (defvarl s (new foo)) ;; access third element of s.array: - s.[array 2] --> 3 + [s.array 2] --> 3 ;; increment first element of array by 42 s.(increment 0 42) --> 43 @@ -29120,11 +29125,12 @@ which may be used to invoke them, such as: .mets << object .(function-name < arg << ... ) .brev -However, those introduced as "Function" do not operate on an instance. For -brevity, their syntax is nevertheless exemplified as +However, those introduced as "Function" do not operate on an instance. +Their syntax is likewise indicated using the notation that may be used +to invoke them: .verb -.mets << object .'['function-name < arg << ... ']' +.mets <> '[' object .function-name < arg << ... ']' .brev If such a invocation is actually used, the @@ -29133,7 +29139,7 @@ instance only serves for identifying the struct type whose static slot .code function-name provides the function; .meta object -doesn't participate in the call. An object is not required since +doesn't participate in the call. An object is not strictly required since the function can be called using .verb @@ -29543,7 +29549,7 @@ is invoked. .coNP Function @ from-list .synb -.mets << object .'['from-list << list ']' +.mets <> '[' object .from-list << list ']' .syne .desc If a @@ -29574,7 +29580,7 @@ will always return a plain list of items. .coNP Function @ derived .synb -.mets << object .'['derived < supertype << subtype ']' +.mets <> '[' object .derived < supertype << subtype ']' .syne .desc If a structure type supports a function called @@ -77530,6 +77536,20 @@ of these version values, the described behaviors are provided if is given an argument which is equal or lower. For instance .code "-C 103" selects the behaviors described below for version 105, but not those for 102. +.IP 251 +Until \*(TX 251, the syntax +.code "obj.[fun arg]" +was equivalent to +.codn "[obj.fun arg]" , +providing little utility. +A compatibility value of 251 or lower restores that behavior. The new +behavior is that +.code "obj.[fun arg]" +is equivalent to +.codn "obj.[fun obj arg]" , +with +.code obj +evaluated only once, performing method dispatch. .IP 248 Until \*(TX 248, the .code hash-revget |