3 ms·
In TXR Lisp, from system prompt: # simple quasiliteral, denoted by backticks $ txr -p '(let ((x "Bob")) `Hello, @{x -10}`)' "Hello, Bob" # word
by kazinator 11y ago
In TXR Lisp, from system prompt:
# simple quasiliteral, denoted by backticks
$ txr -p '(let ((x "Bob")) `Hello, @{x -10}`)'
"Hello, Bob"
# word-quasiliteral (breaks into list on spaces)
# denoted by hash-backtick:
$ txr -p '#`@(+ 2 2) @(+ 1 2) a b c`'
("4" "3" "a" "b" "c")
# op-argument references in quasiliteral
# ret produces a function whose arguments depend
# on the uses of @1, @2. ... and @rest in the
# expression. The value of the expression is returned.
# These references can emanate from a quasistring:
$ txr -p "(mapcar (ret \`@1--@2--@rest\`) '(1 2 3) '(a b c) '(x y z)))"
("1--a--x" "2--b--y" "3--c--z")
# Very basic indexing, slicing and field adjustment:
$ txr -p '`foo @{(list 1 2 3) [0]} bar`'
"foo 1 bar"
$ txr -p '`foo @{(list 1 2 3) [2]} bar`'
"foo 3 bar"
$ txr -p '`foo @{(list 1 2 3) [1..:]} bar`'
"foo 2 3 bar"
$ txr -p '`foo @{(list 1 2 3) [1..:] 20} bar`'
"foo 2 3 bar"
$ txr -p '`foo @{(list 1 2 3) [1..:] -20} bar`'
"foo 2 3 bar"
Interpolation into quasi-literals is very useful and expressive; I use it all the time. Doing trivial things should look trivial in the code.
Oh, right: referencing splices and unquotes is possible from inside a quasistring:
$ txr -p '(let ((a 42) (b (range 1 5)))
^(list `hey @,a @(list ,*b)`))'
(list (sys:quasi "hey "
@42 " " @(list 1 2 3 4 5)))
$ txr -p '(eval (let ((a 42) (b (range 1 5)))
^(list `hey @,a @(list ,*b)`)))'
("hey 42 1 2 3 4 5")
Safe to say, that one's not coming to a Python near you.