Live data from Hacker News

I'm not mutable, I'm partially instantiated

blog.dnmfarrell.com

51–60 of 77 posts

Re: I'm not mutable, I'm partially instantiated

#51
post #18

I am actually working on a logical query language that's a successor to prolog here: https://memelang.net/02/ . Any feedback appreciated!

It'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.

Re: I'm not mutable, I'm partially instantiated

#52
post #50

Earlier quoted context omitted.

I always thought that pattern matching would be an excellent feature for other programming languages, but it seems that it hasn't become popular. Many strategies available to Prolog could become possible just by the addition of this feature. One possible implementation of the idea occurs with C++ templates specialized with numerical parameters. It also seems that Mathematica provides pattern matching, but I don't use…

Erlang, Elixir, Swift, Rust, Python, probably some others. That list is roughly in order of how capable and useful the pattern matching is in each of those languages. Erlang was originally written in Prolog. Also, I definitely agree it's a feature I miss everywhere when not using Erlang/Elixir.

I mostly ignored Python until my job required it, about 8 years ago. Coming from Erlang, I was pleasantly astonished to find that I could use tuple pattern matching in function headers… until I discovered that was dropped in Python 3 and I had been using the mostly-dead version 2 runtime.

Re: I'm not mutable, I'm partially instantiated

#53
post #18

I am actually working on a logical query language that's a successor to prolog here: https://memelang.net/02/ . Any feedback appreciated!

Alternative would be interesting, but successor is thought provoking. Do you mean to say most all Prolog capabilities will be possible to do in Meme?

That's the goal, but please let me know if there's anything you find that you can't do.

Re: I'm not mutable, I'm partially instantiated

#54
post #50

Earlier quoted context omitted.

Erlang, Elixir, Swift, Rust, Python, probably some others. That list is roughly in order of how capable and useful the pattern matching is in each of those languages. Erlang was originally written in Prolog. Also, I definitely agree it's a feature I miss everywhere when not using Erlang/Elixir.

I mostly ignored Python until my job required it, about 8 years ago. Coming from Erlang, I was pleasantly astonished to find that I could use tuple pattern matching in function headers… until I discovered that was dropped in Python 3 and I had been using the mostly-dead version 2 runtime.

I think I'd call this destructuring, as opposed to patterns and matches, and Python still does it, just not in the function head.

I do wish they went the opposite direction and made the feature better instead of keeping it as a weird assignment thing in the body. The match statement is a similarly unfortunate solution, in my opinion.

Oh well. :)

Re: I'm not mutable, I'm partially instantiated

#55
post #26

Earlier quoted context omitted.

It 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 inte…

Check 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

Markus is not the author of Scryer Prolog, Mark Thom is.

Re: I'm not mutable, I'm partially instantiated

#56

It 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…

Yes, `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.

Re: I'm not mutable, I'm partially instantiated

#57
post #54

Earlier quoted context omitted.

I mostly ignored Python until my job required it, about 8 years ago. Coming from Erlang, I was pleasantly astonished to find that I could use tuple pattern matching in function headers… until I discovered that was dropped in Python 3 and I had been using the mostly-dead version 2 runtime.

I think I'd call this destructuring, as opposed to patterns and matches, and Python still does it, just not in the function head. I do wish they went the opposite direction and made the feature better instead of keeping it as a weird assignment thing in the body. The match statement is a similarly unfortunate solution, in my opinion. Oh well. :)

You're correct, destructuring is the appropriate term.

I checked the release notes, and the reason they removed it: no one was using it. I guess it's unsurprising, but sad.

Re: I'm not mutable, I'm partially instantiated

#58

Earlier quoted context omitted.

I always thought that pattern matching would be an excellent feature for other programming languages, but it seems that it hasn't become popular. Many strategies available to Prolog could become possible just by the addition of this feature. One possible implementation of the idea occurs with C++ templates specialized with numerical parameters. It also seems that Mathematica provides pattern matching, but I don't use…

Matching of patterns , with only a single occurrence allowed for each variable, is fairly popular in languages designed in the last two decades, isn’t it? A lot of those have or at least borrow from ML heritage, and that of course places a big emphasis on algebraic types and pattern matching. Full-blown unification remains niche, that’s true, but it’s just a fairly heavyweight feature, and I don’t really know how you…

Simon Peyton Jones (of Haskell) is working on Verse, a functional relational programming language, that merges the ideas of both functional and logical programming into one.

It’s being done to facilitate Fortnite metaverse, as he’s doing this work at Epic.

https://youtu.be/OJv8rFap0Nw?si=OmBT9CBJIxdJE1Jv

Re: I'm not mutable, I'm partially instantiated

#59
It’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-minim...

Edit: replaced poorly formatted code with SO link.

Re: I'm not mutable, I'm partially instantiated

#60
post #38

Earlier quoted context omitted.

Do you have a suggestion on where to / how to start learning Prolog beyond towers-of-hanoi? Prolog is basically the last language on my list of things I want to look at, but whenever I tried, I failed to find anything practical to do/try.

Try a rules-based synthesis problem. Prolog style (put simplisticly) is to write down what is true about a solution, and turn the search engine loose. Prolog is still procedural, unfortunately, so practical Prolog requires understanding the search algorithm. A suggestion: produce the XY locations of the nails for a building-code-compliant nailing pattern for a panel of plywood roof sheathing. Allow different stud spa…

I love this example so much. I used a similar kind of problem a year or so ago when playing with some kind of logic/linear programming/optimization system: given a set of shelves (width and length), find the set of guillotine cuts (cuts across the entire sheet) that minimizes how many sheets of plywood are needed. If I recall the general problem is actually in NP but by formulating it as a problem of finding a list of operations (new sheet, cut sheet X horizontally, cut sheet X vertically) the solver was able to come up with high quality solutions in seconds.

I then took it and added a second level: once it has found a minimal number of sheets, minimize the number of cuts. Super handy little tool! Once I had the solver part figured out and added a little tweak for handling kerf, it was quite simple to have it spit out an SVG that showed all of the pieces and cuts.

And now… I want to go find that code and play with it again. Super fun stuff outside of the daily grind.

Post reply on HN