aboutsummaryrefslogtreecommitdiff
path: root/notes
diff options
context:
space:
mode:
authorSamuel Lidén Borell <samuel@kodafritt.se>2025-10-26 09:30:24 +0100
committerSamuel Lidén Borell <samuel@kodafritt.se>2025-10-26 09:30:24 +0100
commit1533e452986a8c670a86f1ad95d5314a9085136b (patch)
tree75e3acf9b63854c13cc73d5ce9a7f708e52a6f61 /notes
parent28e584fc747c0f0eb8df06127dab0e801e144bb3 (diff)
downloadslul-try2-main.tar.gz
slul-try2-main.zip
Notes: Alternatives to goto-sectionsHEADmain
Diffstat (limited to 'notes')
-rw-r--r--notes/goto_improved.txt79
1 files changed, 79 insertions, 0 deletions
diff --git a/notes/goto_improved.txt b/notes/goto_improved.txt
index d1def4b..2afab4e 100644
--- a/notes/goto_improved.txt
+++ b/notes/goto_improved.txt
@@ -66,3 +66,82 @@ Syntax test with assertion failure section:
error "Oops"
return false
end
+
+Alternative solution 1: Blocks for error/success/finally only
+-------------------------------------------------------------
+
+Allow only "sections" as endings of functions. And only allow
+allow error/success/finally? Like this:
+
+ func example
+ int i
+ code
+ ...
+ on error
+ ...
+ on success
+ ...
+ finally
+ ...
+ end
+
+Alternative solution 2: Blocks for error/return only
+-----------------------------------------------------
+
+Or, perhaps skip the `on success` part?
+And rename `finally` to something that does not imply that it is executed in
+abnormal circumstances (e.g. thread termination)?
+
+ func example
+ int i
+ code
+ ...
+ on error
+ ...
+ on return
+ ...
+ end
+
+Alternative solution 3: A before-return block only
+--------------------------------------------------
+
+Skip the distinction between success and errors (and of course don't try to
+handle thread terminiation):
+
+ func example
+ int i
+ code
+ ...
+ last
+ ...
+ end
+
+The `last` block can only access outermost-scoped variables that are
+initialized before the first return.
+
+In the example below, it should definitely be able to access `a`, but
+perhaps not `b` since it hasn't been "merged" to the outermost scope at
+the point of the return.
+
+ func example
+ int i
+ code
+ int a
+ int b
+ if i == 0
+ a = 1
+ else
+ a = 2
+ end
+ if i == 1
+ b = 1
+ else
+ b = 2
+ if i == 3
+ return
+ end
+ end
+ ...
+ last
+ ...
+ end