On Thu, Jul 21, 2011 at 10:27 PM, Meikel Brandmeyer <m...@kotka.de> wrote:

> Hi,
>
> Am Donnerstag, 21. Juli 2011 16:06:23 UTC+2 schrieb Ambrose
> Bonnaire-Sergeant:
>
> >> You do not need to look at the surrounding code to know what (geto x y
> z) does.
> >> It establishes the geto relation between x y z. x must be some key in, y
> must be a
> >> vector of key-value pairs and z must be a value in y. The relation
> guarantees this.
> >
> > I think I understand where Meikel is coming from.
> >
> > The function can be used in radically different ways, depending on the
> values of the arguments,
> > which is somewhat unnerving. (I sympathize)
>
> Thanks for explaining my point than I did. Here some examples:
>
> logic-introduction.core=> (run* [q] (geto 'f [['f :- Integer] ['g :-
> Integer]] Integer) (== q true))
> (true)
> logic-introduction.core=> (run* [q] (exist [a] (geto 'f [['f :- Integer]
> ['g :- Integer]] a) (== q a)))
> (java.lang.Integer)
> logic-introduction.core=> (run* [q] (exist [a] (geto a [['f :- Integer] ['g
> :- Integer]] Integer) (== q a)))
> (f g)
>
> Basically the purpose *why* I call geto are always different (Maybe "call"
> is already wrong?). With (get x y z) in pure Clojure that's not the case.
> Free (fresh?) variables kind of feel like side-effects for my eyes. But
> again: I have no clue whatsoever about logic programming. Maybe I just have
> to train to look with the right glasses at the code.
>
>
I think this comes down to the declarative style of logic programming.

Think of the call to `geto` like a query.

You give the query parameters, and if the query succeeds, `geto` succeeds.
In `geto`s case, the query is  "does the type association [key :- value]
occur in the environment?"

For example:

logic-introduction.core=> (run* [q] (geto 'f [['f :- Integer] ['g :-
Integer]] Integer) (== q true))
(true)

This seems like a simple boolean expression, "does ['f :- Integer] occur
in [['f :- Integer] ['g :- Integer]]"?

But then you have the added flexibility of adding "fresh" variables.

Suddenly it becomes apparent that the "query" is really declarative.

`geto` says "the type association [key :- value] IS in the environment(!)",
and assigns any fresh
variables to make it so.

If this assertion fails, then we can consider our program to fail.

For example:

logic-introduction.core=> (run* [q] (exist [a] (geto 'f [['f :- Integer] ['g
:- Integer]] a) (== q a)))
(java.lang.Integer)

Here, `geto` says "['f :- a] _IS_ in [['f :- Integer] ['g :- Integer]]", and
assigns a to Integer to make it so.

The "side effect" that looks evil (reminds me of passing pointers in C),
really is just `geto` being flexible enough
to consider its arguments as either inputs or outputs.

Hmm, let me know if that made sense.

Ambrose

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to