examples - pannous/warp GitHub Wiki

Examples

Hello World in Angle is
"Hello World"

The deep formal reason why this is a valid program is that the last object in a block is its return value and the last result in the root block of the main file is printed.

data

«Data is Code and Code is Data»
Everything in Wasp is a node, when it has children it is a list, when the children are of type key it's a map:
1 == [1] ≈ [a:1]

lists

[ 1 2 3 ] == ( 1 2 3 ) == { 1 2 3 } == 〔 1 2 3 〕== 1 2 3 …

All unicode brackets are parsed as lists〚…〛〖…〗『…』「…」 …

[ 1 2 3 ] + ( 4 5 ) = 1 2 3 4 5

types

data can be typed as classes or wit schema.

flags virtues={fast, safe, cheap}
virtues angle_goal = fast+safe
angle_goal.safe   # 1: a flags value is a record of bools (wit `flags`), {fast:1 safe:1 cheap:0}

data selectors

{a:1 b:2}.b == 2

tree data as first class citizen
{a:1 b:2 c:{d:3 e:4}}.c.d == 3

item selection

lists have a 0 based []index and 1 based #number selector:

x='abcde';x[0] == 'a'
x='abcde';x#4 == 'd'

broadcasting

Functions operating on single elements are automatically applicable to lists

square x:=x*x
square [1 2 3] == [1 4 9]

Bare square 1 2 3 broadcasts too: [1 4 9]. x² may need x*x depending on input method. Behavior can be refined via overloading

folding (left associative)

sum := fold +; sum [1 2 3]

fold + takes one list argument (result 6). Bare sum 1 2 3 is planned as an auto-collected fold (card fold-bare-arguments); keep the definition and call on one evaluation unit (:=…; …).

similarity operator

⅓ ≈ .33333

modules

use math sin π/2 == 1

Fibonacci in Angle is

fibonacci number = if number<2 : 1 else fibonacci(number - 1) + fibonacci it - 2

for more complete list of examples see syntax
https://github.com/pannous/wasp/tree/master/samples
https://github.com/pannous/wasp/blob/master/source/tests.cpp
https://github.com/pannous/wasp/blob/master/source/test_wasm.cpp
https://github.com/pannous/wasp/blob/master/source/test_angle.cpp
https://github.com/pannous/english-script-samples/tree/master
https://github.com/pannous/angle/tree/master/tests (old python tests)

Whole programs

The repository's samples/ folder holds runnable programs; warp samples/<name>.warp runs one. A few that show what a page of warp does:

  • crontab.warp: reads the cron table (exec sh "crontab -l") and shows it as a page, schedules in words ("every 10 minutes", "daily at 06:35", "at startup") and the log file in a column of its own. warp app samples/system/crontab.warp opens it in a window.
  • visualizer.warp, gpu_visualizer.warp: a tune plays while its spectrum is drawn, as bars or by a GPU shader (sound).
  • matching.warp: the forms of pattern matching in one program.
  • form_submit.warp, component_totals.warp: html pages with forms and components.
  • y_combinator.warp: factorial and Fibonacci through the Z combinator.
⚠️ **GitHub.com Fallback** ⚠️