Archives for the 'Prolog' Category

From foldl to difference lists

Sunday, November 9th, 2008

Most declarative languages have lists. Usually this lists are either a nil atom (empty list) or a cons (a couple whose second element is a list). It is easy to see how we can append things to the head of the list.
In my former article we explored lists and foldl. Indeed, it is clear that [...]

Declarative Programming, Programming, Prolog | No Comments

Accumulators and Foldl in declarative languages

Saturday, November 8th, 2008

Using accumulators in declarative programming is common. Basically it is possible to convert not tail recursive functions into tail recursive ones using an accumulator.
Consider a very simple procedure: sum numbers in a list. The naive implementation is:
naive_sum([]) ->
0;
naive_sum([H|T]) ->
H + naive_sum(T).
This one is not tail recursive. Every [...]

Declarative Programming, Erlang, Functional Programming, Haskell, Programming, Prolog | Comments Off

ICLP 08

Monday, October 13th, 2008

Tomorrow I registered to the ICLP 08 conference.
I’m looking forward to go!

Prolog | No Comments

A Prolog XML printer in less than 100 lines.

Tuesday, December 19th, 2006

Suppose we have an XML parser that converts an XML file into a Prolog term.
We may (quite) easily build one with DCG. I will be doing one soon, for values of ’soon’ that depend on the status of my thesis.
We describe the way the prolog term is built:
Text is simply a prolog term. In a [...]

Prolog | No Comments

Difference Lists for visiting trees (Prolog)

Wednesday, November 15th, 2006

This is are some (simple) exercises in Prolog using difference lists.
They should be correct, but I have to say I’m a beginning Prolog programmer… so…

inorder_dl(tree(X, L, R), Xs-Ys) :-
inorder_dl(L, Xs-[X|Zs]),
inorder_dl(R, Zs-Ys).
inorder_dl(void, Xs-Xs).

preorder_dl(tree(X, L, R), [X|Xs]-Ys) :-
preorder_dl(L, Xs-Zs),
preorder_dl(R, Zs-Ys).
preorder_dl(void, Xs-Xs).

postorder_dl(tree(X, L, R), Xs-Zs) :-
postorder_dl(R, Ys-[X|Zs]),
postorder_dl(L, Xs-Ys).
postorder_dl(void, Xs-Xs).

Prolog | No Comments

Difference lists

Sunday, November 12th, 2006

Well…. I just discovered this new wonderful world. I really like them a lot.
I suspect I’m getting a little bit more into Prolog programming. However, I still find more exciting Haskell lazy programming. But I have to admit that my scarce love for Prolog it’s more a problem of (my) ignorance.
A couple of days ago [...]

Prolog, Senza Categoria | 2 Comments

Something about Prolog…

Friday, April 21st, 2006

As I had to admit in my last Prolog post, I’m no Prolog guru. I’d rather deserve the term newbie. However, I followed some math logic courses that make it all less harder. If you find something incorrect or if you don’t understand something, comment it.

The first [...]

Programming, Prolog | No Comments

get_sublist in prolog

Thursday, February 23rd, 2006

The hardest thing when programming prolog, is to change your mind. In fact declarative programming (while powerful) is hard to get in touch. I always tend to think imperatively, even if I attended formal logic lessons in the University.
Now just a couple of easy things… I’m a beginner.
get_sublist(Start, Len, List, Sub) :- append(L1, L2, List),
length(L1, [...]

Programming, Prolog | No Comments

Recent Posts

Blogroll

Siti amici

Misc

Recent Comments

Categories

Enrico Franchi graduated in Maths and Computer Science and is now studying for a Computet Science MSc (though because of italian bureaucracy that very course is to be cancelled).

RiK0's Tech Temple is using WP-Gravatar