3 votes

What is the most advanced or creative program you can create using the LOX programming language?

Lox is a toy programming language that is designed in Java and C at craftinginterpreters.com.

My challenge to you is: given the constraints of the Lox language, what are some creative or advanced programs you can create?

This page provides a rundown of the design of Lox.

To kick it off, here's a simple function that estimates the value of pi:

fun estimatePi(rounds) {
	var pi = 0;
	var alt = 1;
	for (var i = 0; i < rounds; i = i + 1) {
		pi = pi + alt * 4/(2 * i + 1);
		alt = -alt;
	}
	return pi;
}

print "The value of pi is:";
print getPi(100000);

4 comments

  1. [4]
    arqalite
    Link
    I'll admit I skimmed the whole thing, but besides the lack of a standard library and I/O, are there any other limitations? This seems perfectly suited for mathematical problems as long as you can...

    I'll admit I skimmed the whole thing, but besides the lack of a standard library and I/O, are there any other limitations?

    This seems perfectly suited for mathematical problems as long as you can implement most concepts. Also you can probably do some really fun ASCII stuff since you have string concatenation.

    The syntax is nice, not the greatest, but considering it's a theoretical language that isn't meant to solve a real-world problem, it's completely adequate.

    4 votes
    1. [3]
      Beenrak
      Link Parent
      I agree, this seems to have basically everything you would need to make any non-graphical program you wanted? There's no default list, but it has classes so you could create a pretty simple...

      I agree, this seems to have basically everything you would need to make any non-graphical program you wanted? There's no default list, but it has classes so you could create a pretty simple LinkedList to handle that.

      Honestly, the more interesting questions is what cant you make. What features are missing that prohibit certain styles of application.

      2 votes
      1. [2]
        Power0utage
        Link Parent
        Off the top of my head, it's missing: any form of input/reading files -- this seems like the biggest barrier to me any form of outputting other than just printing, so no way to store information...

        Off the top of my head, it's missing:

        • any form of input/reading files -- this seems like the biggest barrier to me
        • any form of outputting other than just printing, so no way to store information
        • modularity
        • lists (could be created, as you mention)
        1. Beenrak
          Link Parent
          What do you mean by modularity?

          What do you mean by modularity?

          1 vote