Next

From Esolang
Jump to navigation Jump to search
Next
Paradigm(s) Functional
Designed by User:Hakerh400
Appeared in 2023
Computational class Turing complete
Major implementations Implemented
File extension(s) .txt

Next is an esolang invented by User:Hakerh400 in 2023.

Overview

In this esolang it is possible to see what the value of a variable will be in the future, based on the assumption that the result is equal to the current value of the variable.

This is a functional language. All variables are global and they can be referenced by names (strings). Values of variables are unbounded signed integers, initially 0.

Builtin functions:

  • get_var name - Get the current value of the variable whose name is name
  • set_var name val - Assign integer val to the variable whose name is name
  • next name n - Get the value of the variable name after exactly n assignments (to any variables)

Standard arithmetical operators are supported (+ - * / < <= > >= == /=), as well as if-then-else statements.

Note that next name 0 is equivalent to get_var name.

I/O format

Input and output are integers. The main function is main. The entire computation is performed inside the Nxt monad, which is just a continuation monad transformer whose inner monad is a state monad.

Example

main inp = do          -- The main function
  set_var "x" 5        -- Assign 5 to the global variable "x"
  x <- next "x" 1      -- Get the value of "x" after 1 assignment (it's 12) <--------------\
  set_var "x" (x + 7)  -- "x" is now 19, but it would be 12 if the result of next was 5 ---/
  return x             -- This returns 12 because the value of the local constant x is 12,
                       -- but the value of the global variable "x" is now 19

Implementation