StewartLang
The world's first programming language oriented towards our Lord and Savior Ben Stewart.
This fork is a "fancier" version with easier run/install instructions.
Write
Code should look like this:
stewart ben 4
tom ben stewarts 4
stewage ben
xotic
c&d stewart log
stewage! log
blooket {
console.log('beanie')
}
bean stewart beaner
Let's destructure the code a bit:
- The
stewart
operator defines a global variable. This defines a variable with the name ben
as the number 4. - The
tom
operator is an "if" statement.
- If the variable
ben
"stewarts" (equals) 4, then the variable is logged to the console. - Then, the if statement is returned with the
xotic
operator.
- The
c&d
(or Cease and Desist) operator defines a native function.
- Operators within native functions are marked with exclamation points (such as
stewage!
). - Native functions are compiled to JavaScript and executed when needed.
- This function uses the
stewage
operator in order to log its only argument, log
to the console.
- The
#blooket
operator defines an inter-op, implicitly executed JavaScript function. It may also be defined with arguments in a similar fashion to native functions. - The
bean
operator then explicitly calls the native function "stewart."
Of course, this is a joke programming language and has many bugs I need to sort out. Don't actually use this in production, it's not worth it (or is it)?
Installation
- Install Node.
- Log into the terminal/PowerShell as an administrator.
- Run
npm i -g stewlang
. If this throws a No Access error, run sudo npm i -g stewlang
. - StewLang has been installed!
Run
Just type stew <filename>
I.E. stew script.stew
.
Docs
Native functions
Native functions are simple functions directly defined within StewartLang.
They may take multiple arguments and are compiled into JavaScript from StewartLang.
Here is a more complicated example:
c&d add a b
stewart! result a plus b
stewage! result
xotic!
bean add 1 2
This is a simple function to add two numbers together. The valid operations for math operations within variable definitions are:
plus (joke about Blooket Plus) - Add
ben - Subtract
spencer - Multiply
corey - Divide
Operations can only be used within variable definitions as they would be much too complicated otherwise.
Interop
StewartLang, since it is written in JavaScript, has support for JavaScript interoperability. This is defined within the blooket
statement.
blooket {
var blook = await import('ben-module');
console.log(blook);
}
Interop statements end with a closed brace, or optionally, a pipe such as } xotic
to send output to a variable.
WARNING: All interop functions are executed implicitly, are forced to be asynchronous, and may execute before native functions.
If
If statements are named tom
.
stewart blooket 4 ben 2
tom blooket stewarts 2
stewage blooket
xotic
This is a very simple function.
The variable blooket
is defined as 4 ben 2
, or 4 - 2, which is 2.
If the variable blooket stewarts, or equals 2, the variable blooket is logged to the console.
The available conditions are as follows:
stewarts - equals
spencers - does not equal
coreys - greater than
toms - less than
Variables
Variables can be defined in a simple manner. The stewart
operator defines variables, and allows for mathematic functions to be embedded within a definition. Here is a short example.
stewart blooket 0 corey 0
This produces the famous NaN
value, because we are dividing 0 by 0. The list of mathematic definitions was defined at the bottom of Native functions.
Aside from math, the stewart
operator can also define strings and other content types.
stewart blooket Ben Stewart - Defines a string with the content "Ben Stewart"
stewart blooket2 true - Defines a boolean.
Functions
As we saw earlier, c&d
, blooket#
, tom
, stewart
, and many more are operators, but there are built-in functions we can give a brief overview of.
stewage
, stewage!
Logs an inferred value to the console. Specific checks are in place so that NaN can be logged, and variables that do not exist have their names logged as strings.
stewage fart - Is not defined, logs "fart"
stewage blooket - Is defined, logs "Ben Stewart"
bean
This cannot be used recursively within functions in order to be safe. This function calls another native function.
bean add arg1 arg2 - Adds arg1 and arg2
Examples
Express server
blooket {
let server = (await import('express')).default;
let app = server();
return app;
} xotic
c&d get path string
this.xotic.get(path, (req, res) => {
res.send(string);
});
xotic!
bean get /, hello world!
blooket {
this.xotic.listen(8080);
}
This uses a new feature, JavaScript embedded within native functions, as well as interop piping. You can see that variables in the context of native and interop functions must be referenced with this
.
And finally, running your code:
npx benstewart ./file.ben
Thank you for using StewartLang.