Instead of writing a pattern like λ "abc" ⁀ xs ⁀ "def"
, we might have the convention of writing λ "abc $xs def"
, understood to mean the same thing. That is, this isn’t a pattern that matches strings containing the dollar sign. The dollar sign might not even be part of the alphabet that the matched strings are made from. Instead it matches strings that have the prefix "abc"
and the suffix "def"
, and it assigns whatever comes in between those (which might be the empty string) to the variable xs
.
If you tried to write a pattern like λ "abc $"
or put anything after the dollar sign that couldn’t be understood as a variable, like a digit or the string empty
, that would be broken or illegal. Having the variable at the start or end, like λ "abc $xs"
or λ "$xs def"
or even λ "$xs"
would be fine. The last would mean the same as λ xs
.
Instead of writing an expression like "abc" ⁀ xs ⁀ "def"
, we might have the convention of writing "abc ${xs} def"
, understood to mean the same thing. That is, this doesn’t designate a string value containing the dollar sign or { }
brackets. Instead it designates a string that has the prefix "abc"
and the suffix "def"
, and has in between whatever string the variable xs
is assigned.
If you tried to write an expression like "abc ${xs"
without a closing }
, or one where a $
wasn’t followed by a {
, like "abc $"
or "abc $xs"
, these would also be broken or illegal. Same as if you had an expression like "abc
with no closing quote. If the variable you put inside the ${ }
wasn’t assigned a value, that would also be broken.
I suggested using these slightly different notations for the pattern case and for the expression case — requiring { }
s only in the latter — to help remind us of when we were dealing with patterns and when with expressions. Also, in the expression case we could allow not just variables to come in between the { }
s but any interpretable expression. Thus you could also write "abc ${take("def", 2)} ghi"
and that would designate the string "abc de ghi"
. You could even write "abc ${"de"} ghi"
, which would be a cumbersome way of expressing the same string. Naturally, "abc ${empty} ghi"
would express the string "abc ghi"
. (Remember that throughout this discussion spaces are only for readability. So there’s no difference between "abc ghi"
and "abc ghi"
and "abcghi"
.)
If you’re familiar with Quinean “corner quotes” or “quasi quotes”, what Quine would write as ⌜abc α ghi⌝
, using α
as a string variable, we’d instead write as "abc ${α} ghi"
.
This kind of quasi-quotation is also common in many programming languages. In Bash/Shell, you’d write "abc ${var} ghi"
as we do (though there you can’t put arbitrary expressions inside the { }
s, and you’re allowed also to just write "abc $var ghi"
). In Python, you’d write f"abc {var} ghi"
. In JavaScript you’d write `abc ${var} ghi`
.