1
0
Fork 0
forked from fun/fun
fun/docs/examples
2026-03-30 14:53:11 +02:00
..
data/htdocs Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 22:53:40 +01:00
net Added some await pattern and added a scheduler to the stdlib. Broken! (0.39.13) 2026-03-30 14:53:11 +02:00
builtins_extended.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
builtins_maps_and_more.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
byte_for_demo.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
byte_overflow_try_catch.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
cast_demo.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
class_constructor.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
class_test.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
class_without_object.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
classes_demo.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
cli_argv_dump.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
conversions_showcase.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
cpp_add.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
datetime_basic.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
datetime_extended.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
datetime_timer.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
echo_example.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
env_all.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
error_handling.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
expressions_test.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
features.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
file_print_for_file_line_by_line.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
floats.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
for_range_test.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
functions_test.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
have_fun.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
have_fun_function.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
hex_example.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
if_else_test.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
include_lib.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
include_local.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
include_local_util.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
inheritance_demo.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
loops_break_continue.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
maps.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
match.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
namespaced_mod.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
nested_loops.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
objects_basic.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
objects_more.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
os_env.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
process_example.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
progress.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
progress_inline.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
random_demo.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
random_number_example.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
README.md Added some await pattern and added a scheduler to the stdlib. Broken! (0.39.13) 2026-03-30 14:53:11 +02:00
regex_demo.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
regex_procedural.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
rust_hello.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
rust_hello_args.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
rust_hello_args_return.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
serial_demo.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
short_circuit_test.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
signed_ints.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
stdlib_showcase.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
strings_test.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
tcp_http_get.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
tcp_http_get_class.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
test_bits.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
test_dec_to_hex.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
test_hex_to_dec.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
test_include.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
test_rol.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
test_serial.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
test_shl.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
test_types.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
test_xor.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
thread_class_example.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
threads_demo.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
try_catch_finally.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
type_safety.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
type_safety_fails.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
typeof.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
typeof_features.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
types_integers.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
types_overview.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
uint_types.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
unix_socket_echo.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
version.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00
while_test.md Some documentation refactoring. No code changes. (0.39.12) 2026-03-27 23:39:54 +01:00

Examples catalog and how to run them

This page is a practical catalog of the example areas that ship with the Fun language. It explains what youll find in each folder under ./examples/, how to run the scripts, and where deeper walkthroughs live.

If youre building/running from the repository without installing, set FUN_LIB_DIR to the local ./lib directory so examples can locate the stdlib:

  • export FUN_LIB_DIR="./lib"
  • Then run an example: ./build_debug/fun examples/basics/hello_world.fun
    • Or, if installed: fun examples/basics/hello_world.fun

Notes

  • Most scripts are selfdocumented with a short header comment at the top. Open them to see exact behavior and expected output.
  • Some examples depend on optional extensions (cURL, PCRE2, SQLite, Notcurses, Tk, PC/SC, OpenSSL/LibreSSL). See docs/external/ for enablement and availability.
  • Networking examples often bind to 127.0.0.1 on high ports; read the file header for the exact port.

Deepdives

Toplevel examples (./examples)

Quick micro demos covering language features and tiny utilities.

Run pattern:

  • fun examples/.fun

Highlights (selection):

Tip: If a file name is listed above but not present on your build, it may depend on an extension you did not enable.

Algorithms (./examples/algos)

  • deduplicate.fun — removing duplicates from arrays/maps
  • sort_and_search.fun — sorting and lookup patterns
  • stack_queue.fun — basic stack and queue implementation

Arrays (./examples/arrays)

  • arrays.fun — create, index, slice; typical idioms
  • arrays_iter.fun — iteration and enumeration
  • arrays_advanced.fun — copying, filtering, transformations

Basics (./examples/basics)

  • boolean_decl.fun, booleans.fun — boolean values and operators
  • builtins_conversions.fun — core builtins, type conversions
  • collections.fun — arrays, maps, nested structures
  • fibonacci.fun, fizzbuzz.fun — classic exercises
  • hello_world.fun — the canonical first program

CLI (./examples/cli)

  • args_parse.fun — arguments parsing patterns for small CLIs

Compose (./examples/compose)

Compositional patterns, small abstractions to combine behavior.

Crypto (./examples/crypto)

