Skip to content

Desmos scripting language and successor to LISPsmos.

Notifications You must be signed in to change notification settings

radian628/desmoscript

Repository files navigation

Desmoscript

Scroll down for setup instructions

Desmoscript is a programming language that compiles to Desmos graph state. It is designed to provide the features of Desmos with zero overhead and with a C-like syntax. The syntax is largely inspired by JavaScript, Rust, and Desmos itself.

Setup & Installation

There are two main ways to use Desmoscript (the former of which is described below):

  • RECOMMENDED: Through a VSCode extension which adds language support (syntax highlighting, errors, jump to definition, desmos-in-VSCode, etc.)
  • Through releases, which I upload occasionally. This is just a standalone compiler executable you can run.

Because of Desmoscript's... unorthodox... compile target, you can't just get it running normally. There is no built-in desmoscript runtime, and it can't output bytecode your machine nor any "real" VM can run. It outputs a Desmos graph, and it runs in Desmos. There are quite a few ways to get that Desmos graph from your file system into Desmos. The one I like to do is outlined below.

Warning: This extension is still in development and will likely have some bugs

  1. Install the VSCode extension (linked above)
  2. Install TamperMonkey or another similar browser extension. This extension easily lets you inject scripts into whatever pages you want. It's like an extension for letting you make your own extensions.
  3. Install the Desmoscript Loader userscript. Open or refresh Desmos. If you see a little box in the bottom right corner that looks like the image below, it's been properly loaded.

A light gray box with a text input containing the text "http://localhost:3000", followed by a button containing the text "Recompile", followed by a filled checkbox labeled "Auto-recompile."

  1. Type some desmoscript code into a file. This will do as a proof of concept. Make sure the file has the .desmo extension:
y = x ^ 2;
  1. Run the web server by right clicking the file and selecting "Run Desmoscript Web Server." Upon doing this, a new VSCode window should pop up containing some compiler output as well as a URL. If you open the URL in a browser, it should be full of Desmos graph state JSON.

A vscode window titled "DEsmoscript Server: sample.desmo". On separate lines, it contains the text "Annotate expressions with equivalent desmoscript" (with a text box), "Server is running at http://127.0.0.1:3000", "Close this window to shut down the server.", and "Status: Compilation was successful! (took 14ms)"

  1. Paste the URL into the URL box in the Desmos Loader.
  2. Hit "recompile" if it doesn't compile automatically!
  3. Try loading ./sample.desmo if you want to see more features in action.

Features

"variables"
var = 3;
"points"
pt = (3, 4);
"list comprehensions"
listComp = [(a, b) for a=[1..10], b=[1..10]];
"anonymous block expressions"
blk = {
temp = 3;
temp + temp
};
"functions"
fn double(x) {
x * 2
}
"piecewises"
fn abs(x) {
{ x >= 0: x, x < 0: -x, x < 0 }
}
"namespacing (maps to desmos folders)"
ns namespace {
innerExpr = 123;
}
namespace.innerExpr * 2;
"displayed expressions"
show y = x @{ colorLatex: ds(rgb(255, 0, 255)) }

Goals of Desmoscript

  • Highly performant— doing things the idiomatic way should incur little-to-no performance overhead. If the idiomatic way is not performant, a performant alternative should be available.
  • Easy to both write and read— C-like syntax is familiar to most programmers, and has an emphasis on compactness.
  • Able to be effectively used in large projects— A proper scoping system, namespacing, and file-splitting capabilities are used to help manage complexity in large projects.
  • Catch as many errors at compile-time as possible.
  • Allow Desmos to interface with the outside world— An extensible macro system should allow Desmoscript to import external data— for instance, Desmoscript macros could be used to add 3D models, SVG paths, or CSV data to a Desmos graph, automatically formatted as Desmos data.

Notable Desmoscript Projects

Want to see your project here? Send me a message or open an issue!

Creator Description Source Graph
radian628 MONUMENT OF BERNARD (2022-2023 Art Contest Winner) (Note: uses old version) Link Link
Lenny-the-burger 3-space Engine (Note: uses old version) Link Link
radian628 3D Parametric Editor (Note: uses old version) Link Link

Features (non-exhaustive)

  • arithmetic
  • functions
  • lists
  • ranges
  • points
  • list comprehension
  • namespaces
  • piecewises
  • multi-step expressions
  • integrals and derivatives
  • products and sums
  • displayed expressions
  • graph settings

Additional Contributors

Big thanks to the following people for helping with this project:

  • @Lenny-the-burger on GitHub.

About

Desmos scripting language and successor to LISPsmos.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •