Andrew's Programming Language

From Esolang
(Redirected from User:Afarnen/APL)
Jump to navigation Jump to search
This is still a work in progress. It may be changed in the future.

Andrew's Programming Language is a work-in-progress language created by User:Afarnen. It also needs a name (please help; I'm horrible at naming).

Intro

Let's create a variable x with a value of 5, you'd write:

x=5

Now, let's create another variable y:

y=2*x

In this example, y equals 10. Now what if we updated the value of x:

x=3.5

Would y update along with x? Yes, y now equals 7. You can implement many simple functions similarly. For example:

c=(f-32)*5/9

is a simple fahrenheit to celsius convertor. The variable c updates every time f is updated. But what about recursive functions, like the fibonacci function?

fib(1)=1
fib(2)=1
fib(x)=fib(x-2)+fib(x-1)

Since variables cannot recurse, we use actual function notation, in this example to implement the fibonacci function.

Creating an array is simple:

x=1,2

It's just creating a variable with more than one value, separated by commas. You can perform regular operations on a whole array at a time:

y=2*x

Each item in the array is operated on separately, and then put back together. In this case, y would equal 2,4. Functions can also perform on arrays:

fib(5,7)

Since the 5th and 7th fibonacci numbers are 5 and 13 respectively, this example would return 5,13. Now what if our function accepted two arguments, such as a power function:

power(x,y)=x^y

Function parameters, as well as array items, are separated by commas, so how would we work around this if we wanted to perform the above function on an array? "power(1,2,3,2)" could be interpreted many different ways, so we..

power((1,2,3),2)

Use parenthesis to distinguish each parameter. Here we're squaring the array 1,2,3, so we get 1,4,9.

Conclusion

It's basically "set-by-name". As far as we know, functions are array transforms.