I've always been a fan of array-based programming languages, but I feel like that most popular ones (J, K) are needlessly unreadable. I discovered Nial a while ago while researching array-based programming languages and found that it was pretty much what I wanted.
I will try to give you an extremely brief introduction here, but you should really download it from their page (http://www.nial.com/) which has a great implementation guide, as well as manuals in their documentation ZIP package.
> p :+ 1.5 1.6
> q := 3 4
> p * q
4.5 6.4
> * p q
4.5 6.4
> + * p q
10.9
There exists several forms for writing vectors/lists in Nial:
s := 3
v := (3 4)
m := [2 3 4, 5 6 7]
> + v
7
> + m
10 18 28
> each + m
9 18
In the K tutorial they have psuedo-code which looks like Nial code.
> v + v
6 8
> v eachleft < v
[false true, false false]
> v eachright < v
[false false, true false]
Keep in mind, I am lieing here. true is actually represented as 'l' and false is represented by 'o'. Strange, but it works.
> v * m
[6 9 12, 20 24 28]
> + * v m
26 33 40
Function currying is done on the left side.
(2 *) m
[4 6 8, 10 12 14]
Given a list of cashflows c that come at corresponding times t with a prevailing discount rate d, then ...
> c := 0.1 0.1 1.1
> t := 1 2 3
> pv is op c t d { + * c (d power t) }
> pv c t 0.9
0.9729
I don't really follow the last example, and it doesn't translate to Nial because Nial requires the shapes to match up. So giving an array of 4 to PV doesn't work. If they keep it to an array of 3 it does.
> pv c t (1 0.9 .81)
.765585
> pv c t (0.9 .81 .729)
0.581773
This gets a different answer from what they show though. Shrug.
Nial also has indexing primitives like k.
> t
1 2 3
> t@1
2
> m
[2 3 4, 5 6 7]
> m@1
5 6 7
You have to be careful how you define your variables to have indexing work right (which is frustrating). For example:
> a := [2 3 4, 5 6 7]
> 1 2 pick a
?address
> b := 2 3 reshape 2 3 4 5 6 7
> 1 2 pick b
7
> shape a
2
> shape b
2 3
> shape a@1
3
> b@(1 2)
7
When defined the first way, a doesn't understand the shape of the sublists. So you have to manually touch it to see what it is. Lame.
> a := 2 3 reshape link a
> a
[2 3 4, 5 6 7]
LINK forces a into a single list, and reshape changes the shape of A so the outer-most container understands what it is. '2 3 reshape A' will make a shape that is 2 3, but it wont be what you want.
I will try to give you an extremely brief introduction here, but you should really download it from their page (http://www.nial.com/) which has a great implementation guide, as well as manuals in their documentation ZIP package.
There exists several forms for writing vectors/lists in Nial: In the K tutorial they have psuedo-code which looks like Nial code. Keep in mind, I am lieing here. true is actually represented as 'l' and false is represented by 'o'. Strange, but it works. Function currying is done on the left side. Given a list of cashflows c that come at corresponding times t with a prevailing discount rate d, then ... I don't really follow the last example, and it doesn't translate to Nial because Nial requires the shapes to match up. So giving an array of 4 to PV doesn't work. If they keep it to an array of 3 it does. This gets a different answer from what they show though. Shrug.Nial also has indexing primitives like k.
You have to be careful how you define your variables to have indexing work right (which is frustrating). For example: When defined the first way, a doesn't understand the shape of the sublists. So you have to manually touch it to see what it is. Lame. LINK forces a into a single list, and reshape changes the shape of A so the outer-most container understands what it is. '2 3 reshape A' will make a shape that is 2 3, but it wont be what you want. That said, It's likely that the implementation isn't as good/efficient as J or K, but the source code is available.