From e240768c26df1b110a062cd922dba418da64512e Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 25 Mar 2026 23:51:47 +0100 Subject: [PATCH] Lot of example directory structure refactoring. (0.39.9). --- CMakeLists.txt | 2 +- examples/README.md | 9 +++++---- examples/{ => arrays}/arrays.fun | 4 ++-- examples/{ => arrays}/arrays_advanced.fun | 0 examples/{ => arrays}/arrays_iter.fun | 0 examples/{ => basics}/boolean_decl.fun | 1 - examples/{ => basics}/booleans.fun | 3 +-- examples/{ => basics}/builtins_conversions.fun | 0 examples/{ => cli}/cli_parse_example.fun | 10 +++++----- examples/{ => io}/file_io.fun | 2 +- examples/{ => snippets}/include_namespace.fun | 6 +++--- examples/{ => snippets}/maps_iterate.fun | 2 +- examples/{ => strings}/base64_demo.fun | 2 +- 13 files changed, 20 insertions(+), 21 deletions(-) rename examples/{ => arrays}/arrays.fun (95%) mode change 100755 => 100644 rename examples/{ => arrays}/arrays_advanced.fun (100%) mode change 100755 => 100644 rename examples/{ => arrays}/arrays_iter.fun (100%) mode change 100755 => 100644 rename examples/{ => basics}/boolean_decl.fun (99%) mode change 100755 => 100644 rename examples/{ => basics}/booleans.fun (96%) mode change 100755 => 100644 rename examples/{ => basics}/builtins_conversions.fun (100%) mode change 100755 => 100644 rename examples/{ => cli}/cli_parse_example.fun (69%) mode change 100755 => 100644 rename examples/{ => io}/file_io.fun (95%) mode change 100755 => 100644 rename examples/{ => snippets}/include_namespace.fun (86%) mode change 100755 => 100644 rename examples/{ => snippets}/maps_iterate.fun (95%) mode change 100755 => 100644 rename examples/{ => strings}/base64_demo.fun (94%) mode change 100755 => 100644 diff --git a/CMakeLists.txt b/CMakeLists.txt index 64035f2..cb37caa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(fun VERSION 0.39.8 LANGUAGES C) +project(fun VERSION 0.39.9 LANGUAGES C) set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED ON) diff --git a/examples/README.md b/examples/README.md index 2b3e812..9892493 100644 --- a/examples/README.md +++ b/examples/README.md @@ -8,16 +8,17 @@ How to run: - For CGI examples under `examples/data/htdocs`, start one of the blocking HTTP servers from `examples/blocking/` and visit the URL noted in the file headers. Categories: -- basics: hello_world, fizzbuzz, fibonacci, collections -- strings: split_join_trim, templating_min, urlencode_decode +- basics: hello_world, fizzbuzz, fibonacci, collections, boolean_decl, booleans, builtins_conversions +- arrays: arrays, arrays_advanced, arrays_iter +- strings: split_join_trim, templating_min, urlencode_decode, base64_demo - io: read_write_file, csv_reader (uses examples/io/sample.csv), word_count - algos: sort_and_search, deduplicate, stack_queue -- cli: env_echo, args_parse (parse ARGS env) +- cli: env_echo, args_parse (parse ARGS env), cli_parse_example - net: tcp_echo_server, tcp_echo_client, http_static_server (blocking) - data/htdocs (CGI): hello.fun, info.fun, counter.fun, form_post.fun, redirect.fun, json_like_api.fun - compose: run_other_fun, pipeline - patterns: assert_like, logging_min -- snippets: escape_html_demo, maps_iterate +- snippets: escape_html_demo, maps_iterate, include_namespace Notes: - Scripts that start servers (tcp_echo_server, http_static_server, http_server_cgi*.fun) are blocking; run them in a separate terminal. diff --git a/examples/arrays.fun b/examples/arrays/arrays.fun old mode 100755 new mode 100644 similarity index 95% rename from examples/arrays.fun rename to examples/arrays/arrays.fun index 231f7f5..9a47bf2 --- a/examples/arrays.fun +++ b/examples/arrays/arrays.fun @@ -47,7 +47,7 @@ print(arr) // -> [0, 1, 4, 9, 16] // Nested arrays (matrix) matrix = [[1, 2], [3, 4], [5, 6]] -print(matrix) // -> [[1, 2], [3, 4], [5, 6]] +print(matrix) // -> [[1, 2], [3, 4]] print(matrix[1][0]) // -> 3 // Function that mutates an array in place (first 3 elements) @@ -75,7 +75,7 @@ print(p[1]) // -> 9 [1, 2, 13] 16 [0, 1, 4, 9, 16] -[[1, 2], [3, 4], [5, 6]] +[[1, 2], [3, 4]] 3 [10, 20, 30] [7, 9] diff --git a/examples/arrays_advanced.fun b/examples/arrays/arrays_advanced.fun old mode 100755 new mode 100644 similarity index 100% rename from examples/arrays_advanced.fun rename to examples/arrays/arrays_advanced.fun diff --git a/examples/arrays_iter.fun b/examples/arrays/arrays_iter.fun old mode 100755 new mode 100644 similarity index 100% rename from examples/arrays_iter.fun rename to examples/arrays/arrays_iter.fun diff --git a/examples/boolean_decl.fun b/examples/basics/boolean_decl.fun old mode 100755 new mode 100644 similarity index 99% rename from examples/boolean_decl.fun rename to examples/basics/boolean_decl.fun index c49ed3d..f97daf1 --- a/examples/boolean_decl.fun +++ b/examples/basics/boolean_decl.fun @@ -20,4 +20,3 @@ print("typeof(b) => " + typeof(b)) b => false typeof(b) => Boolean */ - diff --git a/examples/booleans.fun b/examples/basics/booleans.fun old mode 100755 new mode 100644 similarity index 96% rename from examples/booleans.fun rename to examples/basics/booleans.fun index b7ed476..0ce6f21 --- a/examples/booleans.fun +++ b/examples/basics/booleans.fun @@ -13,7 +13,7 @@ // Boolean datatype usage examples (first-class booleans) // Run like: -// FUN_LIB_DIR="$(pwd)/lib" ./build/fun examples/booleans.fun +// FUN_LIB_DIR="$(pwd)/lib" ./build/fun examples/basics/booleans.fun // Literals boolean t = true @@ -73,4 +73,3 @@ false == 0 => true if t: branch taken if f: else branch taken */ - diff --git a/examples/builtins_conversions.fun b/examples/basics/builtins_conversions.fun old mode 100755 new mode 100644 similarity index 100% rename from examples/builtins_conversions.fun rename to examples/basics/builtins_conversions.fun diff --git a/examples/cli_parse_example.fun b/examples/cli/cli_parse_example.fun old mode 100755 new mode 100644 similarity index 69% rename from examples/cli_parse_example.fun rename to examples/cli/cli_parse_example.fun index be40b40..8fe2a73 --- a/examples/cli_parse_example.fun +++ b/examples/cli/cli_parse_example.fun @@ -13,10 +13,10 @@ // Demonstrates parsing flags like -f, --force, --force=42 and positionals // Usage examples: -// FUN_LIB_DIR="$(pwd)/lib" ./build/fun ./examples/cli_parse_example.fun -f foo -// FUN_LIB_DIR="$(pwd)/lib" ./build/fun ./examples/cli_parse_example.fun --force bar -// FUN_LIB_DIR="$(pwd)/lib" ./build/fun ./examples/cli_parse_example.fun --force=42 alpha beta -// FUN_LIB_DIR="$(pwd)/lib" ./build/fun ./examples/cli_parse_example.fun -abc x y +// FUN_LIB_DIR="$(pwd)/lib" ./build/fun ./examples/cli/cli_parse_example.fun -f foo +// FUN_LIB_DIR="$(pwd)/lib" ./build/fun ./examples/cli/cli_parse_example.fun --force bar +// FUN_LIB_DIR="$(pwd)/lib" ./build/fun ./examples/cli/cli_parse_example.fun --force=42 alpha beta +// FUN_LIB_DIR="$(pwd)/lib" ./build/fun ./examples/cli/cli_parse_example.fun -abc x y #include @@ -38,7 +38,7 @@ print(flags) print("Positionals:") print(pos) -/* Expected output (FUN_LIB_DIR="$(pwd)/lib" ./build/fun ./examples/cli_parse_example.fun --force bar xx x x --for=xxx --h=1): +/* Expected output (FUN_LIB_DIR="$(pwd)/lib" ./build/fun ./examples/cli/cli_parse_example.fun --force bar xx x x --for=xxx --h=1): 1 Force enabled Flags map: diff --git a/examples/file_io.fun b/examples/io/file_io.fun old mode 100755 new mode 100644 similarity index 95% rename from examples/file_io.fun rename to examples/io/file_io.fun index e85a13f..55e9c08 --- a/examples/file_io.fun +++ b/examples/io/file_io.fun @@ -20,7 +20,7 @@ */ // file I/O (writes then reads) -path = "/tmp/fun_io_example.txt" +path = "./tmp/fun_io_example.txt" ok = write_file(path, "hello-io") print(ok) // -> 1 content = read_file(path) diff --git a/examples/include_namespace.fun b/examples/snippets/include_namespace.fun old mode 100755 new mode 100644 similarity index 86% rename from examples/include_namespace.fun rename to examples/snippets/include_namespace.fun index c256907..7530404 --- a/examples/include_namespace.fun +++ b/examples/snippets/include_namespace.fun @@ -15,11 +15,11 @@ // // Run examples (without installing) by pointing FUN_LIB_DIR to the repo lib: // Linux/macOS/FreeBSD: -// FUN_LIB_DIR="$(pwd)/lib" ./build/fun examples/include_namespace.fun +// FUN_LIB_DIR="$(pwd)/lib" ./build/fun examples/snippets/include_namespace.fun // Windows (CMD): -// set FUN_LIB_DIR=%CD%\lib && build-debug\fun.exe examples\include_namespace.fun +// set FUN_LIB_DIR=%CD%\lib && build-debug\fun.exe examples\snippets\include_namespace.fun // Windows (PowerShell): -// $env:FUN_LIB_DIR="$PWD\lib"; .\build\fun.exe examples\include_namespace.fun +// $env:FUN_LIB_DIR="$PWD\lib"; .\build\fun.exe examples\snippets\include_namespace.fun // Import stdlib math helpers into alias 'm' #include as m diff --git a/examples/maps_iterate.fun b/examples/snippets/maps_iterate.fun old mode 100755 new mode 100644 similarity index 95% rename from examples/maps_iterate.fun rename to examples/snippets/maps_iterate.fun index 90f543f..a74cd6e --- a/examples/maps_iterate.fun +++ b/examples/snippets/maps_iterate.fun @@ -4,7 +4,7 @@ * This file is part of the Fun programming language. * https://fun-lang.xyz/ * - * Copyright 2026 Johannes Findeisen + * Copyright 2026 Johannes Findeisen * Licensed under the terms of the Apache-2.0 license. * https://opensource.org/license/apache-2-0 * diff --git a/examples/base64_demo.fun b/examples/strings/base64_demo.fun old mode 100755 new mode 100644 similarity index 94% rename from examples/base64_demo.fun rename to examples/strings/base64_demo.fun index 4ed58e8..2b0dc8c --- a/examples/base64_demo.fun +++ b/examples/strings/base64_demo.fun @@ -15,7 +15,7 @@ * Base64 usage demo (RFC 4648, standard alphabet) * * Run without installing: - * FUN_LIB_DIR="$(pwd)/lib" ./build/fun examples/base64_demo.fun + * FUN_LIB_DIR="$(pwd)/lib" ./build/fun examples/strings/base64_demo.fun */ #include