News for hackers. Stuff that matters.

Ask HN: How would a goal-oriented programming language look like?

Reading this article and discussion: There Are Three Programming Paradigms (2013) https://news.ycombinator.com/item?id=13612587

Imagine you could design a general purpose goal-oriented programming language. I was wondering how would such a language look like.

Actually, I've been having much spare time lately, so I'd like to actively research this topic.

( 25 comments | 20 points | on HN )
Re:Ask HN: How would a goal-oriented programming language lo... by irq-1 on Monday April 30, 2018 @02:15PM (#16960890)
Look at Racket. It hosts multiple languages including prolog/solver variants. Racket is made to create variant languages so you could start with a working system and change it to try designs. Here's just a few relevant Racket links:

https://docs.racket-lang.org/racklog/index.html

https://docs.racket-lang.org/parenlog/index.html

https://docs.racket-lang.org/datalog/index.html

Re:Ask HN: How would a goal-oriented programming language lo... by snrji on Monday April 30, 2018 @05:21PM (#16962479)
Excellent, thanks!
Re:Ask HN: How would a goal-oriented programming language lo... by bjourne on Monday April 30, 2018 @12:58PM (#16960234)
Prolog and MiniZinc (google them) are two useful goal-oriented programming languages. They are amazing at solving goal-problems, but are IMHO lacking in the general purpose department. What I mean is that they are great at solving n-queens problems and finding optimal seating arrangements, but not great for writing web servers or GUI:s in.
Re:Ask HN: How would a goal-oriented programming language lo... by brudgers on Monday April 30, 2018 @09:08AM (#16958237)
Prolog, SQL, or other logic programming languages...as mentioned in the linked C2 entry.
Re:Ask HN: How would a goal-oriented programming language lo... by snrji on Monday April 30, 2018 @10:27AM (#16958777)
Right, but these languages are declarative.
Re:Ask HN: How would a goal-oriented programming language lo... by brudgers on Monday April 30, 2018 @11:53AM (#16959633)
Sorry. I guess I don't see how a goal oriented language would work without declaring the goal and declaring the conditions under which it must be achieved.
Re:Ask HN: How would a goal-oriented programming language lo... by coldtea on Tuesday May 01, 2018 @05:38AM (#16965641)
Did you read the article the poster is reffering to, though?

It specifically mentions that the kind of "missing paradigm" looked for is not one of the declarative ones we currently have (SQL, Prolog, etc) because those fall into the Evaluate + Consequent combo.

So, he gives 3 paradigms:

FunctionalProgramming -> Evaluate + Mechanism (list of instructions)

ImperativeProgramming -> Execute + Mechanism

LogicProgramming/ConstraintProgramming -> Evaluate + Consequent (i.e. towards a consequent (result) based on constraints) [this is where declarative falls).

So, the "goals oriented" language he defines as the missing: Execute + Consequent pair.

Re:Ask HN: How would a goal-oriented programming language lo... by brudgers on Tuesday May 01, 2018 @09:17AM (#16966767)
Yes. And the Hacker News guidelines.
Re:Ask HN: How would a goal-oriented programming language lo... by coldtea on Tuesday May 01, 2018 @09:58AM (#16967046)
I would expect something more substantial for my "several paragraphs with summary and references" response than "the HN guidelines say to not question whether another has read TFA" then...
Re:Ask HN: How would a goal-oriented programming language lo... by brudgers on Tuesday May 01, 2018 @10:11AM (#16967135)
Not going to feed you.
Re:Ask HN: How would a goal-oriented programming language lo... by phaedrus on Monday April 30, 2018 @04:09PM (#16961798)
An imperative goal oriented language can be implemented as a staged language using lambdas. The first stage answers the question, "What are the subgoals?" The second stage applies a subgoal to a candidate solution.

Logic-programming style control flow can be implemented on top of these two primitives.

Re:Ask HN: How would a goal-oriented programming language lo... by snrji on Monday April 30, 2018 @05:26PM (#16962543)
Yes, I agree. But in the article I shared, they say that this goal-oriented language would be somehow "imperative" in the sense that you would be telling to the computer concrete things to do, just from a (much) higher abstraction level.
Re:Ask HN: How would a goal-oriented programming language lo... by brudgers on Tuesday May 01, 2018 @01:58PM (#16969524)
The C2 page is a wiki (the orginal). The page contains several viewpoints by different authors. Among them is the view that the division into a 2x2 table is incomplete/incorrect/of-limited-utility. For me, the relationship of declarative languages to the ordinary usage of "goal" is much stronger (for me at least) than the vague terms used to create the 2x2 table. To put it another way, I find the premise dubious. For me, it is useful to keep in mind the truth table of conditional statements in modal logic:

   a -> b
           b = T     b = F
         +--------+--------+
   a = T |   T    |    F   |
         +--------+--------+
   a = F |   T    |    T   |
         +--------+--------+
For me, the statement about there being some fourth category is trivially true because the division into two categories is false.
Re:Ask HN: How would a goal-oriented programming language lo... by childintime on Monday April 30, 2018 @05:03PM (#16962318)
I find Picat an exciting new development, with all three paradigms represented properly. See https://news.ycombinator.com/item?id=16563349
Re:Ask HN: How would a goal-oriented programming language lo... by snrji on Monday April 30, 2018 @05:21PM (#16962476)
Very interesting. Gonna read it. Thanks.
Re:Ask HN: How would a goal-oriented programming language lo... by wsy on Monday April 30, 2018 @12:10PM (#16959792)
If you want to work on a new programming language, think hard about an application area where all current languages can't be used to express a developer's intention easily and clearly.

Designing a language in the abstract usually doesn't work, it is better to start with use cases that demonstrate how the new approach helps expressing nicely what was cumbersome in previous languages.

Re:Ask HN: How would a goal-oriented programming language lo... by snrji on Monday April 30, 2018 @05:22PM (#16962499)
So, start small with a niche? Thanks.
Re:Ask HN: How would a goal-oriented programming language lo... by phaedrus on Monday April 30, 2018 @03:07PM (#16961300)
Another good source is anything to miniKanren / uKanren, especially papers and talks by William Byrd. There's a book called the Reasoned Schemer by Daniel Friedman and William Byrd describing their take on a goal oriented language.
Re:Ask HN: How would a goal-oriented programming language lo... by snrji on Monday April 30, 2018 @05:23PM (#16962510)
Great, thanks!
Re:Ask HN: How would a goal-oriented programming language lo... by coldtea on Tuesday May 01, 2018 @05:34AM (#16965626)
Neural networks and things like that look like "goal oriented" programming...
Re:Ask HN: How would a goal-oriented programming language lo... by phaedrus on Monday April 30, 2018 @03:01PM (#16961268)
I've been working on this (albeit as a library rather than a language in its own right).

The more papers I read the more lost I became trying to make sense of the different approaches to goal-oriented / relational / logic programming. This retrospective paper by Robert Kowalski gave me an historical framework to make sense of it all: https://www.doc.ic.ac.uk/~rak/papers/History.pdf

One of the key insights I gleaned from that paper is the difference between bottom-up and top-down strategies. All logic / relational / goal oriented paradigms exhibit a characteristic top-down or bottom-up quality, and this classification can then be used to understand the essence of goal-oriented programming.

The following is my interpretation of the historical information from that paper:

During the 1980s a burgeoning Datalog community, with roots in the database field, assimilated the existing deductive database community which had roots in AI. The database perspective focuses on finite models that are computable bottom-up. However a naive bottom-up implementation, deducing forwards from facts using rules, ignores the query until it derives it "as though by accident." To make generated models relevant to the query, Datalog uses transformations such as "Magic Sets" to incorporate the query into the rules.

An early deductive database (AI) strategy was Hyper-resolution, which is essentially also bottom-up, and it suffers from the same problem of generating new derivations blindly until one matches the query "by accident". Another strategy known as "set of support" restricted the inputs (axioms) so as to keep the derivations relevant to the query. However, according to Kowalski, set of support only approximates top-down reasoning, and a better approximation is linear resolution.

"Linear resolution addresses the problem of relevance by focusing on a top clause C0, which could represent an initial goal."

A problem which stood in the way of implementing this top-down strategy was the fact that given "n" clauses there are "n!" ways to compute the conjunction.

"The obvious solution was simply to resolve upon the literals in the clauses Ci in a single order. This order can be determined statically, by ordering the literals in the input clauses, and imposing the same order on the resolvents. Or it could be determined dynamically, as in selected linear (SL) resolution."

Thus, you see, it was the invention of SL, soon extended to SLD resolution (the D stands for "definite clause") which enabled top-down logic programming such as Prolog to be computationally tractable.

This top-down versus bottom-up distinction is what separates something like, e.g. language integrated query (LINQ) from logic programming: despite the similarity as a declarative form, a LINQ statement is computed bottom-up because datasets are generated and transformed in a forwards (i.e. not contingent) manner. In contrast a Prolog-style logic query (such as the Castor C++ library) is computed top-down: the query consists of an AND-OR tree of goals and subgoals which is visited top-down.

Re:Ask HN: How would a goal-oriented programming language lo... by snrji on Monday April 30, 2018 @05:24PM (#16962525)
Wow, very interesting.

I'm familiar with Prolog and its implementation, but definitely didn't know all of that.

Re:Ask HN: How would a goal-oriented programming language lo... by svisser on Monday April 30, 2018 @02:13PM (#16960881)
You should look into BDI agents and BDI programming languages.
Re:Ask HN: How would a goal-oriented programming language lo... by snrji on Monday April 30, 2018 @05:22PM (#16962505)
I will. Thanks!
Re:Ask HN: How would a goal-oriented programming language lo... by meric on Monday April 30, 2018 @08:38PM (#16963773)
SHRDLU? It was goal oriented.