3 ms·
I like the idea of having something like PROLOG/minikanren builtin to the language. Prolog is neat, but I wouldn't use it for text processing and database acce
by 6thaccount2 7y ago
I like the idea of having something like PROLOG/minikanren builtin to the language.
Prolog is neat, but I wouldn't use it for text processing and database access, so the logic programming piece to me makes better sense as embedded functionality in a more general purpose language, which is what I'm guessing you did here?
- clauderoux 7y agoAbsolutely, 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"
- thelazydogsback 7y agoCongrats @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?
- clauderoux 7y agoExactly. 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.
- dkersten 7y agoI have the exact same opinion and like minikanren libraries in Scheme and Clojure for that reason. I always liked Prolog, it always felt like an awesome way to write certain aspects of a program, but always felt super awkward for the rest of the program. With this approach, you can write the bits that make sense in the style that most suits. That's a pretty nice thing to be able to do!
- 6thaccount2 7y agoExactly!
- clauderoux 7y agoActually, there is a simple program: hanoi.tmg in https://github.com/naver/tamgu/tree/master/examples/Predicates https://github.com/naver/tamgu/tree/master/examples/Predicat..., which shows how to mix Prolog and imperative programming for a benefit of both.