More examples documentation and just small fixes.
This commit is contained in:
parent
d21378c869
commit
24f5f7517c
3 changed files with 65 additions and 1 deletions
30
examples/for_print_file_line_by_line.fun
Normal file
30
examples/for_print_file_line_by_line.fun
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
#!/usr/bin/env fun
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Fun programming language.
|
||||||
|
* https://hanez.org/project/fun/
|
||||||
|
*
|
||||||
|
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||||
|
* Licensed under the terms of the ISC license.
|
||||||
|
* https://opensource.org/license/isc-license-txt
|
||||||
|
*/
|
||||||
|
|
||||||
|
print("=== Line-by-line print start ===")
|
||||||
|
|
||||||
|
string file = "/etc/passwd"
|
||||||
|
|
||||||
|
// Print each line in a file
|
||||||
|
fun print_file_lines(path)
|
||||||
|
content = read_file(path)
|
||||||
|
lines = split(content, "\n")
|
||||||
|
for line in lines
|
||||||
|
print(line)
|
||||||
|
|
||||||
|
print("Printing file: " + file)
|
||||||
|
print_file_lines(file)
|
||||||
|
|
||||||
|
print("=== Line-by-line print end ===")
|
||||||
|
|
||||||
|
/* Expected output:
|
||||||
|
? The content of /etc/passwd
|
||||||
|
*/
|
||||||
|
|
@ -67,3 +67,38 @@ for x in range(1, 3)
|
||||||
print(x + y) // expect: 2,3,3,4
|
print(x + y) // expect: 2,3,3,4
|
||||||
|
|
||||||
print("=== for/range test end ===")
|
print("=== for/range test end ===")
|
||||||
|
|
||||||
|
/*
|
||||||
|
=== for/range test start ===
|
||||||
|
0
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
6
|
||||||
|
2
|
||||||
|
3
|
||||||
|
3
|
||||||
|
4
|
||||||
|
=== for/range test end ===
|
||||||
|
=== for/range test start ===
|
||||||
|
0
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
6
|
||||||
|
2
|
||||||
|
3
|
||||||
|
3
|
||||||
|
4
|
||||||
|
=== for/range test end ===
|
||||||
|
*/
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,6 @@ static int is_blank_line(const char *s) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char* lstrip(const char *s) {
|
static const char* lstrip(const char *s) {
|
||||||
while (*s == ' ' || *s == '\t') s++;
|
while (*s == ' ' || *s == '\t') s++;
|
||||||
return s;
|
return s;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue