Skip to content

A stack-based language with similarities to Fourier

Notifications You must be signed in to change notification settings

beta-decay/Noether

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Noether

Named after the mathematician Emmy Noether, Noether is a RPN (Reverse Polish Notation) stack-based programming language with similarities to the Fourier programming language. In particular, Noether was designed to be a more functional and more useful version of Fourier.

Links

Variables

To assign a value to a variable, you use the syntax

~i

Where ~ is the assignment function and i is the variable. This assigns the value on the top of the stack to the variable i.

If a variable is used that has not been previously assigned to, its value is automatically set to 0.

Functions have uppercase names so variables must have lowercase names to avoid raising an error.

Control Flow

If Statements

If statements are defined using curly brackets

If-then

An if-then statement is defined like so:

{<expression>}{<true code>}

If the stack at <expression> ends at 1, then the code at <true code> is run. Otherwise, the program continues past the if statement.

If-then-else

An if-then-else statement is defined like so:

{<expression>}{<true code>}{<false code>}

If the stack at <expression> ends at 1, then the code at <true code> is run. Otherwise, the code at <false code> is run.

While loop

A loop is defined using parentheses like so:

(<code>)

At the (, the exit condition for the loop is popped off the stack. If the top of the stack at ) equals the exit condition, then the loop ends and the program continues. Otherwise, the code goes back to ( and it loop again.

Built-in Functions

These are the functions which exist in Noether. They are subject to change without prior notice.

Zero argument functions

These functions do not pop anything off the stack

@

  • Clears the output screen

%

  • Rotates the stack. I.e. 11, 12, 13, 14 becomes 14, 11, 12, 13

I

  • Pushes the user input

N

  • Negates any number which follows it. E.g. N12P outputs -12.

$

  • Reverses the stack. I.e. 11, 12, 13, 14 becomes 14, 13, 12, 11

?

  • Prints a newline

!

  • Increments the variable which follows directly after the command (if the variable is a number). If variable had not been previously used, it is set to 1.

Single argument functions

All of these functions except P pop the top item off the stack

P

  • All types: Prints the top item of the stack

_

  • Number: Floors the number and returns the result
  • String: Makes all characters in the string lowercase

U

  • Number: Ceilings the number and returns the result
  • String: Makes all characters in the string uppercase

R

  • Number: Returns a random number from 0 to the given number
  • String: Shuffles the characters in the string

D

  • Number: The number given is the mode number (see Date Modes below) which dicates the part of the date pushed to the stack

;

  • Number: Pauses the program for the given number of seconds

L

  • Number: Returns the log 10 of the number
  • String: Returns the length of the string

#

  • All types: Pops the top item off the string and does nothing

W

  • Number: Converts number to string
  • String: Converts string to number

A

  • Number: Returns one of the stored constants according to the mode number (see Constant Modes below)
  • String: Returns one of the stored constants according to the mode name (see Constant Modes below)

B

  • Number: Returns the character with ASCII code n
  • String: Returns the ASCII code of the first character of the string

Double argument functions

All of these functions pop the top two items off the stack

+

  • Number and a Number: adds the two numbers and pushes the result
  • String and a Number: converts the number to a string, concatenates it to the string and pushes the result
  • String and a String: concatenates the strings and pushes the result

-

  • Number and a Number: subtracts the two numbers and pushes the result
  • String and a Number: deletes the character at the given index and pushes the result
  • String and a String: removes characters according to the given regex string from the first string and pushes the result

*

  • Number and a Number: Multiplies the two numbers and pushes the result
  • String and a Number: String multiplication

/

  • Number and a Number: Divides the two numbers and pushes the result
  • String and a Number: Pushes the character at the given index of the string
  • String and a String: Returns true if the string contains the given substring and false if not

^

  • Number and a Number: Raises one number to the power of the other number and returns the result
  • String and a String: Splits the first string by the second string and pushes all parts to the stack individually

=

  • All types: Returns true if top two items are equal and false if not

>

  • Number and a Number: Returns true if the first number is greater than the second number

<

  • Number and a Number: Returns true if the first number is less than the second number

&

  • All types: Performs a bitwise AND operation on the two top items of the stack

|

  • All types: Performs a bitwise OR operation on the top two items of the stack

T

  • Number and a Number: The first number is the number which is passed to the trig function, the second is the mode number (see Trig Modes below)
  • String and a Number: The number is the number which is passed to the trig function and the string is the mode name (see Trig Modes below)

Three argument functions

These functions pop three items off the stack

S

  • String, Number A, Number B: Slices the string from position A to position B

Date Modes

The function D pops the mode number off the stack:

  1. Pushes the number of seconds in the time
  2. Pushes the number of minutes in the time
  3. Pushes the number of hours in the time
  4. Pushes the number of days in the date  
  5. Pushes the number of months in the date
  6. Pushes the current year
  7. Pushes the ISO date string

Any other number will mean that D pushes the UNIX timestamp.

Trig Modes

The function T pops the number, x and the mode number/name:

  1. sin: Pushes the sine of x in radians
  2. cos: Pushes the cosine of x in radians
  3. tan: Pushes the tangent of x in radians
  4. asin: Pushes the arcsine of x
  5. acos: Pushes the arccosine of x
  6. atan: Pushes the arctangent of x
  7. DtoR: Converts x from degrees to radians
  8. RtoD: Converts x from radians to degrees
  9. pi: Pushes the value of pi (nothing is popped)
  10. tau: Pushes the value of tau (2*pi) [nothing is popped]

Constant Modes

The function A pops the mode number/name:

  1. alpha: Pushes the string "abcdefghijklmnopqrstvwxyz"
  2. ALPHA: Pushes the string "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  3. nums: Pushes the string "0123456789"
  4. pi: Pushes the value of pi
  5. e: Pushes the value of e (the base of the natural logarithm)

Example Programs

Hello World

"Hello, World!"P

Try it online!

Prints the phrase "Hello, World!".

Explanation:

"Hello, World!"  - Push the string "Hello, World!"
               P - Print the top of the stack

Quine

"~a34BPaP34BPaP"~a34BPaP34BPaP

Try it online!

Outputs its own source code

Explanation:

"~a34BPaP34BPaP"~a             - Push the string "~a34BPaP34BPaP" ans stores in the variable a
                  34BP         - Print the character with ASCII code 34 (")
                      aP       - Print the variable a
                        34BP   - Print the character with ASCII code 34 (")
                            aP - Print the variable a

Fibonacci Numbers

1~a~bI(aPb+~cb~ac~b?!i)

Try it online!

Outputs the first n Fibonacci Numbers, where n is given as input.

Explanation:

1                       - Push 1 onto the stack
 ~a                     - Store 1 in a
   ~b                   - Store 1 in b
     I(               ) - Loop until the top of the stack equals the input
       aP               - Print a
         b+             - Add a and b
           ~c           - Store the result in c
             b~a        - Set a equal to b
                c~b     - Set b equal to c
                   ?    - Print a newline
                    !i  - Increment i

About

A stack-based language with similarities to Fourier

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published