Skip to content

function

Pannous edited this page Sep 18, 2021 · 6 revisions

Functions can be defined in the following natural ways:

function square (n: number){ n*n }
to square a number: return it * it
square of a number = it * it
square(number n)=n*n
square(n)=n*n
square:=it*it

The parser should differentiate between variables and functions via these heuristics:

  1. functions have braces left of the assignment square(n)=n*n or
  2. functions have blocks right of the assignment square = {it*it} or
  3. functions use := for the assignment square:=it*it

The difference to square=it*it is that variables get evaluated instantly and only once, whereas The function square:=it*it is a dangling closure

Under the hood all are represented equally: as the charged data

square = {it*it}

Together with an entry in the pattern dictionary [:square, number] => &square denoting that the symbol 'square' together with the type number should be resolved to the function square.

Functions are unary prefix operators, that is in an expression a f b c they get parsed as a (f (b c))

Every function generates a suffix operator: square 2 == 2 squared

Todo : do they have the same precedence? I.e. does
square 1+2 == 1+2 squared
square 1+2 == 1 + (2 squared) ?

Home

Philosophy

data & code blocks

features

inventions

evaluation

keywords

iteration

tasks

examples

todo : bad ideas and open questions

⚠️ specification and progress are out of sync

Clone this wiki locally