Skip to main content Svelte Highlight v7.21.1

Bend language preview

1. Binary tree sum

a type definition with recursive fields, and bend/fold
horizon-dark
# a binary tree sum
type Tree:
  Node { ~lft, ~rgt }
  Leaf { val }

def sum(tree):
  match tree:
    case Tree/Node:
      return sum(tree.lft) + sum(tree.rgt)
    case Tree/Leaf:
      return tree.val

def main():
  bend x = 0:
    when x < 3:
      fold x = x + 1
    else:
      return #done
atom-one-dark
# a binary tree sum
type Tree:
  Node { ~lft, ~rgt }
  Leaf { val }

def sum(tree):
  match tree:
    case Tree/Node:
      return sum(tree.lft) + sum(tree.rgt)
    case Tree/Leaf:
      return tree.val

def main():
  bend x = 0:
    when x < 3:
      fold x = x + 1
    else:
      return #done
github-dark
# a binary tree sum
type Tree:
  Node { ~lft, ~rgt }
  Leaf { val }

def sum(tree):
  match tree:
    case Tree/Node:
      return sum(tree.lft) + sum(tree.rgt)
    case Tree/Leaf:
      return tree.val

def main():
  bend x = 0:
    when x < 3:
      fold x = x + 1
    else:
      return #done
dracula
# a binary tree sum
type Tree:
  Node { ~lft, ~rgt }
  Leaf { val }

def sum(tree):
  match tree:
    case Tree/Node:
      return sum(tree.lft) + sum(tree.rgt)
    case Tree/Leaf:
      return tree.val

def main():
  bend x = 0:
    when x < 3:
      fold x = x + 1
    else:
      return #done
nord
# a binary tree sum
type Tree:
  Node { ~lft, ~rgt }
  Leaf { val }

def sum(tree):
  match tree:
    case Tree/Node:
      return sum(tree.lft) + sum(tree.rgt)
    case Tree/Leaf:
      return tree.val

def main():
  bend x = 0:
    when x < 3:
      fold x = x + 1
    else:
      return #done
github
# a binary tree sum
type Tree:
  Node { ~lft, ~rgt }
  Leaf { val }

def sum(tree):
  match tree:
    case Tree/Node:
      return sum(tree.lft) + sum(tree.rgt)
    case Tree/Leaf:
      return tree.val

def main():
  bend x = 0:
    when x < 3:
      fold x = x + 1
    else:
      return #done

2. Lambdas

the lambda and λ syntax variants
horizon-dark
double = lambda x: x * 2
triple = λx (* x 3)
atom-one-dark
double = lambda x: x * 2
triple = λx (* x 3)
github-dark
double = lambda x: x * 2
triple = λx (* x 3)
dracula
double = lambda x: x * 2
triple = λx (* x 3)
nord
double = lambda x: x * 2
triple = λx (* x 3)
github
double = lambda x: x * 2
triple = λx (* x 3)

3. Dups and superpositions

the ! duplication operator and {a b} superpositions
horizon-dark
! x = 5
{y z} = {x x}
result = y + z
atom-one-dark
! x = 5
{y z} = {x x}
result = y + z
github-dark
! x = 5
{y z} = {x x}
result = y + z
dracula
! x = 5
{y z} = {x x}
result = y + z
nord
! x = 5
{y z} = {x x}
result = y + z
github
! x = 5
{y z} = {x x}
result = y + z