From db9665f62a64ab3f973ada95025c92514415967a Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 25 Mar 2026 21:24:35 +0100 Subject: [PATCH] Added maps iteration example. (0.39.6). --- CMakeLists.txt | 2 +- examples/blocking/http_server_cgi.fun | 11 ++++++ examples/data/htdocs/hello.fun | 11 ++++++ examples/maps_iterate.fun | 54 +++++++++++++++++++++++++++ lib/net/cgi.fun | 11 ++++++ 5 files changed, 88 insertions(+), 1 deletion(-) mode change 100644 => 100755 examples/blocking/http_server_cgi.fun create mode 100755 examples/maps_iterate.fun diff --git a/CMakeLists.txt b/CMakeLists.txt index 81c3ace..5d7c4e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(fun VERSION 0.39.5 LANGUAGES C) +project(fun VERSION 0.39.6 LANGUAGES C) set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED ON) diff --git a/examples/blocking/http_server_cgi.fun b/examples/blocking/http_server_cgi.fun old mode 100644 new mode 100755 index bb14147..a7c2879 --- a/examples/blocking/http_server_cgi.fun +++ b/examples/blocking/http_server_cgi.fun @@ -1,5 +1,16 @@ #!/usr/bin/env fun +/* + * This file is part of the Fun programming language. + * https://fun-lang.xyz/ + * + * Copyright 2026 Johannes Findeisen + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 + * + * Added: 2026-03-25 + */ + /* * Minimal CGI-capable HTTP server (blocking) */ diff --git a/examples/data/htdocs/hello.fun b/examples/data/htdocs/hello.fun index 2512d14..762253a 100644 --- a/examples/data/htdocs/hello.fun +++ b/examples/data/htdocs/hello.fun @@ -1,5 +1,16 @@ #!/usr/bin/env fun +/* + * This file is part of the Fun programming language. + * https://fun-lang.xyz/ + * + * Copyright 2026 Johannes Findeisen + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 + * + * Added: 2026-03-25 + */ + #include cgi = CGI() diff --git a/examples/maps_iterate.fun b/examples/maps_iterate.fun new file mode 100755 index 0000000..90f543f --- /dev/null +++ b/examples/maps_iterate.fun @@ -0,0 +1,54 @@ +#!/usr/bin/env fun + +/* + * This file is part of the Fun programming language. + * https://fun-lang.xyz/ + * + * Copyright 2026 Johannes Findeisen + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 + * + * Added: 2026-03-25 + */ + +/* + * Iterating through maps in Fun + * + * This example shows common patterns to iterate over a map: + * - for k in keys(m): access value via m[k] + * - for v in values(m): iterate values directly + * - Notes about non-deterministic key order unless you define one + */ + +// Define a sample map +user = { "name": "Ada", "age": 37, "city": "London" } + +print("-- Iterate keys, then index map --") +for k in keys(user) + print(k + ": " + to_string(user[k])) + +print("-- Iterate values only --") +for v in values(user) + print(v) + +// If you need a specific order, provide it explicitly +order = ["name", "city", "age"] +print("-- Deterministic order by explicit key list --") +for k in order + if has(user, k) + print(k + ": " + to_string(user[k])) + +/* Expected output (key order in the first two blocks may vary): +-- Iterate keys, then index map -- +name: Ada +age: 37 +city: London +-- Iterate values only -- +Ada +37 +London +-- Deterministic order by explicit key list -- +name: Ada +city: London +age: 37 +*/ diff --git a/lib/net/cgi.fun b/lib/net/cgi.fun index d16af35..10212e1 100644 --- a/lib/net/cgi.fun +++ b/lib/net/cgi.fun @@ -1,3 +1,14 @@ +/* + * This file is part of the Fun programming language. + * https://fun-lang.xyz/ + * + * Copyright 2026 Johannes Findeisen + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 + * + * Added: 2026-03-25 + */ + // Minimal, parser-friendly CGI helper (incrementally extend as needed) #include