-
Notifications
You must be signed in to change notification settings - Fork 0
User Defined Operators
You can define your own prefix, infix, postfix and even mixfix operators within the language.
To define an operator you use the following syntax:
[export] [lazy] operator <template-string> <associativity> <precedence> <implementation>;
For example in listutils.fn we define:
export operator "_|>_" left 8 fn (lst, f) { map(f, lst) };
<template-string> is a pattern, the underscores are "holes" for argument expressions.
Prefix operators will look like i.e. "??_" and postfix operators like "_??".
Mixfix operators might be like "_?_:_"
<associativity> is one of left, right or none.
<precedence> is an integer. Currently precedences range from 0 to 15 but there are no
limits imposed.
<implementation> is a function name or anonymous function definition.
Operators must be marked for export if you plan to import them from the namespace they are defined in.
Lazy operators take their arguments as unevaluated thunks like lazy functions and force them at the point of use.
Due to a limitation in the parser you cannot declare both an infix and a postfix operator with the same symbol.

CEKF(s) a.k.a. F Natural a.k.a F♮