Recently I've been working on adding arrays and functions to my DALIS programming language. To test this stuff out I decided to write a very simple Artificial Neural Network. I've hard-coded the weights between a 5 neuron feed-forward 3 layer network. It's a classic XOR example with 2 inputs and one output. The output should be 1 if the two inputs are different, otherwise the output will be zero. This is the output from the program:
Trivial Neural Network Example
Input 0,0 Output 1 is: 0
Input 1,0 Output 1 is: 1
Input 0,1 Output 1 is: 1
Input 1,1 Output 1 is: 0
...and this is the DALIS source code that I used:
:<b>Trivial Neural Network Example</b><br/>
sizeL1=2, sizeL2=2, sizeL3=1
L1[sizeL1]=0, L2[sizeL2]=0, L3[sizeL3]=0
W2=2, W2=-1, W2=-1, W2=2
WRITE "Input "+TEXT(a,0)+","+TEXT(b,0)
LOOP j=1, size = sizeL2
L2[j] = L2[j] + L1[i] * W2[w]
REPEAT i=i+1 IF i<=sizeL1
REPEAT j=j+1 IF j<=sizeL2
LOOP j=1, size=sizeL3
L3[j] = L3[j] + L2[i] * W3[w]
REPEAT i=i+1 IF i<=sizeL2
WRITE " Output "+TEXT(j,0)+" is: "+TEXT(L3[j],0)+EOL
REPEAT j=j+1 IF j<=sizeL3
VALUE = 0
VALUE = (f*s)+b-s
VALUE = retval
So I'm now starting to think about genetic programming in DALIS, there's no real reason why DALIS programs couldn't write other DALIS programs and run them by posting them to the server.
I mentioned to a friend of mine that I wanted to slap together a quick load balancer to demonstrate that DALIS programs can bounce between different servers without the need for any shared state.
Being able to do that was my original aim for writing a cloud based language,
and a demo showing DALIS in action would be nice to have. Of course, I had
intended to simply extend my
C# webserver example
and make a simple load-balancer out of that. But my friend happened to say “why
don’t you write the load balancer in DALIS?”. Damn him, putting ideas in my head
like that. Still I got my own back when I showed him the
Esoteric Programming Languages site and he spent way too much time reading it
So ... here is my (very simple) load balancer written in DALIS:
IF (RANDOM >= 0.5)
newUrl = REPLACE arg0, "DALIS", "DALIS1"
newUrl = REPLACE arg0, "DALIS", "DALIS2"
newUrl = REPLACE newUrl, "balance", arg1
IF RAWCONTENT = ""
WRITE WEBGET newUrl
WRITE WEBPOST newUrl, RAWCONTENT
I had to add a few new things to the language to make this work (it is great when you’re the boss of the programming language and you can add whatever you like):
- RANDOM – generate a pseudo random number between 0.0 and 1.0
- RAWCONTENT – allows your program to access the data in the raw http request
- TRANSPARENT – tells DALIS that you don’t want it to add anything to the output
- WEBPOST – does an http POST with the data you specify
- REPLACE – replace a value in some text with some new value
Anyway, this seems to work a treat, it means that you can run 3 separate DALIS servers (called DALIS, DALIS1 and DALIS2 in this example),
one being the load-balancer, along with two others. You can then run a DALIS program via the load-balancer and it will route it randomly to one of the other two DALIS servers. Using the TRANSPARENT keyword in the load-balancer code is critical, since it allows stuff to simply pass through without any interference.
The trouble is, I’m actually starting to enjoy programming in DALIS now. What have I done?
After working on some improvements to my DALIS programming language, I decided to celebrate by actually taking the time to understand the algorithm that draws the mandelbrot set better. After some reading on wikipedia, I was able to refactor it somewhat. So, this is my current implementation:
LOOP d=0, h=0, e=1.1
LOOP n=0, h=127, r=0
r = r*r-n*n+b
n = 2*d*n+e
REPEAT d=r, h=h-1 IF ((r*r)+(n*n) < 4) AND (h > 32)
REPEAT b=b+0.04 IF b < 1
REPEAT e=e-0.1 IF e > -1.2
I think it's much better. As you can see, it's now possible for several variables to be assigned on the same line and there is a RETURN keyword to write line breaks easily. Drawing the mandelbrot set in ten lines of code is pretty good, surely?
At the moment I'm working on a means of getting user input, which is going well, and in the background I'm thinking of ways to build simple webservices with DALIS... At this rate I'll have to start writing a book entitled "The DALIS programming language" :-)
I decided to give my new (experimental) programming language, codenamed DALIS a try on some other platforms. This one is obvious I guess - the good old iphone:
...but I was pleasantly surprised to see it working OK on my PSP as well:
The fonts on the PSP don't come out the same, but it seems to run OK, which is the main thing. I would be fun to try a Kindle, but I don't have one (yet). The advantage of a cloud-based language like this is that you only need a browser, so it should work on all kinds of things.