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.
SockZ
- This article is not detailed enough and needs to be expanded. Please help us by adding some more information.
SockZ is a small stack-based programming language able to work with big relative integers. It features only a minimalist set of instructions but allows easy definition of functions (eg to handle fractions or polynomials).
It was not intended to be an esoteric language, but rather as a home-brewed programming language, as simple as possible, for working with large numbers.
Fast Documentation
| Command | Description |
|---|---|
#FunctionName
|
Defines a function (shall exit with END) |
.LabelName
|
Defines a label |
FunctionName
|
Executes function (returns when END is encountered) |
LabelName
|
Jumps to the label |
END
|
Return from current function or end the program |
QUIT
|
Quit the program |
CR
|
New line |
HPRINT
|
Removes and prints the top of stack in hexadecimal |
INPUT
|
Ask for a decimal number and put it on stack (escape quits) |
PRINT
|
Removes and prints the top of stack in decimal |
"SockZ"
|
Prints the string "SockZ" on screen |
"RuleZ+LF
|
Prints the string "RuleZ" on screen (not recommended) |
| Command | Stack before | Stack after | comment |
|---|---|---|---|
12345
|
.. C B A | .. C B A 12345 | |
-6789
|
.. C B A | .. C B A -6789 | |
COPY
|
.. C B A | .. C B A A | |
COPY2
|
.. C B A | .. C B A B A | |
DROP
|
.. C B A | .. C B | |
DROP2
|
.. C B A | .. C | |
OVER
|
.. eN .. e2 e1 N | .. eN .. e2 e1 eN | |
OVER2
|
.. C B A | .. C B A B | |
SIZE
|
eM .. e1 | eM .. e1 M | ;size of stack |
SWAP
|
.. eN .. e2 e1 N | .. e1 .. e2 eN | |
SWAP2
|
.. C B A | .. C A B | |
TIME
|
.. C B A | .. C B A TIME | ;32 bits internal clock |
+
|
.. C B A | .. C B+A | |
-
|
.. C B A | .. C B-A | |
*
|
.. C B A | .. C B*A | |
/
|
.. C B A | .. C B%A [B/A] ;rest and quotient, error if A=0 | |
NEG
|
.. C B A | .. C B -A | |
ABS
|
.. C B A | .. C B abs(A) | |
AND
|
.. C B A | .. C (abs(B) AND abs(A)) | |
EOR
|
.. C B A | .. C (abs(B) EOR abs(A)) | |
LOG2
|
.. C B A | .. C B [log2(abs(A))] | ;-1 if A=0 |
OR
|
.. C B A | .. C (abs(B) OR abs(A)) | |
<<
|
.. C B A | .. C B<<A | ;B>>-A if A<0 |
>>
|
.. C B A | .. C B>>A | ;B<<-A if A<0 |
SKIP=0
|
.. C B A | .. C B | ;If A=0 then skip next instruction |
SKIP<>0
|
.. C B A | .. C B | ; A<>0 |
SKIP>0
|
.. C B A | .. C B | ; A>0 |
SKIP<0
|
.. C B A | .. C B | ; A<0 |
SKIP>=0
|
.. C B A | .. C B | ; A>=0 |
SKIP<=0
|
.. C B A | .. C B | ; A<=0 |
SKIP=
|
.. C B A | .. C | ;If B=A then skip next instruction |
SKIP<>
|
.. C B A | .. C | ; B<>A |
SKIP>
|
.. C B A | .. C | ; B>A |
SKIP<
|
.. C B A | .. C | ; B<A |
SKIP>=
|
.. C B A | .. C | ; B>=A |
SKIP<=
|
.. C B A | .. C | ; B<=A |
Note: The normal definition for the Euclidian division in Z is:
For every B in Z and A in Z* there exist a couple (Q;R) in Z*Z such that B=A*Q+R and 0<=abs(R)<abs(A).
Problem is that this does not lead to a unique couple (Q;R), which is unsuitable for computing, so i used the following definition:
For every B in Z and A in Z*, there exist a unique couple (Q;R) in ZxZ such that B=A*Q+R, 0<=abs(R)<abs(A), sgn(R)=sgn(B) & sgn(Q)=sgn(A)*sgn(B).
examples:
-7 = 3 * (-2) + (-1) [B=-7; A=3] 21 = -4 * (-5) + 1 [B=21; A=-4] -13 = -2 * 6 + (-1) [B=-13; A=-2]
Example program
;Comments start with a semicolon (as in assembly)
INPUT ;ask for a number n
COPY PRINT "!=" ;print it followed by "!="
! PRINT ;compute n! then print it
END
;Recursive factorial function, input=... n, output=... n!
#! ;Functions start with a sharp and return with END
COPY ;... n n
SKIP>0 !end ;go to !end if n<=0
COPY ;... n n
1 ;... n n 1
- ;... n n-1
! ;... n (n-1)!
* ;... n!=n*(n-1)!
END ;quit function
.!end ;Labels start with a dot
DROP 1 END ;return 1 when n<=0