Andrew's Functional Programming Language

From Esolang

Jump to: navigation, search

Andrew's Functional Programming Language , or AFPL, is the name of an idea for a functional, turing-complete programming language designed by User:Afarnen in 2008. The language, as well as the name, is a work-in-progress.

Contents

[edit] Variable definitions

Variables in AFPL are described, rather than assigned and updated, in relation to numbers and other variables.

X= 5
Y>X
12Y=Z

The previous example describes variables X, Y, and Z. X is given a single numeric value, while Y and Z cannot evaluate that far, since Y could be anything greater than 5, and Z depends on Y. Here's a program that converts degrees Fahrenheit to degrees Celsius:

C=(F-32)(5/9)

The only missing piece is F. Without it, C cannot evaluate fully:

F=212

Variables don't always have to evaluate to a single numerical value. Here's a program that uses variables to mimic the metric system:

Km=1000M
M=100Cm
Cm=10Mm

If we then wrote the code:

X=10Cm

X could then be evaluated to equal 100Mm, 0.1M, etc. As you can see, alot can be done with just variable definitions.

[edit] Functions

F(X): 5X-1

The previous example defines a function F with parameter X. Unlike what we did before with variable definitions, functions are very extensible, and much more practical for many things. For instance, we can use the same function over more than once with different parameter values:

Foo=F(5)
Bar=F(6)

The previous example is two variable definitions, which show how functions are called. Functions can also recurse, which means call itself, within itself. One good example is the McCarthy 91 Function:

M(N>100): N-10
M(N<=100): M(M(N+11))

You may have noticed that in order to do different things in functions, depending on the parameter(s), you simply define the function once for each possible situation. The above example means "If N is greater than 100, then do this...If N is less than or equal to 100, do this..."

[edit] Operations

[edit] Addition

X+Y

[edit] Subtraction

X-Y

[edit] Division

X/Y

[edit] Multiplication

XY

or

X*Y

[edit] Exponentation

X^Y

[edit] More info

There are no data types in AFPL. That means that you don't define a variable as being "int", "float", "double", etc.

All variable names as well as function names must start with an uppercase letter, and all characters after are restricted to lowercase letters, numbers, or underscores (_)

For example, these variable names are incorrect:

FOO
bar
_bLaH
12Ab

These are correct:

Foo
Blah_
Ab12

This rule is so that variable and function names can be prepended to eachother (used for multiplication) without conflict.

Personal tools