tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

intro.tri (2252B)


      1 !export *
      2 
      3 -- Start here: a small tricu language guide.
      4 -- Lines beginning with -- are comments. Read down, then try the exports.
      5 -- Edit this source in place; valid edits compile after a short pause.
      6 -- Write a call in Evaluate tricu expression, then press Evaluate.
      7 -- Imports/exports declare a module; this introductory one needs no libraries.
      8 
      9 -- 1. Definitions give a name to a value: name = expression.
     10 -- Every value is a tree. These are the three constructor forms.
     11 leaf = t
     12 stem = t t
     13 fork = t t t
     14 -- Evaluate leaf, stem or fork with tricu ยท t source to see its structure.
     15 
     16 -- 2. A lambda names an input before the colon and returns an expression.
     17 identity = (x : x)
     18 -- Try identity "Hello!" with Text, then identity 42 with Natural number.
     19 
     20 -- 3. Named parameters are a convenient way to write functions.
     21 -- This is equivalent to first = (a b : a).
     22 first a b = a
     23 -- Try first 7 9: it returns the first of its two arguments.
     24 
     25 -- 4. Application is written with spaces and groups to the left.
     26 -- first 7 9 means (first 7) 9. Parentheses group an expression explicitly.
     27 answer = identity (first 42 7)
     28 -- Evaluate answer with Natural number: the result is 42.
     29 -- A name by itself needs no further arguments; [] is an empty-list value.
     30 
     31 -- 5. Numbers, quoted strings and lists are convenient tree literals.
     32 greeting = "Hello from tricu!"
     33 numbers = [1 2 3]
     34 -- Evaluate greeting with Text, or numbers with Bytes to display [1, 2, 3].
     35 -- Bytes requires a list of naturals in 0..255; use t source for other lists.
     36 -- Lists use spaces, not commas: try identity [4 5 6].
     37 
     38 -- 6. The result interpretation tells the playground how to read a tree.
     39 -- Use Text for a string, Natural number for a number, or t source for any tree.
     40 -- Pure value observes the result; Browser IO interprets an IO action tree.
     41 -- The Conversation demo shows input, output and continuations.
     42 
     43 -- Settings also offers structured arguments and stored-definition inspection.
     44 -- Edits stay local; Restore original returns to the published source.
     45 -- For an application spanning lines, put the entire call in parentheses.
     46 -- Other demos import libraries by immutable manifest hash, shown in their headers.
     47 -- Next: Tree microscope shows how functions can inspect other program trees.