Overview
Cob is a corn-themed hybrid language with Python-style,
indentation-and-colon block structure. A program is a sequence of
statements; blocks (while, if,
elif, else and recipe) are opened with a
trailing : and their body is whatever's indented
further than the header line.
recipe countdown(n): while n > 0: pop("counting down: " + n) set n = n - 1 serve "liftoff" pop(countdown(3))
The language itself is small: variables, arithmetic, pop,
while, if, recipe and
shuck. Everything else — reading what the person
types, text, numbers, time, files, lists, arrays, SQLite, windows, Tcl/Tk — is
the standard library: real shared libraries
brought in with shuck, every name corn themed.
Indentation is spaces only — tabs are a hard error. Comments are whole lines starting with #; there are no trailing comments, so the notes written to the right of some examples on this page are explanation, not code you can paste.
The toolchain
| Tool | What it does |
|---|---|
cob_interp | Interprets a .cob file directly, with a fast-boot .strawberry bytecode cache — or, with no file, starts an interactive REPL. One interpreter: the core language only, with no vendor libraries, so it builds in about a second. |
popcorn_comp | Compiles a .strawberry file to a real, standalone native executable. Handles the whole language, recipes and every standard library module included. |
farmer | The package manager — installs .cob libraries from a static registry. |
lib/ | The standard library: one shared library per module, with its .cob wrapper. Keep it next to the tools. |
lib/ into a folder you choose. It is portable: no registry,
PATH or administrator changes, so add that folder to your PATH yourself or run the interpreter from it.
It is not code signed yet, so Windows SmartScreen and macOS Gatekeeper will each ask you to approve it once.
Language reference
pop("text")
Writes text to stdout followed by a newline.
pop("hello") # hello pop("line one\nline two")
Supported escapes inside the string literal: \\, \", \n, \t.
set <name> = <expr>
Assigns a value to a variable, creating it if it doesn't exist
yet. A value is either an integer or a string. Expressions support
+ - * / with standard precedence
(*// bind tighter than
+/-) on two integers; + also
concatenates when either side is a string, converting the other
side to text first.
set a = 2 + 3 * 4 # 14 set b = a - 1 set greeting = "count: " + a # "count: 14"
while <condition>:
Loops while the condition is true. A bare expression is a
truthiness test (nonzero); a comparison uses
== != < > <= >=, and works the same way on
two strings as it does on two integers. Loops nest to any depth
and are capped at 10,000,000 iterations as a safety net against
runaway/infinite programs.
while a != 0: pop("tick") set a = a - 1
if / elif / else 0.0.7
if <condition>: runs its indented block when the
condition is true. The condition is exactly what a
while takes: a comparison
(== != < > <= >=) on two integers or two
strings, or a bare expression as a truthiness test (non-zero for an
integer, non-empty for a string).
An if may be followed by any number of
elif <condition>: blocks and then at most one
else: block. They must sit at the same
indentation as the if they belong to, and are
checked top to bottom — only the first block whose condition
is true runs, or the else block if none is.
set score = 85 if score >= 90: pop("grade: A") elif score >= 80: pop("grade: B") else: pop("keep practicing") # grade: B is printed instead
Blocks nest to any depth, inside each other and inside loops:
set i = 1 while i <= 3: if i == 2: pop("two") else: pop(i) set i = i + 1
and/or/not
yet — a condition is a single comparison or truthiness test.
To combine two tests, nest one if inside the other. An
else or elif with no matching
if directly above it at the same indentation is a
syntax error, and so is an if line with no trailing
:. Both cob_interp and
popcorn_comp support it and print identical output.
if, elif and else are
reserved words.
recipe <name>(<params>): / serve [<expr>] 0.0.9
A recipe is a function — it works like Python's
def — and serve hands a value back to
whoever called it, like return. A call is
name(a, b), and can be used anywhere an expression can, or
on a line of its own.
# serve hands a value back recipe add(a, b): serve a + b # a recipe that ends without serve gives 0 recipe greet(name): pop("Hello, " + name + "!") recipe fact(n): if n <= 1: serve 1 serve n * fact(n - 1) pop(add(2, 3)) greet("Ada") pop(fact(10))
- Scope. A recipe's parameters, and every name it
sets, are local to it, for its whole body, and start at 0. Any other name reads the global variable of that name. A recipe cannot assign a global — it hands results back withserve. - Top level, and hoisted. A recipe is defined at the top level of a program, never inside a
while,ifor another recipe. All recipes exist before the program starts, so a call may appear above its recipe, and recipes may call each other. - Checked before anything runs. A call to a name that is not a recipe or a library function, a wrong number of arguments, a duplicate recipe, or
serveoutside a recipe is an error with its line number, so a typo fails up front, not halfway through. - Order of evaluation. Arguments, and the two sides of an operator, are evaluated left to right — in
popcorn_compas well. - Recursion works, up to 500 calls deep; past that you get a warning and the call gives 0, rather than a crash.
- Names.
recipeandserveare reserved words. A recipe cannot share its name with anextern.
[cob_interp] error at line 5: recipe 'add' takes 2 arguments but 1 was given
shuck <library_name>
Loads <library_name>.cob and splices its statements in at that point,
like a textual include. It looks, in order, in:
- the current directory,
cob_modules/<library_name>/<library_name>.cob— the layoutfarmer harvestinstalls into,- the standard library directory.
Circular imports and excessive nesting depth are rejected with a clear error. A file that defines recipes can only be shucked at the top level of a program.
shuck greeter shuck kernels pop("back in the main program")
porch.cob next to your program) is found before the real one.
Name your own files accordingly.
extern <name>(<params>) from "<library>"
Binds a C function from a shared library, so it can be called like any other function. This is
what the whole standard library is built on, and how you write your own module.
<library> is a path ("./libmine.so") or a bare module name
("porch", found in the standard library directory). The parameter names are
documentation: Cob does not check how many arguments a call passes. If the library, or the
function in it, can't be found you get one warning for the library and the function
evaluates to 0.
extern double_it(n) from "./libdoubler.so" pop(double_it(21))
harvest(<bytes>) / trash(<variable>)
Low-level manual memory: harvest(n) is an expression
that allocates n bytes and returns an opaque integer
handle; trash(v) frees the handle held in v.
Both require the --no-gc flag — a
program that uses either without it is refused outright by both
cob_interp and popcorn_comp, not silently
ignored.
set p = harvest(64)
trash(p)
trash(). Double-free and unknown-handle use are
reported as warnings, not crashes.
_MakeCache = False
If the literal first line of a .cob file is
_MakeCache = False (whitespace/case-insensitive), the
.strawberry fast-boot cache is disabled entirely for that file
— neither read nor written.
_MakeCache = False
pop("always reparsed fresh")
The REPL 0.0.9
Run cob_interp with no file to try Cob interactively (cob_interp --repl
does the same). Variables and recipes persist from one input to the next.
$ cob_interp Cob 0.0.10 REPL -- :help for help, :quit or Ctrl-D to leave cob> 1 + 2 3 cob> set x = 10 cob> recipe square(n): ... serve n * n ... cob> square(x) 100 cob> :quit
- A bare expression prints its value — numbers plainly, strings in quotes so
"5"and5look different. A recipe call that ends withoutserveprints nothing. - A line ending in
:starts a block. Keep typing indented lines (the prompt becomes...) and finish with a blank line. - Typing a recipe again replaces it. Mistakes print an error and the session carries on.
- Commands:
:help,:vars,:recipes(or:funcs),:load <file.cob>,:reset,:quit(or Ctrl-D). cob_interp file.cob -iruns a file first and then stays in the REPL with everything it defined. A file that fails to start does not drop you into the REPL.- Prompts and the banner only appear on a real terminal, so
cob_interp --repl < script.txtis scriptable.
cob_interp only — not popcorn_comp, and not the browser build.The standard library 0.0.9
Everything beyond the core language is a module: a real shared library
(lib<name>.so on Linux, lib<name>.dylib on macOS,
<name>.dll on Windows) plus a small <name>.cob wrapper of
extern declarations. shuck <name> loads the
wrapper, which loads the library. Every module and every function is corn themed.
| shuck | What it is | Functions |
|---|---|---|
porch | talk to whoever is at the keyboard | porch_ask porch_ask_int |
cornmath | numbers beyond + - * / | husk_abs ear_max ear_min stalk_pow stalk_sqrt silk_mod scatter_seed scatter_rand |
kernels | text, kernel by kernel | kernel_len kernel_upper kernel_lower kernel_slice kernel_find kernel_repeat kernel_trim kernel_replace kernel_char kernel_code kernel_from_code kernel_to_int kernel_starts kernel_ends |
almanac | the farmer's calendar and clock | almanac_now almanac_ticks almanac_nap almanac_year almanac_stamp |
granary | files, stored like grain | granary_read granary_write granary_append granary_exists granary_remove |
bushel | lists that grow, a bushel of whatever you pick | bushel_new bushel_free bushel_len bushel_push bushel_get bushel_set bushel_insert bushel_remove bushel_clear bushel_find bushel_sort bushel_reverse bushel_extend bushel_copy bushel_join bushel_split |
furrow | arrays: a fixed-length row, planted once | furrow_new furrow_free furrow_len furrow_get furrow_set furrow_fill furrow_swap furrow_find furrow_sum furrow_sort furrow_copy |
pantry | a SQLite database to keep things in | pantry_open pantry_exec pantry_query pantry_close |
barn | a window to put things in | barn_open barn_label barn_wait barn_close barn_button barn_slider barn_textbox |
tassel | Tcl and Tk | tassel_tcl tassel_tk |
silo | the everyday five in one go | porch + cornmath + kernels + almanac + granary |
Where the libraries live
In a lib/ folder next to the tools (cob_interp, popcorn_comp),
or wherever the COB_STDLIB environment variable points. make builds it
into bin/lib/; ship it beside the binaries. If a library can't be found you get one
warning naming it, and its functions evaluate to 0 or "".
- Forgetting a
shuckis a clear error:'kernel_len' is not defined -- it is in the standard library: add `shuck kernels` at the top. - Wrong arguments to a library function print a warning (
[kernels] warning: kernel_slice() takes 3 arguments, got 2) and give a harmless default (0or""); they never crash. Library warnings are tagged with the module name. - The same in both tools.
popcorn_complinks the same shared libraries and records the library folder as an rpath, so a compiled program behaves like the interpreted one, warnings included — but it must be linked dynamically, so keeplib/where it was when you compiled (or setCOB_STDLIB).
porch cornmath kernels almanac
granary bushel furrow pantry; barn needs X11 and OpenGL to build and
tassel is a long from-source build, so both are opt-in
(make stdlib-barn, make stdlib-tassel). The browser playground
has no shared libraries to load, so it compiles porch, cornmath,
kernels, almanac, bushel and furrow in and makes the rest quiet no-ops with a one-time notice.
porch — console input
shuck porch. Reads from standard input, so a program can be fed from a file or a pipe: cob_interp quiz.cob < answers.txt.
| Call | Returns |
|---|---|
porch_ask(<prompt>) | string — the line typed, without its line ending; "" at end of input |
porch_ask_int(<prompt>) | int — the line parsed as a whole number; 0 if it isn't one, or at end of input |
shuck porch set name = porch_ask("What is your name? ") pop("Nice to meet you, " + name + "!") set age = porch_ask_int("How old are you? ") set next_year = age + 1 pop("Next year you will be " + next_year)
- The prompt is optional, and can be a string or a number. It is printed without a trailing newline and flushed before reading, so it appears on the same line as the answer.
- End of input — a piped file that has run out, or Ctrl-D (Ctrl-Z on Windows) — makes
porch_ask()return""andporch_ask_int()return0. porch_ask_intparsing. Spaces or tabs around a base-10 number are fine, and so is a leading-or+. Anything else, including a blank line, gives0; a non-blank non-number also prints[porch] warning: porch_ask_int() got non-numeric input "abc"; treated as 0on stderr.- Windows line endings (
\r\n) are stripped.
while guess != secret:, can't tell "the right answer" from "no more answers": once the
input runs out porch_ask_int keeps returning 0. Make sure the loop has
another way out.
cornmath — numbers
shuck cornmath. All arguments and results are integers.
| Call | Returns |
|---|---|
husk_abs(n) | absolute value |
ear_max(a, b) / ear_min(a, b) | the larger / smaller of two numbers |
stalk_pow(base, exp) | base to a whole-number power; 0 (with a warning) for a negative exponent |
stalk_sqrt(n) | square root rounded down; 0 (with a warning) for a negative number |
silk_mod(a, b) | remainder with the sign of b (so silk_mod(0 - 7, 3) is 2); 0 (with a warning) when b is 0 |
scatter_seed(n) | seed the random numbers, for repeatable runs; returns 0 |
scatter_rand(lo, hi) | a random whole number from lo to hi, both included |
shuck cornmath scatter_seed(42) set roll = scatter_rand(1, 6) pop("You rolled " + roll) pop(silk_mod(17, 5))
scatter_rand uses its own generator, so a seeded run gives the same numbers on every platform. Unseeded, it starts from the clock.
kernels — text
shuck kernels. Positions count from 0 and count bytes (plain ASCII text).
| Call | Returns |
|---|---|
kernel_len(s) | number of characters |
kernel_upper(s) / kernel_lower(s) | the text in upper / lower case (ASCII) |
kernel_slice(s, start, count) | count characters from position start, clipped to the text |
kernel_find(hay, needle) | position of the first match, or -1 |
kernel_repeat(s, n) | s written n times ("" if n is 0 or less) |
kernel_trim(s) | without leading and trailing blanks |
kernel_replace(s, from, to) | every from swapped for to |
kernel_char(s, i) | the one-character string at position i ("" if there isn't one) |
kernel_code(s) | byte value of the first character (0 if empty) |
kernel_from_code(n) | the one-character string with byte value n (1 to 255) |
kernel_to_int(s) | s read as a whole number; 0 if it isn't one |
kernel_starts(s, prefix) / kernel_ends(s, suffix) | 1 or 0 |
shuck kernels set word = "popcorn" pop(kernel_upper(word) + " has " + kernel_len(word) + " letters") pop(kernel_slice(word, 3, 4)) pop(kernel_replace("a-b-c", "-", "+"))
almanac — time
shuck almanac.
| Call | Returns |
|---|---|
almanac_now() | seconds since 1970-01-01 (Unix time) |
almanac_ticks() | milliseconds on a steady clock — for timing things |
almanac_nap(ms) | sleeps for ms milliseconds; returns 0 |
almanac_year() | the current year, in local time |
almanac_stamp() | the local date and time as "YYYY-MM-DD HH:MM:SS" |
shuck almanac set start = almanac_ticks() almanac_nap(250) set took = almanac_ticks() - start pop("that took " + took + " ms")
granary — files
shuck granary. Text files only: contents are read up to the first zero byte.
| Call | Returns |
|---|---|
granary_read(path) | the whole file as a string; "" (with a warning) if it can't be read |
granary_write(path, text) | replaces the file's contents; 0 on success, 1 on failure |
granary_append(path, text) | adds to the end of the file; 0 on success, 1 on failure |
granary_exists(path) | 1 if the file can be opened, else 0 |
granary_remove(path) | deletes the file; 0 on success, 1 on failure |
shuck granary set rc = granary_write("notes.txt", "first line\n") set rc = granary_append("notes.txt", "second line\n") pop(granary_read("notes.txt"))
bushel — lists 0.0.10
shuck bushel. A list grows as you add to it and holds numbers and strings, mixed freely. A list is a
handle: a whole number (1 or more) you keep in a variable, the way harvest
and pantry_open give you one. Positions count from 0. For a row whose length never changes, see
furrow.
| Call | Returns |
|---|---|
bushel_new() | a new, empty list (its handle) |
bushel_free(b) | 0; the list is thrown away (1 if b is not a live list) |
bushel_len(b) | how many items it holds |
bushel_push(b, v) | 0; v is added at the end (1 on failure) |
bushel_get(b, i) | the item at position i (0 if there isn't one) |
bushel_set(b, i, v) | 0; the item at i is replaced (1 if there is no such position) |
bushel_insert(b, i, v) | 0; v goes in at i and later items move up. i may equal bushel_len(b), which adds at the end |
bushel_remove(b, i) | the item that was at i, now taken out (0 if there isn't one) |
bushel_clear(b) | 0; every item removed |
bushel_find(b, v) | position of the first item equal to v, or -1 |
bushel_sort(b) | 0; numbers first, smallest first, then strings in byte order |
bushel_reverse(b) | 0; the list turned around |
bushel_extend(b, other) | 0; a copy of every item of other added to the end of b (they may be the same list) |
bushel_copy(b) | a new list with the same items (its handle; 0 if b is not a list) |
bushel_join(b, sep) | every item as text with sep between them (numbers are written out) |
bushel_split(text, sep) | a new list of the pieces of text, empty pieces kept; a sep of "" gives one byte per item |
shuck bushel set fruit = bushel_split("pear,apple,fig", ",") bushel_push(fruit, "plum") bushel_sort(fruit) pop(bushel_join(fruit, ", ")) pop("the first is " + bushel_get(fruit, 0)) set nums = bushel_new() set i = 1 while i <= 5: bushel_push(nums, i * i) set i = i + 1 pop(bushel_join(nums, " + ")) recipe total(list): set sum = 0 set j = 0 while j < bushel_len(list): set sum = sum + bushel_get(list, j) set j = j + 1 serve sum pop("= " + total(nums))
- A number never equals a string.
bushel_find(b, 3)will not find"3", and the piecesbushel_splitmakes are strings. - Mistakes warn and carry on. A handle that was never made (or was freed) or a position that isn't there prints one warning, such as
[bushel] warning: bushel_get() -- position 5 is out of range (the list has 3 items), and gives0(or1from the calls above that report success), so a program is never stopped by them. - Limits. A list holds at most 10,000,000 items;
bushel_pushsays so and returns1beyond that. Handles are never reused, sobushel_freea list you are finished with. - Everywhere. The same in
cob_interp, in programs compiled bypopcorn_comp, and in the browser playground.
furrow — arrays 0.0.10
shuck furrow. An array has a length chosen when it is made and never changes. Every slot starts as the
number 0 and holds a number or a string. Like a bushel it is a handle,
and positions count from 0. Use a bushel when the length should change.
| Call | Returns |
|---|---|
furrow_new(n) | a new array of n slots, all 0 (its handle). n must be 0 to 10,000,000; otherwise a warning and 0 |
furrow_free(f) | 0; the array is thrown away (1 if f is not a live array) |
furrow_len(f) | how many slots it has |
furrow_get(f, i) | the value in slot i (0 if there is no such slot) |
furrow_set(f, i, v) | 0; v is put in slot i (1 if there is no such slot) |
furrow_fill(f, v) | 0; v is put in every slot |
furrow_swap(f, i, j) | 0; slots i and j exchange values (1 if either is out of range) |
furrow_find(f, v) | the first slot holding v, or -1 |
furrow_sum(f) | the sum of the numbers in it (strings are skipped) |
furrow_sort(f) | 0; numbers first, smallest first, then strings in byte order |
furrow_copy(f) | a new array with the same values (its handle; 0 if f is not an array) |
shuck furrow shuck bushel set n = 30 set sieve = furrow_new(n + 1) furrow_fill(sieve, 1) furrow_set(sieve, 0, 0) furrow_set(sieve, 1, 0) set p = 2 while p * p <= n: if furrow_get(sieve, p) == 1: set m = p * p while m <= n: furrow_set(sieve, m, 0) set m = m + p set p = p + 1 set primes = bushel_new() set k = 0 while k <= n: if furrow_get(sieve, k) == 1: bushel_push(primes, k) set k = k + 1 pop(furrow_sum(sieve) + " primes up to " + n + ": " + bushel_join(primes, " "))
- A number never equals a string, as in
bushel:furrow_find(f, 7)will not find"7". - Mistakes warn and carry on, tagged with the module name:
[furrow] warning: furrow_get() -- slot 5 is out of range (the array has 5 slots). The call gives0(or1from the calls above that report success).
pantry — SQLite
shuck pantry. The SQLite amalgamation is compiled into the library. Up to 16 databases can be open at once.
| Call | Returns |
|---|---|
pantry_open(path) | handle (int), 0 on failure. ":memory:" opens a database that lives only in memory. |
pantry_exec(h, sql) | 0 on success, -1 (with a warning) on failure — for statements that give no answer |
pantry_query(h, sql) | string — first column of the first row, "" if none |
pantry_close(h) | 0 |
shuck pantry set h = pantry_open("scores.db") set rc = pantry_exec(h, "CREATE TABLE IF NOT EXISTS t (name TEXT)") set rc = pantry_exec(h, "INSERT INTO t VALUES ('cob')") set name = pantry_query(h, "SELECT name FROM t LIMIT 1") pop("got: " + name) set rc = pantry_close(h)
pantry_close (or one that was never opened) warns and gives -1 / "" — it does not crash.barn — a native window
shuck barn. Backed by raylib + raygui. Needs a display, and the barn library, which is opt-in to build (make stdlib-barn).
| Call | Returns |
|---|---|
barn_open(title) | handle (1), 0 on failure (for example, no display) |
barn_label(h, text) | 0 — sets/replaces the window's text |
barn_wait(h, seconds) | 0 — keeps the window responsive for about seconds |
barn_close(h) | 0 |
barn_button(h, label) | 1 if clicked since the last read of that label, else 0 |
barn_slider(h, label, max) | current value, 0 to max, as an int |
barn_textbox(h, label) | current string contents of the box |
shuck barn set h = barn_open("Cob Window Demo") set rc = barn_label(h, "Hello from Cob!") set clicked = barn_button(h, "OK") set volume = barn_slider(h, "Volume", 100) set name = barn_textbox(h, "Name") set rc = barn_wait(h, 5) set rc = barn_close(h)
Widgets are identified by their label: the first barn_button()/barn_slider()/barn_textbox()
call with a given label creates it, stacked below the barn_label() text; every later call with the
same label reads it (a slider is re-ranged, and its value clamped, if called again with a different max).
Up to 16 widgets per window.
barn_button()'s click flag resets on read, so a click is reported exactly once.barn_textbox()is always editable — there is no click-to-focus.
barn_open() again before closing the first
warns and returns 0. The window's own close button ([X]) is intentionally ignored: the
window stays open until barn_wait()'s timer runs out or barn_close() is called
explicitly. Running more than one barn_textbox() at a time hasn't been verified for
keyboard-focus behavior; treat that as unverified rather than unsupported.
tassel — Tcl and Tk
shuck tassel. One process-wide Tcl interpreter: variables and widgets persist between calls.
| Call | Returns |
|---|---|
tassel_tcl(script) | string — Tcl's own string result |
tassel_tk(script) | string — the same interpreter, with Tk also loaded |
shuck tassel pop("answer=" + tassel_tcl("expr {6*7}"))
make stdlib-tassel): it compiles the vendored Tcl/Tk, and needs
TCL_LIBRARY pointed at Tcl's library folder at run time. tassel_tk() needs a real
X11 $DISPLAY; without one it evaluates to a normal Tcl error string, the same as real Tk would
report, not a crash.
silo — the everyday five
shuck silo is just shuck porch, cornmath, kernels,
almanac and granary together. The other modules (bushel,
furrow, pantry, barn, tassel) are shucked on their own.
Upgrading from 0.0.9
There is nothing to change: programs written for 0.0.9 run unchanged. 0.0.10 only adds. The language, the
.strawberry cache format and the extension interface are the same; the new features are two ordinary
standard library modules and the setup wizards.
| New in 0.0.10 | How |
|---|---|
| Lists that grow | shuck bushel, then bushel_new, bushel_push, bushel_get and the rest |
| Arrays of a fixed length | shuck furrow, then furrow_new, furrow_set, furrow_get and the rest |
| A graphical installer | the Windows and macOS setup wizards |
One thing to know: bushel and furrow are now standard library names. If you already have a
file of your own called bushel.cob or furrow.cob next to a program, it keeps being found first
(see shuck); rename it if you want the standard library one.
Upgrading from 0.0.8
The built-in input, SQLite, window and Tcl/Tk keywords are gone; they are standard library
functions now. An old name gives an error that says exactly what to write instead
('input' is now porch_ask() in the standard library: add `shuck porch` at the top and call porch_ask(...)).
| 0.0.8 | 0.0.9 |
|---|---|
input(p) / input_int(p) | shuck porch, then porch_ask(p) / porch_ask_int(p) |
sql_open sql_exec sql_query sql_close | shuck pantry, then pantry_open pantry_exec pantry_query pantry_close |
shuck cobwindow + window_open window_label window_wait window_close window_button window_slider window_textbox | shuck barn, then barn_open barn_label barn_wait barn_close barn_button barn_slider barn_textbox |
tcl_eval / tk_eval | shuck tassel, then tassel_tcl / tassel_tk |
Also new: recipe and serve are reserved words; the .strawberry cache format changed
(old caches are rebuilt automatically); and cob_interp_full, cob_interp_db and
cob_interp_window are no longer different builds — there is one interpreter, and those names are
kept only as make targets for old scripts. See the release notes for everything.
Write your own module
A module is the same thing the standard library is: a shared library whose functions all have one shape,
plus a wrapper that declares them. Include include/cob.h from the Cob source.
/* doubler.c */
#include "cob.h"
COB_EXPORT CobValue double_it(CobValue *argv, int argc) {
if (argc != 1 || argv[0].kind != COB_INT) return cob_int(0);
return cob_int(argv[0].as.i * 2);
}
cc -shared -fPIC -Iinclude -o libdoubler.so doubler.c
# doubler.cob -- the wrapper extern double_it(n) from "./libdoubler.so"
shuck doubler
pop(double_it(21))
Values are COB_INT (as.i) or COB_STR (as.s); make one with
cob_int(n) or cob_str(text). Cob copies a returned string immediately, so return a literal, a
static buffer, or a buffer you keep alive until your next call — never free it for Cob. Put the library and wrapper
in the standard library folder and from "doubler" works too.
Tool reference
cob_interp
cob_interp [file.cob] [--no-cache] [--no-gc] [-i]
| (no file) | Start the interactive REPL. |
| -i, --repl | Run the file, then stay in the REPL with everything it defined. |
| --no-cache | Skip reading/writing the .strawberry cache for this run. |
| --no-gc | Unlock harvest()/trash(). |
One interpreter, the core language only. Console input, text, SQLite, windows and the rest are
standard library modules you shuck; porch_ask()
reads standard input, so a program can be fed from a file or a pipe:
cob_interp quiz.cob < answers.txt.
The .strawberry cache format is version COBSTRW10; caches written by earlier releases are detected and rebuilt.
popcorn_comp
popcorn_comp <file.strawberry> -o <output> [--no-gc] [--cc <compiler>] [--emit-c <path.c>]
Transpiles the bytecode to plain C, then spawns a real C compiler
to produce a native executable. Default backend is
Zig's zig cc —
a Clang-based drop-in C compiler that bundles libc/CRT files for
essentially every target in one install, which is what makes
CobOS/CobArch cross-compiling a plain
-target flag instead of needing a separately
installed cross-toolchain per platform. Release downloads bundle
Zig in a zig/ folder next to popcorn_comp
and find it automatically, so nothing else needs installing; when
building from source, put Zig on your PATH or pass
--cc.
Compiler is resolved in this order:
| --cc <path> | Explicit override, always wins. |
$CobCC | Environment variable override. |
$CobOS / $CobArch | Looked up in a table of Zig target triples. |
zig cc | Default: native compile, Zig auto-detects the host. |
CobOS=windows CobArch=amd64 popcorn_comp prog.strawberry -o prog.exe
# -> spawns: zig cc -target x86_64-windows-gnu ...
-l<module> and the standard library folder is recorded as its rpath. Two
consequences: the program must be linked dynamically (a static program can't use shared libraries —
and the Linux musl targets above are static), and a cross-compiled program needs those modules built for its
target, with COB_STDLIB pointing at them when you compile. Programs that use only the core language are unaffected.
--cc or $CobCC, popcorn_comp looks for zig cc. If you
don't have Zig, name your C compiler: CobCC=cc popcorn_comp prog.strawberry -o prog.
farmer
farmer harvest <package>
Fetches {registry}/api/v1/packages/<package>.json,
verifies the metadata's name field matches what was
requested, downloads the package zip, verifies its
sha256 if one was provided, and unzips it into
cob_modules/<package>/ — ready for
shuck <package>.
$COB_FARMER_BASE_URL | Override the registry base URL. |
The registry itself lives at Cob-Software-Foundation/cpi, served for free via GitHub Pages — no server, just static JSON files.
Docker 0.0.9
GitHub Actions builds, tests and publishes a container image (linux/amd64 and linux/arm64) with the interpreter
and REPL, popcorn_comp, farmer and the standard library — everything except
barn and tassel, which need a display or a long from-source build.
docker run -it --rm ghcr.io/cob-software-foundation/cob docker run --rm -v "$PWD:/work" ghcr.io/cob-software-foundation/cob hello.cob docker run --rm -v "$PWD:/work" ghcr.io/cob-software-foundation/cob popcorn_comp hello.strawberry -o hello
- The first command is the REPL. Anything that is not the name of another tool in the image (
popcorn_comp,farmer,sh) goes tocob_interp. - The image runs as an unprivileged user. To read and write your own files as yourself add
--user "$(id -u):$(id -g)". - A program compiled inside the image is for the image (its glibc, its
lib/): run it there with--entrypoint /work/hellorather than copying it to another machine. - Build it yourself with
docker build -t cob .; the build runs the whole test suite.