1
0
Fork 0
forked from fun/fun

Lot of example directory structure refactoring. (0.39.9).

This commit is contained in:
Johannes Findeisen 2026-03-25 23:51:47 +01:00
commit e240768c26
13 changed files with 20 additions and 21 deletions

View file

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.10) 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 99)
set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_STANDARD_REQUIRED ON)

View file

@ -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. - 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: Categories:
- basics: hello_world, fizzbuzz, fibonacci, collections - basics: hello_world, fizzbuzz, fibonacci, collections, boolean_decl, booleans, builtins_conversions
- strings: split_join_trim, templating_min, urlencode_decode - 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 - io: read_write_file, csv_reader (uses examples/io/sample.csv), word_count
- algos: sort_and_search, deduplicate, stack_queue - 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) - 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 - data/htdocs (CGI): hello.fun, info.fun, counter.fun, form_post.fun, redirect.fun, json_like_api.fun
- compose: run_other_fun, pipeline - compose: run_other_fun, pipeline
- patterns: assert_like, logging_min - patterns: assert_like, logging_min
- snippets: escape_html_demo, maps_iterate - snippets: escape_html_demo, maps_iterate, include_namespace
Notes: Notes:
- Scripts that start servers (tcp_echo_server, http_static_server, http_server_cgi*.fun) are blocking; run them in a separate terminal. - Scripts that start servers (tcp_echo_server, http_static_server, http_server_cgi*.fun) are blocking; run them in a separate terminal.

4
examples/arrays.fun → examples/arrays/arrays.fun Executable file → Normal file
View file

@ -47,7 +47,7 @@ print(arr) // -> [0, 1, 4, 9, 16]
// Nested arrays (matrix) // Nested arrays (matrix)
matrix = [[1, 2], [3, 4], [5, 6]] 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 print(matrix[1][0]) // -> 3
// Function that mutates an array in place (first 3 elements) // Function that mutates an array in place (first 3 elements)
@ -75,7 +75,7 @@ print(p[1]) // -> 9
[1, 2, 13] [1, 2, 13]
16 16
[0, 1, 4, 9, 16] [0, 1, 4, 9, 16]
[[1, 2], [3, 4], [5, 6]] [[1, 2], [3, 4]]
3 3
[10, 20, 30] [10, 20, 30]
[7, 9] [7, 9]

View file

View file

View file

@ -20,4 +20,3 @@ print("typeof(b) => " + typeof(b))
b => false b => false
typeof(b) => Boolean typeof(b) => Boolean
*/ */

3
examples/booleans.fun → examples/basics/booleans.fun Executable file → Normal file
View file

@ -13,7 +13,7 @@
// Boolean datatype usage examples (first-class booleans) // Boolean datatype usage examples (first-class booleans)
// Run like: // Run like:
// FUN_LIB_DIR="$(pwd)/lib" ./build/fun examples/booleans.fun // FUN_LIB_DIR="$(pwd)/lib" ./build/fun examples/basics/booleans.fun
// Literals // Literals
boolean t = true boolean t = true
@ -73,4 +73,3 @@ false == 0 => true
if t: branch taken if t: branch taken
if f: else branch taken if f: else branch taken
*/ */

View file

@ -13,10 +13,10 @@
// Demonstrates parsing flags like -f, --force, --force=42 and positionals // Demonstrates parsing flags like -f, --force, --force=42 and positionals
// Usage examples: // 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/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/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/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 -abc x y
#include <cli.fun> #include <cli.fun>
@ -38,7 +38,7 @@ print(flags)
print("Positionals:") print("Positionals:")
print(pos) 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 1
Force enabled Force enabled
Flags map: Flags map:

2
examples/file_io.fun → examples/io/file_io.fun Executable file → Normal file
View file

@ -20,7 +20,7 @@
*/ */
// file I/O (writes then reads) // file I/O (writes then reads)
path = "/tmp/fun_io_example.txt" path = "./tmp/fun_io_example.txt"
ok = write_file(path, "hello-io") ok = write_file(path, "hello-io")
print(ok) // -> 1 print(ok) // -> 1
content = read_file(path) content = read_file(path)

View file

@ -15,11 +15,11 @@
// //
// Run examples (without installing) by pointing FUN_LIB_DIR to the repo lib: // Run examples (without installing) by pointing FUN_LIB_DIR to the repo lib:
// Linux/macOS/FreeBSD: // 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): // 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): // 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' // Import stdlib math helpers into alias 'm'
#include <utils/math.fun> as m #include <utils/math.fun> as m

View file

@ -4,7 +4,7 @@
* This file is part of the Fun programming language. * This file is part of the Fun programming language.
* https://fun-lang.xyz/ * https://fun-lang.xyz/
* *
* Copyright 2026 Johannes Findeisen <you@hanez.org> * Copyright 2026 Johannes Findeisen
* Licensed under the terms of the Apache-2.0 license. * Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0 * https://opensource.org/license/apache-2-0
* *

View file

@ -15,7 +15,7 @@
* Base64 usage demo (RFC 4648, standard alphabet) * Base64 usage demo (RFC 4648, standard alphabet)
* *
* Run without installing: * 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 <encoding/base64.fun> #include <encoding/base64.fun>