functional language introduction Functional Languages:

the language uses a sequence of statements to determine how to reach a certain goal. These are said to change the state of the program as each one is executed in turn.

Example: Java is Imperative Language

1
2
3
4
int total = 0;
int n1 = 1;
int n2 = 2;
total = n1 + n2;

Functional Languages:

The functional programming paradigm was explicitly created to support a pure functional approach to problem solving. Functional programming is a form of declarative programming.

Functional Languages provide features missing in imperative languages:

  • First-class function values and higher-order functions

    • First-class functions if it treats functions as first-class citizens. This means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures.

      • Example: max(1 3) => (max 1 3) in Schame

        schame
        ((lambda (x) (* x x)) )
        pass funtion as parameter and return the fucntion, which is unnamed function

  • Extensive polymorphism
    • Allows a function to be used on as general a class of arguments as possible
    • List type and operators
      • they have a natural recursive definition, and are easily manipulated by operating on their first element and (recursively) the remainder of the list
    • Structured function returns
    • Constructor (aggregates) for structured objects
    • Garbage collection

What is advantage of functional laugnage comparing to imperative language like java or c++

funtional language like schame can pass funtions as parameter, return those function and it doesn’t need assignment to variable, which makes it better understand of its semantics.