radian628 / lispsmos

A LISP-y language that compiles to Desmos expressions.
58 stars 2 forks source link

LISPsmos

If you're coming here from that desmos plane video, note that this project has been succeeded by my new language, Desmoscript!

DOCUMENTATION HERE

Disclaimer: Despite what GitHub says, LISPsmos was not written in Common Lisp. The ".lisp" files are LISPsmos files.

LISPsmos is a LISP-like programming language that maps almost directly to Desmos expressions, offering an alternate, text-based workflow and tooling.

Along with most Desmos features, LISPsmos comes with builtin support for the following:

Features

Basic Usage

(= a 1) ;variable assignment
(-> a (+ a 1)) ;actions and arithmetic operators
(= tenDividedByFive (/ 10 5)) ;longer variable names are automatically made subscript

Functions

;The positive solution to the quadratic formula.
(fn quadraticFormulaPositiveSoln a b c (
    / 
    (+ (* -1 b) (sqrt (- (* b b) (* 4 a c)))) 
    (* 2 a)
))

Piecewises

;Print x if x>=0, and -x if x<0. Effectively mimics the absolute value function.
;You'll need to manually turn on the display for this (disabled by default)
(fn absoluteValue x (piecewise
    ((>= x 0) x)
    ((< x 0) (* -1 x))
))

Display

(displayMe ;indicates that the expression should be displayed
    (= y x) ;expression to display
    (color red) ;all subsequent arguments to displayMe are optional display settings
    (lineWidth 30) 
    (lineOpacity 0.2) 
    (lineStyle DOTTED)
)

Find-and-replace Macros

;macro that increments a variable
(defineFindAndReplace inc v (-> v (+ v 1)))
(= i 0)
;expands to (-> i (+ i 1))
(inc i)

JavaScript Evaluation Macros

;macro that calls the following function on its arguments
(evalMacro inc "return [['->', args[1], ['+', args[1], '1']]]")
(= a 0)
(inc a) ;application of the macro. All macros of this type are variadic.