summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChloe Brown <chloe.brown.00@outlook.com>2025-04-23 16:37:39 +0100
committerChloe Brown <chloe.brown.00@outlook.com>2025-04-23 17:06:26 +0100
commit4459595f44adb15a1e88e63ee7e97e574fbb3a79 (patch)
tree6b7bdedbc4b5ab5ada4fe49760276a3fb7c78538
parentc45750588a01f532a38c01d108cde8865e612243 (diff)
Improve multiline let formatting.
-rw-r--r--main.tex42
-rw-r--r--sec/systemt.ltx21
2 files changed, 43 insertions, 20 deletions
diff --git a/main.tex b/main.tex
index c2eaafe..0e0c6ff 100644
--- a/main.tex
+++ b/main.tex
@@ -171,21 +171,47 @@
\newcommand\letkw{\ensuremath{\mathsf{let}}}
\newcommand\lettm[3]{\letkw~{#2} \coloneq {#1}~\mathsf{in}~{#3}}
\ExplSyntaxOn
-\NewDocumentCommand \squid_letpart {m m}
- { \letkw & {#1} = \cr
- & {#2} \cr
- \mathsf{in} &
+%% args:
+%% 1. Do I need a & on the first line?
+%% 2. Binder name
+%% 3. Is value multiline?
+%% 4. Value
+\NewDocumentCommand \squid_letpart {m m m m}
+ { \IfBooleanTF{#3}
+ { \letkw \IfBooleanTF{#1}{&}{\nobreakspace} {#2} = \cr
+ & {#4} \cr
+ \mathsf{in}
+ }
+ { \letkw \IfBooleanTF{#1}{&}{\nobreakspace} {#2} = {#4} \nobreakspace \mathsf{in}
+ }
}
-\NewDocumentCommand \squid_contlet {> {\SplitArgument{1}{=}} m}
- { \squid_letpart #1 \squid_checklet [\cr]
+%% args:
+%% 1. Do I need a & on the first line?
+%% 2. Binder name
+%% 3. Is value multiline?
+%% 4. Value
+%% ... further processing
+\NewDocumentCommand \squid_contlet {m m s m}
+ { \squid_letpart {#1} {#2} {#3} {#4}
+ \IfBooleanTF{#3}
+ { \squid_checklet [\BooleanFalse] }
+ { \squid_checklet [\BooleanTrue] }
}
+%% args:
+%% 1. If something, do I need a new line?
+%% 2. Is the next arg not a binder?
+%% ... further processing
\NewDocumentCommand \squid_checklet {o s m}
{ \IfBooleanTF{#2}
- { \IfNoValueF{#1}{#1} & {#3}
+ { \IfNoValueF{#1}{\IfBooleanT{#1}{\cr}} & {#3}
\end{array}
\wlog{End~let}
}
- { \IfNoValueF{#1}{#1} \squid_contlet {#3}
+ { \IfNoValueTF{#1}
+ { \squid_contlet \BooleanTrue {#3} }
+ { \IfBooleanTF{#1}{\cr}{&}
+ \squid_contlet {#1} {#3}
+ }
}
}
\NewDocumentCommand \dolet {O{t}}
diff --git a/sec/systemt.ltx b/sec/systemt.ltx
index 54ba5f2..e66f499 100644
--- a/sec/systemt.ltx
+++ b/sec/systemt.ltx
@@ -171,8 +171,8 @@ the fold. Below is the fold over binary trees.
\mathsf{leaf}(n). f(n);
\mathsf{branch}(x, y). g(x, y)
} \coloneq
- \dolet{
- go = \doprimrec*{t}{\arb}{h}{
+ \dolet{go}*{
+ \doprimrec*{t}{\arb}{h}{
\lambda i. \domatch*{i}{
\mathsf{leaf}(n). f(n);
\mathsf{branch}(l, r). g(h(l), h(r))}}
@@ -206,21 +206,18 @@ respectively, and then case split on this sum. We detail this in \cref{fig:churc
\mathsf{leaf}(n). f(n);
\mathsf{branch}(x,y). g(x, y)
} \coloneq
- \dolet[t]{
- \roll = \lambda x. \domatch*[t]{x}{
+ \dolet[t]{\roll}*{
+ \lambda x. \domatch*[t]{x}{
\mathsf{Left}(n). \mathsf{leaf}(n);
- \mathsf{Right}(x, y). \mathsf{branch}(x, y)
- }
- }{
- x = \dofoldmatch*{t}{
+ \mathsf{Right}(x, y). \mathsf{branch}(x, y)}
+ }{x}*{
+ \dofoldmatch*{t}{
\mathsf{leaf}(n). \mathsf{Left}(n);
- \mathsf{branch}(x, y). \mathsf{Right}(\roll~x, \roll~y)
- }
+ \mathsf{branch}(x, y). \mathsf{Right}(\roll~x, \roll~y)}
}*{
\domatch*{x}{
\mathsf{Left}(n). f(n);
- \mathsf{Right}(x, y). g(x, y)
- }
+ \mathsf{Right}(x, y). g(x, y)}
}
\]
\caption{How to perform pattern matching on binary trees for Church encodings.