We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Lox

From Esolang
Jump to navigation Jump to search
This article is not detailed enough and needs to be expanded. Please help us by adding some more information.
Lox
Designed by Robert Nystrom
Appeared in 2015
Computational class Turing-complete
Reference implementation jlox
clox
Major implementations Implement it yourself!

Lox is a pedagogical programming language designed to be implemented by students of compiler theory. It was introduced in the book Crafting Interpreters.

Examples

Hello, world! program

print "Hello, world!";

Looping counter

var string = "";
while (true) {
  string = string + "*";
  print string;
}

FizzBuzz

fun modulo(a, b) {
  var k = 0;
  while (a - k * b >= b) {
    k = k + 1;
  }
  return a - k * b;
}
var counter = 1;
while (counter < 20) {
  var fizz = false;
  var buzz = false;
  if (modulo(counter, 3) == 0) {
    fizz = true;
  }
  if (modulo(counter, 5) == 0) {
    buzz = true;
  }
  if (fizz and buzz) {
    print "FizzBuzz";
  } else if (fizz) {
    print "Fizz";
  } else if (buzz) {
    print "Buzz";
  } else {
    print(counter);
  }
  counter = counter + 1;
}

Self-interpreter

See here. Note that they use modified versions of Lox as the book version does not have many basic facilities such as input.

See also