Discuss Scratch

NFlex23
Scratcher
1000+ posts

StackLisp v2 Documentation


(StackLisp)
version “2”

Documentation & examples

This is the documentation for the StackLisp programming language (version 2 only). Feel free to post questions and programs here as well!

Comments

Comments are surrounded by /* and */, for example:
/* (print "This code won't run") */
(print "But this will")
Builtin functions

Operators: +, -, *, /, %, ^, =, !=, <, >, <=, >=
Example
(= (+ (* 2 3) 5) 11)

Mathematical functions: abs, sin, cos, tan, sqrt, rand
Example
(print (+ "The absolute value of the sine of 56 is " (abs (sin 56))))
(print (+ "A random number from 1 to 10 is " (rand 1 10)))

Strings: letter, length
Index is 0-based.

Example
(define input (get-input "Enter some text: "))
(print (length input))
(print (letter 1 input))

Booleans: and, or, not
Example
(or false (and (not false) true))

Input & output: print, get-input, clear
Example
(print (+ "Hello, " (get-input "What is your name? ")))
Special forms

Define: (define name value)
Bind a variable to a value. You can not redefine a variable; instead use set.

Example
(define code (get-input "Enter your savecode: "))

Set: (set name value)
Set an existing variable.

Example
(define counter 0)
(set counter (+ counter 1))

Defun: (defun name *args? *body)
Define a function. When the function is called, it creates a new scope that new variables are defined in.

Example
(defun add a b (+ a b))

Return: (return value?)
Return from a function, with an optional return value.

Example
(defun add a b
  (return (+ a b))
  (print "This function won't be run"))

If: (if condition true-body false-body)
Run code based on a condition.

Example
(if (= (+ 1 2) 3) (print "1 + 2 = 3") (print "!?"))

When: (when condition *body)
Similar to if, but without a false body.

Example
(when (= score 10) (define coins (+ coins 1)))

While: (while condition *body)
Execute a block of code until the condition is false.

Example
(define i 0)
(while (< i 10)
  (print i)
  (define i (+ i 1)))

Forever: (forever *body)
Execute a block of code forever.

Example
(forever (print "Looping forever!"))

Break: (break)
Break out of a loop.

Example
(forever (print "Running... once?") (break))

Do: (do *body)
Fit multiple statements in one; useful for if.

Example
(define adding true)
(if adding
  (do
    (print "Adding")
    (+ 1 1))
  (do
    (print "Subtracting")
    (- 3 2)))

Scope: (scope *body)
The same as do but also creates a new scope.

Example
(scope (define a 1))
(print a) /* Error! */

No-refresh: (no-refresh *body)
Similar to do but runs without screen refresh.

Example
(no-refresh
  (forever
    (print "Here's some free lag!")))

Last edited by NFlex23 (Nov. 11, 2022 15:44:39)

Epsilon_3
Scratcher
500+ posts

StackLisp v2 Documentation

Neat! I'll try to make a simple program right now.
impozible
Scratcher
40 posts

StackLisp v2 Documentation

thank you for docs!
MegaEliteCoder
Scratcher
100+ posts

StackLisp v2 Documentation

Let’s say you made a factorial function
If you do print(fact 6)
Would it print that functions return value? If yes that’s pretty impressive
NFlex23
Scratcher
1000+ posts

StackLisp v2 Documentation

MegaEliteCoder wrote:

Let’s say you made a factorial function
If you do print(fact 6)
Would it print that functions return value? If yes that’s pretty impressive
Yes, there are many examples in the docs.
MegaEliteCoder
Scratcher
100+ posts

StackLisp v2 Documentation

NFlex23 wrote:

MegaEliteCoder wrote:

Let’s say you made a factorial function
If you do print(fact 6)
Would it print that functions return value? If yes that’s pretty impressive
Yes, there are many examples in the docs.

I just realized that’s literally the example you used in your project
MegaEliteCoder
Scratcher
100+ posts

StackLisp v2 Documentation

So for my language I was able to make functions but I couldn’t make functions with return values work since

Print(concat(fact(8),” is 8!”))

Since running the function fact messes up the evaluation of prints Params
--Eggs--
Scratcher
12 posts

StackLisp v2 Documentation

for the while loops does it have like a list of all the loops it's in so it can keep track or at the while end does it just go back to the beginnig of the loop?
NFlex23
Scratcher
1000+ posts

StackLisp v2 Documentation

--Eggs-- wrote:

for the while loops does it have like a list of all the loops it's in so it can keep track or at the while end does it just go back to the beginnig of the loop?
It goes back to the beginning of the loop if the condition is still true.
TommyIsntHere
Scratcher
21 posts

StackLisp v2 Documentation

e
TommyIsntHere
Scratcher
21 posts

StackLisp v2 Documentation

is there (function())?
NFlex23
Scratcher
1000+ posts

StackLisp v2 Documentation

TommyIsntHere wrote:

is there (function())?
If you mean calling a self-defined function, you have to do it like this: (function)
34LiuKevin2
Scratcher
100+ posts

StackLisp v2 Documentation

someone go post me a ____ for a scratch in stacklisp
Brandon1615
Scratcher
3 posts

StackLisp v2 Documentation

Oh no, I'm doomed!
34LiuKevin2
Scratcher
100+ posts

StackLisp v2 Documentation

coderyay1234
Scratcher
4 posts

StackLisp v2 Documentation

Wow! Teach me how to make a programing language in scratch!

Last edited by coderyay1234 (Oct. 9, 2025 17:24:22)

Powered by DjangoBB