11 ms·
I'm not mutable, I'm partially instantiated
- lelag 2y agoI've noticed quite a lot of Prolog content lately. I don't know if it's just a case of the Baader–Meinhof phenomenon, but it looks to me that recent article[1] about Prolog being able to improve LLM reasoning abilities renewed some interest in the language. [1] https://shchegrikovich.substack.com/p/use-prolog-to-improve-llms-reasoning https://shchegrikovich.substack.com/p/use-prolog-to-improve-...
- worldsayshi 2y agoHere's the hacker news post: https://news.ycombinator.com/item?id=41831735 https://news.ycombinator.com/item?id=41831735
- dang 2y agoThanks! Macroexpanded: Use Prolog to improve LLM's reasoning - https://news.ycombinator.com/item?id=41831735 https://news.ycombinator.com/item?id=41831735 - Oct 2024 (155 comments)
- deleted 2y ago[deleted]
- weinzierl 2y agoWhich is strange considering how old and limited Prolog in a sense is. I wonder why no superset ever gained traction and what it would look like. I imagine it fitting somewhere in the hierarchy Theorem Prover ⊃ SMT Solver ⊃ SAT Solver since Theorem Prover ⊃ Prolog
- sixfiveotwo 2y agoIndeed, you can get a lot more from dependent types than Damas-Hindley-Milner inference, yet does it mean that you should use the former everywhere?
- Byamarro 2y agoLearning curve perhaps? There doesn't have to be an overlap between people working on this and the tools you have mentioned
- knome 2y agolimited in what sense? prolog is turing complete.
- Epa095 2y agoHe might be thinking about the SLDNF resolution happening. But yes, you can implement any prover in prolog. This distinction is discussed a bit here: https://www.metalevel.at/prolog/theoremproving https://www.metalevel.at/prolog/theoremproving
- Epa095 2y agoThe post in OP has the following hyphothesis: > Why Prolog? [...] Due to it's declarative nature it might be a bit easier for LLMs to generate code, because LLM doesn't need to generate precise control flow. This is an interesting point, and my guess is that prolog is the declarative programming language with most example code out there for it to learn on(excluding SQL). Alternatively it could try to create some problem description for an automated theorem prover. My (absolute ignorant) guess is that the prolog aproach works better for two reasons: - The amount of prolog code in the training set is higher - It is still only able to create code for problems easy enough that prolog can handle them.
- dsabanin 2y agoAnother attractive feature of Prolog is that it’s homoiconic, like lisp.
- p4bl0 2y agoI don't get where the `-` comes from in `key-value` result lines after the "refactoring" title. I feel like it should stay a `,` like at the beginning. Can someone more knowledgeable in Prolog explain that? Is that because of an hidden use of this `to_list` predicate that comes later in the post?
- JadeNB 2y ago(The initial version of this comment missed the point of your question; sorry.) The author says: > We also store pairs as the pair type (Key-Value), instead of two separate values. This makes easy to serialize a dictionary into a list of pairs, which are sortable using the builtin keysort/2. `Key, Value` is two values, not one. I suspect something like `kv(Key, Value)` would work as well. By the way, I disagree that the refactored version doesn't cut; `-> ;` is syntactic sugar over a cut.
- microtonal 2y agoOperators like - are just an infix functor for a Prolog term with arity 2: ?- functor(123-"foo", Name, Arity, Type). Name = (-), Arity = 2, Type = compound. ?- 1-"foo" = '-'(1,"foo"). true. Functors like - only become arithmetic in combination with is: ?- A is '-'(42, 1). A = 41. ?- A is 42 - 1. A = 41.
- tannhaeuser 2y agoIt's purely a convention to use terms of the form "key - value" for 2-tuples here (or '-'(key, value) in funtional/canonical notation which can be used as well). minus is just used because it's already predeclared as an infix operator, and indeed ','(key, value) could be used as well but comma is also used as argument separator and for conjunctions in clause bodies and thus tends to be avoided. You also can see '=' being used for the same thing eg. [ key = value, ...] (for example, as used for representing attributes by SGML/XML parsing libs for SWI, Quintus/SICStus, and others), not to be confused with '=' being interpreted as unification operation in goals/clause bodies. If you think about it, the simplest convention in Prolog to represent "assignment" of a value to a symbol (not a variable) would be key(value). That is, to use the "key" atom as functor itself, rather than use functors/operators in ad-hoc ways. This is exactly what Quantum Prolog can do (optionally, and in addition to ISO Prolog's conventions). Specifically, if you have a list of fact-like terms L = [ p(1), q(2), r(what(ever)) ] then Quantum Prolog can answer queries against such term list, just like answering against the global default database eg. call(L ?- q(X)) binds X = 2 and would also bind additional values for q(X) on backtracking if the term list contained any. This is a natural extension to regular querying in Prolog because a term list [a, b] in Prolog's square bracket notation is just syntactic sugar for using the dot operator '.'(a, '.'(b, [])) and a Prolog program is syntactically just a list of clause terms. In the container planning demo on the Quantum Prolog site [1], this feature is used for backtracking over (un)loading and travelling actions which would normally change state via destructive assert and retract calls and hence not allow backtracking to search for optimal sequences of actions. [1]: https://quantumprolog.sgml.net/container-planning-demo/part2.html https://quantumprolog.sgml.net/container-planning-demo/part2...
- jfmc 2y agoA classic library, you can play with it here: https://ciao-lang.org/playground/#https://github.com/ciao-lang/ciao/blob/master/core/lib/dict.pl https://ciao-lang.org/playground/#https://github.com/ciao-la...
- anfelor 2y agoPartially instantiated data structures are also available in Haskell (via Laziness), in OCaml (via tail modulo cons, https://inria.hal.science/hal-03146495/document https://inria.hal.science/hal-03146495/document) and Koka (via constructor contexts, https://dl.acm.org/doi/pdf/10.1145/3656398 https://dl.acm.org/doi/pdf/10.1145/3656398)
- bmacho 2y agoI don't think Haskell can do this, can have a growable linked list for example. 'last a' is 'last a', regardless what is between them (modulo shadowing and such). And I suspect that Prolog's Partial Instantiation is, while not mutating data, but it is mutating references somewhere
- skybrian 2y agoHaskell has cyclic data structures, which also can’t be implemented without a mutable reference somewhere, though it may be buried in the implementation. The difference is being able to define an incomplete data structure (with a forward reference) and then defining the target of the reference at runtime. Most languages will complain about an undefined reference if it’s not defined by the end of a module. You could do it with soft references, though. Use a symbol or string to refer to something and define it later.
- deleted 2y ago[deleted]
- bmacho 2y agoI rather think the fact the the same symbol/string always denotes the same thing is especially helpful for cyclic structures. Anyway I think I misunderstood the article, I thought they added things to a dictionary in the prolog repl, which would be impossible in haskell/ghci afaik.
- whateveracct 2y agoTechnically, Haskell laziness is just mutability under the hood :) And the "difference list" mentioned in the article is also in Haskell - although framed differently (more "functionally") type DList a = [a] -> [a] concat :: DList a -> DList a -> DList a concat = (.) toList :: DList a -> [a] toList d = d [] fromList :: [a] -> DList a fromList = (++)
- openasocket 2y agoI've never used it in production, but I have a deep love of Prolog, just because of how different it is from any other programming language I've used. As a programming paradigm, it found it as eye-opening as functional programming. What I found interesting is that you are operating on logical statements and pattern matching, which often means that the same "function" can be used for multiple different things. For example: append([], List, List). append([Head|Tail], List, [Head|Rest]) :- append(Tail, List, Rest). Is a simple list append function: append(X, Y, Z) is a predicate that match if Z is the list of all elements of X, followed by all elements of Y. You can use it to concatenate lists, of course. But you can also use it to confirm that a particular list start with a particular sequence, or ends with a particular sequence! The idea that the same predicate can be used in multiple different ways is really fascinating to me. I have no idea to what extent that would scale in a large system, but it's very interesting
- agumonkey 2y agoSame, I love the bidirectional aspect of relations
- wizzwizz4 2y agoIt doesn't scale that well because integers are their own, opaque thing in Prolog, and the is predicate is unidirectional. However, there's no inherent reason this has to be the case: you can construct your own representation of the integers from the Peano axioms, and recover bidirectionality of addition. (You'll want to be using some typed variant of Prolog with the "unary tree of units" optimisation, otherwise integers take O(n) space in memory, but it's possible in the language.) Prolog works how it does, because it's (mostly) backwards-compatible with a facts database used for symbolic AI research, where all atoms were opaque.
- lmkg 2y agoCheck out the CLP(ℤ) library by Markus Triska, who is also the author of Scryer Prolog. It defines new comparison predicates that lets you use bidirectional logical programming on standard integers with standard math operations. https://github.com/triska/clpz https://github.com/triska/clpz
- samweb3 2y agoI am actually working on a logical query language that's a successor to prolog here: https://memelang.net/02/ https://memelang.net/02/. Any feedback appreciated!
- wizzwizz4 2y agoIt might be worth using standard vocabulary. For example: > Reciprocal relations are their own inverse. The usual word for this is "symmetric". > Recursive relations can be chained to themselves infinitely. For example, "my ancestor's ancestor is also my ancestor." The usual word for this is "transitive". A reflexive, symmetric, transitive relation is called an "equivalence relation", and it can be used much like equality. It'd be nice if your language had support for this, though I don't immediately see how to add it.
- simplify 2y agoAlternative would be interesting, but successor is thought provoking. Do you mean to say most all Prolog capabilities will be possible to do in Meme?
- samweb3 2y agoThat's the goal, but please let me know if there's anything you find that you can't do.
- shawa_a_a 2y agoIt's a bold statement to call something a Prolog successor! Are you aiming for a general purpose logic programming language like Prolog, or targeting the use case of querying knowledge bases? One of the draws to Prolog is its immensely simple syntax: A.R:B = true in your case would be represented as simply r(A, B). It looks like you've elevated some set theory properties to syntax, and have added some neat sugar over chained relations. Have you found areas where this really shines as compared to writing more standard Prolog/Datalog queries? I'm afraid I couldn't see many examples on first look at your Github.
- tolerance 2y agoThis is philosophically intriguing.
- bedobi 2y agoPartial instantiation is cool and all, but tbh I prefer just capturing the initial incomplete attributes in one complete record, pass that around, and then instantiate the real thing when you have all attributes data class IncompletePerson(val name: String) data class Person( val name: String, val email: String ) or data class Person( val initialAttributes: IncompletePerson, val email: String ) if you want to nest it. if you're the type to instead do this data class Person( val name: String, val email: String? ) I never want to work with your code. Now, there's no disambiguation between the complete object and the incomplete one, I always have to check before doing anything with it, and people will inevitably try send an incomplete object someplace that can't handle it and generate bugs.
- skybrian 2y agoHow would you define a cyclic data structure?
- skybrian 2y agoIt seems like whether this represents a mutable or immutable data structure depends on the operations you allow. If polling with nonvar() is allowed, couldn’t you see variables mutate as you do more unification? But if it’s not allowed, I guess you get a variable to be defined later? Compare with a Promise. If you can check whether it resolved, you can see it mutate. If the only operation allowed is to await it then from the code’s point of view, it might be considered an immutable reference to the pending result.
- colanderman 2y agoYes, `nonvar/1` is considered "extralogical", in that it can be used to observe these side effects. If one sticks to "pure" logical operations (which unintuitively excludes `\+` negation) they are not observable.
- ks2048 2y agoIs "The Art of Prolog" a good place to start with the lanugage?
- rscho 2y agoThe book is ok for core Prolog, but quite old and many new features have been made available since then. Including stuff making parts of the core language obsolete. Honestly, the language is super small. Best way to learn IMO is to go on https://swish.swi-prolog.org/ https://swish.swi-prolog.org/ and do the examples / play with it. If you stick to it, then you can branch to other engines later (there are many systems with unique features).
- benreesman 2y agoIt’s a beautiful construction. It reminds me a bit of the “canonical” quicksort in Haskell [1]. Neither of these implementations is going to be displacing absl::btree_map or std::sort any time soon, but I do feel we have a lot of “room at the bottom” for making simple and elegant code practical on real machines. [1] https://stackoverflow.com/questions/7717691/why-is-the-minimalist-example-haskell-quicksort-not-a-true-quicksort https://stackoverflow.com/questions/7717691/why-is-the-minim... Edit: replaced poorly formatted code with SO link.
- dr-detroit 2y ago[dead]
- skrebbel 2y agoOnly slightly related, I wish there were a way to express this in run-off-the-mill, imperative/eager languages. Eg some way to explicitly mark a class, or something like it, as immutable-but-partially-instantiated. TypeScript supports this a tiny bit by means of its `readonly` keyword which lets you assign a value in the constructor, or in any method called from the constructor. But no later than that! If there was a way to make a field "readonly once_assignable" or something like that, you could do something like in this article (esp if you nest instances of a class that uses this) with an eager language, albeit with a lot more boilerplate (and getters, I assume).
- stonemetal12 2y agoBoth Java and C# do. In Java marking a variable final makes it immutable after assigned. In C# a variable marked readonly is the same.
- contextfree 2y agoMore precisely in C# a readonly field of a type can only be assigned to within that type's constructor.
- skrebbel 2y agoWhich means you can't have a partially instantiated object except while the constructor is running.