Hashing and cryptographic helpers. Availability depends on whether OpenSSL/LibreSSL is enabled.

  • openssl_md5.fun — MD5 via OpenSSL (if -DFUN_WITH_OPENSSL)
  • libressl_md5.fun — MD5 via LibreSSL (if -DFUN_WITH_LIBRESSL)
  • aes256.fun and hash samples if present on your build

Data (./examples/data)

Static assets for example servers; not meant to be run directly.

  • htdocs/ — files used by HTTP server examples (index.html, hello.fun, info.fun, form_post.fun, counter.fun, redirect.fun, json_like_api.fun)

Error handling and diagnostics (./examples/error)

  • debug_reporting.fun — enabling debug output and reading traces
  • exit_example.fun — exit codes
  • fail.fun — triggering and observing failures
  • repl_on_error.fun — dropping into REPL on error
  • rust_vm_access.fun — Rust opcode errors (if enabled)
  • test_indent.fun — parser/indentation corner cases
  • try_catch_with_error.fun — capturing error objects

Extra integrations (./examples/extra)

These require optional external libraries. See docs/external/.

  • curl_* — cURL HTTP client examples (download, GET JSON, POST)
  • ini_* — parsing INI files (simple to complex)
  • json_showcase.fun — JSON helpers
  • libsql_example.fun — libSQL client usage
  • notcurses_* — rich TUI demos (if Notcurses enabled)
  • pcre2_* — PCRE2 regex engine demos
  • pcsc*.fun — smart card access via PC/SC
  • sqlite_example.fun — SQLite usage
  • tcp_echo_server*.fun — basic TCP echo server
  • tk_* — Tcl/Tk GUI examples
  • xml_* — XML parsing with libxml2

Interactive (./examples/interactive)

  • console_prompt.fun — simple prompt loop
  • input_example.fun — reading user input
  • input_hidden_example.fun, input_hidden_pam_auth.fun — hidden input/passwords

IO (./examples/io)

  • async_http_client.fun — nonblocking HTTP client
  • await_http_client.fun — nonblocking HTTP client using lib/async/scheduler.fun (await-style helpers)
  • csv_reader.fun — parse CSV files
  • file_io.fun, read_write_file.fun — file operations
  • word_count.fun — classic WC example

Math (./examples/math)

Small, focused math helpers and demonstrations:

  • math_ceil, math_floor, math_round, math_trunc, math_sign
  • math_cos, math_sin, math_tan
  • math_sqrt, math_isqrt
  • math_exp_log
  • math_fmin_fmax
  • math_gcd_lcm

Networking (./examples/net)

Servers and socket utilities. See docs/examples/net/httpserver.md for the HTTP family.

  • HTTP servers: httpserver.md — endtoend walkthrough of all HTTP server variants in examples/net/
  • http_static_server.fun — minimal static server over sockets
  • http_server.fun — blocking static/CGI dispatcher using lib/net/http_server.fun
  • http_server_cgi.fun — blocking server with CGI via lib/net/http_cgi_server.fun
  • http_server_cgi_lib.fun — blocking server leveraging net/cgi.fun helpers
  • http_mt_server.fun — threadperconnection static server
  • http_mt_server_cgi.fun — threadperconnection with CGI support

Patterns (./examples/patterns)

Small idioms and reusable patterns.

  • assert_like.fun — assertstyle checks via language constructs

Snippets (./examples/snippets)

Miscellaneous oneoff code snippets demonstrating particular opcodes or tricks.

SQLite daemon (./examples/sqlited)

  • Files related to running a small SQLitebacked service (see source for details)

Strings (./examples/strings)

  • base64_demo.fun — base64 encode/decode using encoding/base64
  • split_join_trim.fun — string splitting and trimming
  • templating_min.fun — barebones templating
  • urlencode_decode.fun — percentencoding helpers

Broken (./examples/broken)

Historical or intentionally broken examples kept for reference/regression.

  • notcurses_* — experiments around Notcurses
  • ripemd160* — legacy or experimental hash routines

Running examples reliably

Prefer the local build when running from the repository root:

  • ./build_debug/fun <path/to/example.fun>
  • or: ./build_release/fun <path/to/example.fun>

Set up env if needed:

  • export FUN_LIB_DIR="./lib" # to find stdlib
  • export FUN_EXEC="./build_debug/fun" # used by CGI examples
  • export FUN_HTDOCS="./examples/data/htdocs" # override docroot

When optional extensions are not enabled, their examples will not run; reconfigure the build with the required -D flags shown in docs/external/.