3 ms·
A quoted value is exactly what is written, for example in LISP: (let ((foo "hello")) (quote (My name is foo))) > (My name is foo) An unquote
by chriswarbo 12y ago
A quoted value is exactly what is written, for example in LISP:
(let ((foo "hello"))
(quote (My name is foo)))
> (My name is foo)
An unquoted value is interpreted completely:
(let ((foo "hello"))
(My name is foo))
> Error: "My" is not a function
A quasiquoted value is literal by default (like a quoted value), but we can selectively "unquote" parts, to have them interpreted:
(let ((foo "hello"))
(quasiquote (My name is (unquote foo))))
> (My name is "hello")
As you can see, in LISP we can use quasiquotes on pretty much anything. Most other languages with quasiquotes only support it in strings; for example in PHP ' is the quotation mark and " is the quasiquotation mark:
$foo = "hello";
echo 'My name is $foo'; // Gives 'My name is $foo'
echo "My name is $foo"; // Gives "My name is hello";
Depending on the language, some require explicit unquoting (eg. ${} syntax), others require explicit escaping (eg. \$ syntax).
The article uses two forms of quasiquotation marks: [r| and |], and [l| and |]
For example:
person :: Person
person =
[r| {name = "Yuri Alekseyevich Gagarin",
birthday = {year = 1934, month = 3, day = 9},
country = {name = "Soviet Union", language = "Russian"}} |]
Here the value of "person" is quasiquoted, so some parts of its contents (eg. the "{", "}", "," and "=" syntax, along with the "name, "birthday", "year", "month", "day", "country" and "language" tokens) will take their 'literal' values in the record-building language. The other values, '"Yuri Alekseyevich Gagarin"', "1934", "3", "9", '"Soviet Union"' and '"Russian"' will be interpreted as Haskell values, and the results (various Strings and Nums) will be used in the record-building language, instead of their literal tokens.