Objeck example programs

The programs in this folder ship with every Objeck release, in the examples/ directory of the distribution. welcome.obs prints this same index at the terminal:

obc -src welcome.obs -lib json,net,cipher
obr welcome.obe

Each program is self-contained and opens with a comment giving its exact compile and run lines. Run them from this folder (or from examples/ in an install): two of them read files from data/, which ships alongside.

ExampleLibrariesWhat it shows
hello_0.obsnonea class, a function, Main, and one line of output
values_1.obsnonetypes, literals, variables, interpolation and conversions
control_flow_2.obsnoneif, select, while, do/while, for, each, break and continue
functions_3.obsnonefunctions, default and named arguments, ref parameters, recursion
classes_4.obsnoneclasses, inheritance, virtual methods, interfaces and Stringify
records_enums_5.obsnonerecords, readonly records, enums and consts
errors_6.obsnonecustom errors, try/on/finally, built-in errors and ?-> recovery
generics_7.obsnonegeneric classes, bounded generic functions, Vector and Map
closures_8.obsnonefunctions as values, lambdas and closures
arrays_9.obsnonearrays: literals, 2-D, jagged, sorting, Fill and Copy
strings_10.obs-lib cipherstring methods, comparison, formatting, SHA-256 and Base64
collections_11.obsnoneVector, List, Map, Hash, Set, Stack, Queue, unboxed collections
threads_12.obs-lib concurrentthreads, critical sections and a CountDownLatch
files_13.obsnonewrite, read, append and list files and folders
json_14.obs-lib json,json_streamparse, walk, query and build JSON; stream a file
xml_15.obs-lib xmlparse XML, walk elements and attributes, build XML
csv_16.obs-lib csvread CSV by row and column, quoted fields, write CSV
regex_17.obs-lib regexmatch, find all, capture groups, replace and split
sql_tables_18.obs-lib query,misc,net,json,regex,xml,csv,cipherSQL over in-memory tables: group by, indexes, Explain
sql_files_19.obs-lib query,misc,net,json,regex,xml,csv,cipherSQL over CSV and JSON files and a folder, with a join
serialize_20.obsnonesave objects to a file and load them back
odbc_21.obs-lib odbca database through ODBC: prepared inserts and queries
http_client_22.obs-lib net,json,cipherHTTPS GET: status, headers, JSON and failure handling
web_server_23.obs-lib net,net_server,json,ciphera two-route web server that tests itself and stops
rss_reader_24.obs-lib rss,xml,net,cipherfetch an RSS feed and list the latest headlines
ml_regression_25.obs-lib csv,mllinear and logistic regression with a test split
ml_classify_26.obs-lib csv,mlrandom forest, cross-validation and a confusion matrix
ml_outliers_27.obs-lib csv,mlanomaly detection with isolation forest and LOF
nlp_28.obs-lib nlptokenizing, stemming, sentiment and TF-IDF search
llm_29.obs-lib gemini,net,net_server,json,misc,cipherask a large language model (Gemini) a question
ai_search_30.obs-lib aiA* pathfinding and minimax
game_31.obs-lib sdl2,sdl_game,jsonan SDL2 game: collect gems, dodge spiders, keep a best score

Building all of them

build_examples.py beside this file reads the Libraries column above and compiles each example with exactly what it names:

python build_examples.py              compile every example, report
python build_examples.py --only json  just the ones whose name matches
python build_examples.py --keep       leave the .obe files behind

It finds obc in ../bin (an install) or the repo's deploy tree, and exits non-zero if any example fails. CI runs it on every change, so the table above is verified rather than merely written down: a wrong entry in the Libraries column fails the build.

Building one

With no libraries:

obc -src hello_0.obs
obr hello_0.obe

With them, naming the list from the table above:

obc -src json_14.obs -lib json,json_stream
obr json_14.obe

Notes


Generated from welcome.obs by tools/cicd/gen_examples_readme.py. Edit the arrays there, not this file, and regenerate.