From Esolang
Jump to navigation Jump to search

Functional is an esoteric programming language that only use function calls like this:

print("Hello world!")

Even control structures, loops and variable declarations are function calls:

print("What's your name?\n")
set(name, input())
printf("Hello, %s\n", name)

Even comments are function calls:

rem("This is a comment.")


nop("nop function does nothing")

Data types

There are three data types:

  • Barewords: Unquoted string or numbers, like identifiers in other programming languages, for example: set(bareword, "string value") Most functions will treat barewords as an identifier. Numbers such as 12 are also barewords.
  • Strings: They can be quoted with "" or ''. For example: "Hello, world!", 'Naruto\'s file'
  • Code blocks: They are enclosed with { and }. For example: if (equals(a,b), {print("a equals to b") } )

Standard functions

  • set(var, value) Set variable to value
  • if(condition, code) Execute the code if condition is true or not zero/null.
  • if_else(condition, code, else) Expands to if(condition){code}else{else}
  • loop(code) An infinite loop.
  • while(condition, code) A while loop.
  • for(init, condition, incr, code)
  • function(name, ..., code) Create a new function. The ... lists all arguments.

Cat program

    set(user_input, input())
    print(concat(user_input, "\n"))

Functional as a Java scripting language

If the Functional virtual machine is written in Java, it can let the Functional programs call Java methods and create Java objects, like what the Rhino JavaScript engine did.

    set(fs, new(, "out.txt"))
    set(w, new(, fs))
    w.write("Hello, world!")
  }, java.lang.Exception, e {
    System.err.println("Error: ")

See also