Skip to content

Commit f5c2c45

Browse files
committed
[Untested] Replace ors in destruct-> examples with ||
Applied to one argument, the empty invocation is an identity transform, compiling as operation-ordering parentheses. This is arguably a bit simpler than alternatives like ors, which requires a macroexpansion (and that the macro be in scope), although that only adds a comment, or worse alternatives, like doto, which compile to a lambda.
1 parent 8fbdead commit f5c2c45

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

docs/macro_tutorial.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6490,7 +6490,7 @@ There are various ways to check for errors if you want to be strict about it:
64906490
#.. (.pop 'file sys..stdout) file
64916491
#.. (.pop 'flush False) flush
64926492
#.. (.values) values
6493-
#.. (-> .keys list !#-1) (ors last-key
6493+
#.. (-> .keys list !#-1) (|| last-key
64946494
#.. type last-key-type))
64956495
#.. (unless (is_ last-key-type int)
64966496
#.. (throw (TypeError (.format "{!r} is an invalid keyword argument" last-key))))

src/hissp/macros.lissp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3929,15 +3929,15 @@ sentinel#
39293929
;; .. code-block:: REPL
39303930
;;
39313931
;; #> (destruct-> nested-data
3932-
;; #.. (!#'ns (ors ns ; The whole SimpleNamespace (progn works too).
3932+
;; #.. (!#'ns (|| ns ; Identity transform. ->, progn, doto, etc. also work.
39333933
;; #.. (getattr 'missing "a default for missing") missing
39343934
;; #.. @#'spam inner ; attribute lookup
39353935
;; #.. @#'a-tuple ([#:-1] ab [#:] abc ; slices with overlaps
39363936
;; #.. iter (next A list rest) ; iterator destructuring
39373937
;; #.. ;; Composed transform, method calls, defaults.
39383938
;; #.. (-> enumerate dict) ((.get 2 ()) two
39393939
;; #.. (.get 3 ()) three)
3940-
;; #.. ;; Throwaway names must be unique. (`$#_ always works).
3940+
;; #.. ;; Throwaway names must be unique. (`,$#_ always works).
39413941
;; #.. iter (next _0 (next :b) B next _1 (next :d) D)))
39423942
;; #.. (.get 'quux "default for quux") myquux)
39433943
;; #.. (pprint..pp (locals)))
@@ -4091,8 +4091,8 @@ sentinel#
40914091
;; .. code-block:: REPL
40924092
;;
40934093
;; #> (destruct-> (dict : spam 1 foo 2)
4094-
;; #.. (ors whole
4095-
;; #.. ors !s#(spam foo))
4094+
;; #.. (|| whole
4095+
;; #.. || !s#(spam foo))
40964096
;; #.. (print whole spam foo))
40974097
;; >>> # destructQzH_QzGT_
40984098
;; ... # hissp.macros.._macro_.letQzH_from
@@ -4144,8 +4144,8 @@ sentinel#
41444144
;; .. code-block:: REPL
41454145
;;
41464146
;; #> (destruct-> (types..SimpleNamespace : spam 1 foo 2)
4147-
;; #.. (ors whole
4148-
;; #.. ors @s#(spam foo))
4147+
;; #.. (|| whole
4148+
;; #.. || @s#(spam foo))
41494149
;; #.. (print whole spam foo))
41504150
;; >>> # destructQzH_QzGT_
41514151
;; ... # hissp.macros.._macro_.letQzH_from
@@ -4197,7 +4197,7 @@ sentinel#
41974197
;; .. code-block:: REPL
41984198
;;
41994199
;; #> (destruct-> '(ABC XYZ)
4200-
;; #.. (ors whole ors pos#(abc pos#(x y)))
4200+
;; #.. (|| whole || pos#(abc pos#(x y)))
42014201
;; #.. (print whole abc x y))
42024202
;; >>> # destructQzH_QzGT_
42034203
;; ... # hissp.macros.._macro_.letQzH_from

0 commit comments

Comments
 (0)