Closed dzpao closed 1 year ago
You might be able to use #line local
to make new variable declarations from #format and most other commands local.
That might reduce the number of declarations.
Nice. WHY I FORGOT THIS.
But one problem with #line local
in practice is that it introduces a layer of indentation that makes the whole block of code incoherent. Like this:
#alias foo {
........
........
#line local {
..........
..........
};
........
........
#line local {
..........
..........
};
........
........
};
Unless I wrap the whole block in #line local, like this:
#alias foo { #line local {
......
......
}};
Looks a bit strange. But I tried to give #line local
to the front and it doesn't work properly again.
#line local #alias foo {
.......
.......
};
If only there was some way to make #alias/#action/#func
all use local by default (unless declared with #var
).
This would effectively prevent different parts of the code block from reading the wrong values.
Or, simply, allowing #local
to declare multiple variables at once might be a good way to go.
#alias foo { #line local {
......
......
}};
That would be the correct way to go about it since #line creates its own scope.
You could use nesting:
#local temp {};
#format temp[name] %-10s x;
#math temp[other_name] 1+1
I understand that #alias foo { #line local {
is good, but it looks a bit strange. Is it possible to make it a little more pretty?
I don't think so. There's also the foreach route:
#foreach {bli;bla;blo} {item} #local $item {}
Request a new syntax to declare multiple
#local
variables at once.I like to keep my code's runtime space clean with the
#local
syntax. But if I have multiple#local
variables to declare in a block, then I need to write many lines of#local
, which makes the code look a bit bloated. So I'd like to be able to declare multiple#local
at once.