From 24f5f7517cc0a01aeaae536ee05214e6ba09ebf9 Mon Sep 17 00:00:00 2001 From: hanez Date: Tue, 16 Sep 2025 07:45:19 +0200 Subject: [PATCH] More examples documentation and just small fixes. --- examples/for_print_file_line_by_line.fun | 30 ++++++++++++++++++++ examples/for_range_test.fun | 35 ++++++++++++++++++++++++ src/fun.c | 1 - 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 examples/for_print_file_line_by_line.fun diff --git a/examples/for_print_file_line_by_line.fun b/examples/for_print_file_line_by_line.fun new file mode 100644 index 0000000..3a34a5c --- /dev/null +++ b/examples/for_print_file_line_by_line.fun @@ -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 + * 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 +*/ diff --git a/examples/for_range_test.fun b/examples/for_range_test.fun index 78b85e7..b72aa7d 100755 --- a/examples/for_range_test.fun +++ b/examples/for_range_test.fun @@ -67,3 +67,38 @@ for x in range(1, 3) print(x + y) // expect: 2,3,3,4 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 === +*/ diff --git a/src/fun.c b/src/fun.c index 4e3a026..9c9a8b2 100644 --- a/src/fun.c +++ b/src/fun.c @@ -58,7 +58,6 @@ static int is_blank_line(const char *s) { return 1; } - static const char* lstrip(const char *s) { while (*s == ' ' || *s == '\t') s++; return s;