martes, 14 de febrero de 2017

My first post on Prolog

As always...I was looking for my next programming language to learn...and somehow...Prolog got in the way...

I had played with Logic Programming in the past by learning Mercury...but really...when it comes to logic...Prolog wins the pot...

Did you guys knew that the first Erlang compiler was built on Prolog? Me neither -:P

For learning...I'm using SWI-Prolog which seems to be the nicer and widely used...and I have to admit...it's pretty cool -;)


So...in a glance...Prolog reminds me of Mercury of course...but also Forth a little bit...and weirdly to   Haskell in the sense that recursion is a key component...

As happens many times when I'm learning a new programming language...I started off with my Fibonacci numbers application...so here it is...

fibonacci.pl
fibo(NUM,A,B,[H|T]) :- (NUM > 1 -> H is A + B, X is NUM - 1, 
                        (A =:= 0 -> fibo(X,H,B,T); fibo(X,H,A,T))).
fibo(_,_,_,[]).

fibonacci(NUM,R) :- fibo(NUM,0,1,X), !, append([0,1], X, R).

.pl extension? Yep...the same as Perl...but as you can see...it has anything to do with Perl at all -;)

Anyway...here's the output screen...


My LED Numbers applications is gladly ready and will come after this blog -;)

Greetings,

Blag.
Development Culture.

No hay comentarios: