You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Bash allows a text file to be read efficiently one line at a time, so a large file takes no more working memory than a small one:
while IFS= read -r line; do
echo "[$line]"
done <"foo.txt"
Amber should provide this functionality.
Describe the solution you'd like
I propose the following Amber syntax, where a new lines builtin can be used in the expression slot of an iterative loop:
for line in lines("foo.txt") {
echo "[{line}]"
}
let path = "foo.txt"
for line in lines(path) {
echo "[{line}]"
}
The builtin can also be used in an initialisation, set or append statement, in which case it will read all lines from the file into an array, instead of reading one line at a time:
let array = lines("foo.txt")
for line in array {
echo "[{line}]"
}
let array = [Text]
array = lines("foo.txt")
for line in array {
echo "[{line}]"
}
let array = [Text]
array += lines("foo.txt")
for line in array {
echo "[{line}]"
}
Note:
Because lines behaves like a function, it should be called like one, using parentheses; our users will not care how this functionality is implemented.
It will also be necessary to rename standard library function lines as split_lines.
Describe alternatives you've considered
The alternative would be to write a standard library function; but it would then be impossible to read the file efficiently, as the function would have to create and return an array, regardless of how it was called.
Additional context
N/A
The text was updated successfully, but these errors were encountered:
To me is fine but we need to decide about builtins with parenthesis
I knew this was going to show up again!
I would argue that builtins in expression slots, e.g. for line in lines("foo.txt") and let array = lines("foo.txt"), should expect parentheses, mostly because that's what our users will expect. They won't care if something that looks like a function is actually implemented as a function or a builtin.
Is your feature request related to a problem? Please describe.
Bash allows a text file to be read efficiently one line at a time, so a large file takes no more working memory than a small one:
Amber should provide this functionality.
Describe the solution you'd like
I propose the following Amber syntax, where a new
lines
builtin can be used in the expression slot of an iterative loop:The builtin can also be used in an initialisation, set or append statement, in which case it will read all lines from the file into an array, instead of reading one line at a time:
Note:
lines
behaves like a function, it should be called like one, using parentheses; our users will not care how this functionality is implemented.lines
assplit_lines
.Describe alternatives you've considered
The alternative would be to write a standard library function; but it would then be impossible to read the file efficiently, as the function would have to create and return an array, regardless of how it was called.
Additional context
N/A
The text was updated successfully, but these errors were encountered: