Skip to content

Commit

Permalink
Use new fragment syntax in macros.lissp
Browse files Browse the repository at this point in the history
  • Loading branch information
gilch committed Jan 1, 2024
1 parent 01d3053 commit 0bfa47a
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions src/hissp/macros.lissp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Hidden doctest adds bundled macros for REPL-consistent behavior.

See also: `when`, `cond`, `any-map <anyQz_map>`, `if_expr`.
"
`((lambda ,'bca .#"c()if b else a()") ; boolean, consequent, alternate
`((lambda ,'bca |c()if b else a()|) ; boolean, consequent, alternate
,test
(lambda : ,consequent)
(lambda : ,alternate)))
Expand Down Expand Up @@ -194,7 +194,7 @@ Hidden doctest adds bundled macros for REPL-consistent behavior.

See also: `if-else<ifQz_else>`, `unless`, `if`.
"
`((lambda ,'bc .#"c()if b else()") ; boolean, consequent
`((lambda ,'bc |c()if b else()|) ; boolean, consequent
,condition (lambda : ,@body)))

(defmacro unless (condition : :* body)
Expand Down Expand Up @@ -228,7 +228,7 @@ Hidden doctest adds bundled macros for REPL-consistent behavior.

See also: `when`.
"
`((lambda ,'ba .#"()if b else a()") ; boolean, alternate
`((lambda ,'ba |()if b else a()|) ; boolean, alternate
,condition (lambda : ,@body)))

(defmacro let (pairs : :* body)
Expand Down Expand Up @@ -714,7 +714,7 @@ Hidden doctest adds bundled macros for REPL-consistent behavior.
;;
;; .. code-block:: REPL
;;
;; #> (define teen? X#.#"13<=X<20")
;; #> (define teen? X#|13<=X<20|)
;; >>> # define
;; ... __import__('builtins').globals().update(
;; ... teenQzQUERY_=(lambda X:13<=X<20))
Expand Down Expand Up @@ -787,7 +787,7 @@ Hidden doctest adds bundled macros for REPL-consistent behavior.
;;
;; .. code-block:: REPL
;;
;; #> (XYZ#.#"X*Y == Z" : X math..pi Y 2 Z math..tau)
;; #> (XYZ#|X*Y == Z| : X math..pi Y 2 Z math..tau)
;; >>> (lambda X,Y,Z:X*Y == Z)(
;; ... X=__import__('math').pi,
;; ... Y=(2),
Expand All @@ -805,7 +805,7 @@ Hidden doctest adds bundled macros for REPL-consistent behavior.
;;
;; .. code-block:: REPL
;;
;; #> (XYZW#.#"X[Y:Z:W]" "QuaoblcldefHg" -2 1 -2)
;; #> (XYZW#|X[Y:Z:W]| "QuaoblcldefHg" -2 1 -2)
;; >>> (lambda X,Y,Z,W:X[Y:Z:W])(
;; ... ('QuaoblcldefHg'),
;; ... (-2),
Expand Down Expand Up @@ -1188,7 +1188,7 @@ Hidden doctest adds bundled macros for REPL-consistent behavior.
$target `$#target)
(let (args (i#takewhile X#(op#ne X ':) iargs))
`(let (,$target ,target)
,@(map X#`(setattr ,$target ',.#"X.split('.')[-1]" ,X) args)
,@(map X#`(setattr ,$target ',|X.split('.')[-1]| ,X) args)
,@(map X#`(setattr ,$target ',X ,(next iargs))
iargs)
,$target))))
Expand Down Expand Up @@ -1224,7 +1224,7 @@ Hidden doctest adds bundled macros for REPL-consistent behavior.
,@(map X#`(,(get#0 X)
,$self
,@([#1:] X))
(map X#.#"X if type(X) is tuple else (X,)" invocations))
(map X# |X if type(X) is tuple else (X,)| invocations))
,$self))))

;;;; Arrange Macros
Expand Down Expand Up @@ -1266,8 +1266,8 @@ Hidden doctest adds bundled macros for REPL-consistent behavior.
See also:
`-\\<>><Qz_QzLT_QzGT_QzGT_>`, `X#<XQzHASH_>`, `get#<getQzHASH_>`.
"
(functools..reduce XY#.#"(Y[0],X,*Y[1:],)"
(map X#.#"X if type(X) is tuple else (X,)" forms)
(functools..reduce XY# |(Y[0],X,*Y[1:],)|
(map X# |X if type(X) is tuple else (X,)| forms)
expr))

(defmacro -<>> (expr : :* forms)
Expand Down Expand Up @@ -1313,7 +1313,7 @@ Hidden doctest adds bundled macros for REPL-consistent behavior.
"
(functools..reduce XY#(let (i (iter Y))
`(,@(i#takewhile X#(op#ne X :<>) i) ,X ,@i))
(map X#.#"X if type(X) is tuple else (X,)" forms)
(map X# |X if type(X) is tuple else (X,)| forms)
expr))

;;; TODO: implement other arrange macros?
Expand Down Expand Up @@ -1385,9 +1385,9 @@ Hidden doctest adds bundled macros for REPL-consistent behavior.
See also: `if-else<ifQz_else>`, `case`, `any-map<anyQz_map>`, `elif`.
"
(when pairs
`((lambda (,@(map X#.#"f'x{X}'" (range (X#.#"X+1&-2" (len pairs)))))
`((lambda (,@(map X# |f'x{X}'| (range (X# |X+1&-2| (len pairs)))))
,(op#concat
(.join "else " `(,"x1()if x0 " ,@(map X#.#"f'x{X+1}()if x{X}()'"
(.join "else " `(,"x1()if x0 " ,@(map X# |f'x{X+1}()if x{X}()'|
(range 2 (len pairs) 2))))
"else()"))
,([#0] pairs)
Expand Down Expand Up @@ -1576,8 +1576,8 @@ Hidden doctest adds bundled macros for REPL-consistent behavior.
(cond (not exprs) True
(op#eq (len exprs) 1) (get#0 exprs)
:else
`((lambda (,@(map X#.#"f'x{X}'" (range (len exprs))))
,(.join "and " `(,"x0 " ,@(map X#.#"f'x{X}()'" (range 1 (len exprs))))))
`((lambda (,@(map X# |f'x{X}'| (range (len exprs))))
,(.join "and " `(,"x0 " ,@(map X# |f'x{X}()'| (range 1 (len exprs))))))
,([#0] exprs)
,@(map X#`O#,X ([#1:] exprs)))))

Expand Down Expand Up @@ -1628,8 +1628,8 @@ Hidden doctest adds bundled macros for REPL-consistent behavior.
"
(cond (op#eq (len exprs) 1) (get#0 exprs)
exprs
`((lambda (,@(map X#.#"f'x{X}'" (range (len exprs))))
,(.join "or " `(,"x0 " ,@(map X#.#"f'x{X}()'" (range 1 (len exprs))))))
`((lambda (,@(map X# |f'x{X}'| (range (len exprs))))
,(.join "or " `(,"x0 " ,@(map X# |f'x{X}()'| (range 1 (len exprs))))))
,([#0] exprs)
,@(map X#`O#,X ([#1:] exprs)))))

Expand All @@ -1640,7 +1640,7 @@ Hidden doctest adds bundled macros for REPL-consistent behavior.
Avoid using this form except when implementing throw method overrides.
Prefer `throw` instead.
"
`(.#"(lambda g:g.close()or g.throw)(c for c in'')" ,@exception))
`(|(lambda g:g.close()or g.throw)(c for c in'')| ,@exception))

(defmacro throw (exception)
"Raise an exception.
Expand Down Expand Up @@ -1891,7 +1891,7 @@ Hidden doctest adds bundled macros for REPL-consistent behavior.
(when (ands xs (op#eq :* (get#-1 xs)))
(throw (SyntaxError "trailing :*")))
(let (ixs (iter xs))
`((lambda (: :* ,'xs) .#"[*xs]")
`((lambda (: :* ,'xs) |[*xs]|)
: ,@chain#(map X#(if-else (op#eq X ":*")
`(,X ,(next ixs))
`(:? ,X))
Expand Down Expand Up @@ -1922,7 +1922,7 @@ Hidden doctest adds bundled macros for REPL-consistent behavior.
(when (ands xs (op#eq :* (get#-1 xs)))
(throw (SyntaxError "trailing :*")))
(let (ixs (iter xs))
`((lambda (: :* ,'xs) .#"{*xs}")
`((lambda (: :* ,'xs) |{*xs}|)
: ,@chain#(map X#(if-else (op#eq X ":*")
`(,X ,(next ixs))
`(:? ,X))
Expand Down Expand Up @@ -1957,12 +1957,12 @@ Hidden doctest adds bundled macros for REPL-consistent behavior.
"
(cond
(op#mod (len kvs) 2) (throw (TypeError "extra key without value"))
kvs `((lambda (,@(i#starmap XY#.#"f'x{X}'" (filter X#(op#ne :** (get#1 X))
(enumerate kvs))))
kvs `((lambda (,@(i#starmap XY# |f'x{X}'| (filter X#(op#ne :** (get#1 X))
(enumerate kvs))))
,(.format "{{{}}}"
(.join "," (i#starmap XY#(if-else (op#eq Y :**)
.#"f'**x{X+1}'"
.#"f'x{X}:x{X+1}'")
|f'**x{X+1}'|
|f'x{X}:x{X+1}'|)
(-> kvs enumerate (i#islice 0 None 2))))))
,@(filter X#(op#ne X :**) kvs))
:else (dict)))
Expand Down Expand Up @@ -2532,9 +2532,9 @@ except ModuleNotFoundError:pass"
;;
;; .. code-block:: REPL
;;
;; #> (any-map x '(1 2 spam .#"42" :eggs)
;; #> (any-map x '(1 2 spam |42| :eggs)
;; #.. (case x (print "default")
;; #.. (0 2 .#"42") (print "even")
;; #.. (0 2 |42|) (print "even")
;; #.. (1 3 spam) (print "odd")))
;; >>> # anyQz_map
;; ... __import__('builtins').any(
Expand Down Expand Up @@ -2784,15 +2784,15 @@ except ModuleNotFoundError:pass"
`(,my.obj ,@(i#islice my.iexprs my.arity+1))
`((op#attrgetter ',([#1:] my.obj))
,(next my.iexprs)))))
.#"/" (progn (.pop my.exprs my.arity) ())
.#"&" (@ (op#getitem my.exprs my.arity))
.#"@" (@ (.pop my.exprs my.arity+1))
.#">" nil#(.insert my.exprs my.arity my.mark)
.#"<" (@ (let (x (tuple (i#takewhile X#(op#ne X my.mark) my.iexprs)))
(if-else suffix
`(op#getitem ,(next my.iexprs) x)
x)))
.#"*" (@ :* (i#islice my.iexprs my.arity) :* (next my.iexprs))
|/| (progn (.pop my.exprs my.arity) ())
|&| (@ (op#getitem my.exprs my.arity))
|@| (@ (.pop my.exprs my.arity+1))
|>| nil#(.insert my.exprs my.arity my.mark)
|<| (@ (let (x (tuple (i#takewhile X#(op#ne X my.mark) my.iexprs)))
(if-else suffix
`(op#getitem ,(next my.iexprs) x)
x)))
|*| (@ :* (i#islice my.iexprs my.arity) :* (next my.iexprs))
: ()))
(set@ my.result
(._rewrite _macro_ program : :* my.result :* my.iexprs))
Expand Down Expand Up @@ -2919,7 +2919,7 @@ Creates a lambda of arity {X} containing a `^*#<QzHAT_QzSTAR_QzHASH_>`
;;
;; .. code-block:: REPL
;;
;; #> (avow 7 (X#.#"X%2 == 0")
;; #> (avow 7 (X#|X%2 == 0|)
;; #.. it "That's odd.")
;; >>> # avow
;; ... # hissp.macros.._macro_.let
Expand Down Expand Up @@ -2981,7 +2981,7 @@ Creates a lambda of arity {X} containing a `^*#<QzHAT_QzSTAR_QzHASH_>`
;;
;; .. code-block:: REPL
;;
;; #> (assure 7 (X#.#"X%2 == 0")
;; #> (assure 7 (X#|X%2 == 0|)
;; #.. it "That's odd.")
;; >>> # assure
;; ... # hissp.macros.._macro_.avow
Expand Down

0 comments on commit 0bfa47a

Please sign in to comment.