News for hackers. Stuff that matters.
Re:Tamgu, a functional, imperative, logical programming lang... by clauderoux on Wednesday July 24, 2019 @04:37AM (#20513285)
Absolutely, you're right. In fact, I first slightly modified the Prolog syntax by replacing the traditional variables that start with a capital letter with variables of the form:"?X". We can therefore differentiate between Tamgu variables and Prolog variables. In addition, Tamgu's basic objects, such as vectors, strings or numbers are automatically reinterpreted as vectors, strings or Prolog numbers.

We can therefore apply operations like: [?X|?Z].

Finally, Tamgu considers that the reception variables before the "=" sign define the execution context. Therefore, if we take the following program:

parent ("John", "Peter").

parent ("John", "Mary").

parent ("Peter", "Roland").

parent ("Roland", "Pierre").

bool b = parent("John",?X);

vector v = parent(?X,?Y);

The first case will return "true" if we find a matching occurrence. Here "b==true".

The second case will return all the possibilities that match:

[parent("John", "Peter"),parent("John", "Mary"),parent("Peter", "Roland"),parent("Roland", "Pierre")

Access to each parameter is possible:

v[0] = parent ("John", "Peter")

v[0][1] == "Peter"

v[0].name() == "parent"

Re:Tamgu, a functional, imperative, logical programming lang... by thelazydogsback on Wednesday July 24, 2019 @04:11PM (#20519148)
Congrats @clauderoux! -- I've been working on similar fusions on and off during the years.

So "?X" is not true logical variable, but more of a part of a pattern expression? -- in other words, a logical var is a first-class object that can be stored in a data-structure (possibly in an unbound state) and be bound at a later time, and perhaps unbound and re-bound again if there is backtracking. So in Tamgu, "parent(?X,?Y)" acts as a one-shot "find" if the LHS is atomic, and acts as a generator (similar to a possibly nested list comprehension) if the LHS is a collection (but no inter-statement backtracking points are established), correct? So is the generation of the sequence eager/realized or lazy/by-need?

Re:Tamgu, a functional, imperative, logical programming lang... by clauderoux on Thursday July 25, 2019 @05:48AM (#20523989)
Exactly. If you provide a collection, the system will deduce that you want all solutions to be extracted, while if you provide a non collection variable then it will stop once one solution has been found. Actually, I have a very specific type, which is "predicatevar", if you want to get your unification once.

?X is actually a true Prolog variable that can be unified over and over again. Furtheremore, you can call Tamgu functions from your predicate description, in which these variables can be used if they are unified.

grandparent(?X,?Y) :- parent(?X,?Z), println(?Z), parent(?Z,?Y).

In the case above, the "println", which is not a predicate, will try to display the content of ?Z, if ?Z has been unified.

println could be replaced with a call to an actual function, as long as this function returns true. If the function returns false, then it will be considered as a fail.