MyScript

From Esolang
Jump to navigation Jump to search

MyScript is an esolang created by User:PythonshellDebugwindow.

Syntax

Functions

Functions in MyScript are different in that they don't need brackets, e.g. function() -> function and add(a, b) -> add a b. This means that functions can't have arbitrary amounts of arguments (but an array could easily be used instead). So what in many languages would be

B(A(D()), C(D(), B(E(), D()), E())))

if instruction A takes 1 argument, B takes 2, C takes 3, and D and E both take none, then the equivalent MyScript code would be

B A D C D B E D E

User-Defined Functions

To create one:

var fname is func *args
  ...

To return:

return

Or:

return val

Function to print Hello World:

var printHelloWorld is func
  say "Hello, World!"

Function to add 2 numbers:

var add2Numbers is func firstNum secondNum
  return add firstNum secondNum

Function to sum an array (this one’s a bit more advanced):

var sumArray is func a
  var res is 0
  var i is 0
  while less i arrlen a,
    res is add res itemat a i
    i is add i 1
  return res

Variables

To create one:

var vname is val

To modify one once created:

vname is val

To access one once created:

vname

Math

To add A and B:

add A B

To subtract them:

subtract A B

Multiply:

multiply A B

Divide:

divide A B

Switch

In MyScript, the keywords if and else keywords are used with the check keyword to form a switch statement:

check val?
  if value1,
    ...
  if value2,
    ...
  ...
  if valueN,
    ...
  else,
    ...

if is like case, and else is like default. You can have any amount of ifs, and 0 or 1 elses.

While

Executes code while condition converted to a boolean evaluates to yes (true):

while condition,
  code

Loops until the user says "stop":

say "Say 'stop' to stop"
while not equals ask "stop",
  say "Say 'stop' to stop"
say "You said 'stop'"

Datatypes

Datatype Example
Integer 123
Float/double 123.45
String "abc\nThis is a \"test\""
Boolean yes
Array [123, 4.5, "s", no, 0, 3.14159]

Strings only use double quotes (valid escape sequences are \0, \n, \\, \t, \f, and \"), and Boolean true is represented by yes and false by no.

Examples

Hello, World!

say "Hello, World!"

Cat

say ask

Infinite cat

while yes,
  say ask

Truth-machine

check ask?
  if "1",
    while yes,
      say "1"
  else,
    say "0"

Simple class

var MyClass is func prop
  return [prop]
var MyClass_myMethod is func obj
  say concat "obj.prop: " itemat obj 0
var MyClass_getProp is func obj
  return itemat obj 0
var myObject is MyClass "Hello!"
MyClass_myMethod myObject

This should print obj.prop: Hello!.