3

In recent years many elements of 'functional programming' have entered Java, in particular with Java 8. I have in mind lambda-expressions, functional interfaces, Java Generics, the Stream-interface, the Optional-class and similar.

My question is, are there likewise any new classes/interfaces/syntaxes that have been added to Java and stem from the paradigm of 'logic programming'? Or are there maybe plans to do so?

(see e.g. here for a comparison of the two approaches)

2 Answers 2

4

A logic programming language (such as Prolog) allows programs to be written as statements of truth and relations between them, so that an implementation of the language is essentially an algorithm which searches for solutions which satisfy all of a program's declarative statements.

So for Java to support logic programming "out of the box", the standard library would have to contain such a search algorithm. To my knowledge, it does not. However, there are third-party libraries which do; a Google search for 'Java logic programming library' yields several (constraint programming libraries likewise.)

These libraries will generally represent statements and relations as Java objects, and include an implementation of an algorithm (or possibly several algorithms to choose from) in order to search for solutions. Given the availability, complexity and variety of these libraries, it seems unlikely that something equivalent will be added to the Java standard library.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @kaya3 ! Adding "library" to my search really helped, at least in the duckduckgo-search ... It seems to me now that also SAT-solving (SAT for satisfyable) is a helpful keyword to search for useful libraries. For support in the Java standard library I was hoping that maybe at least when following the example of plain Prolog which supports only so-called Horn-clauses to my knowledge, one would end up with some pretty established basic algorithms. But I'm not yet into the topic, so I might be completely wrong.
1

Java supports predicates, functional interfaces that take an argument and return true or false depending on whether the argument makes the conditions of the predicate true or false. This is similar to the Prolog predicates mentioned in the question you linked.

3 Comments

Sure, thanks, I should have thought of these, as I'm using them quite frequently. As they are functional interfaces, my mind had put them in the 'functional'-drawer ...
The Predicate functional interface in Java is not really analogous to predicates in Prolog; see the Q&A linked in the OP for a discussion.
@kaya3 I have ammended my answer to "similar" instead of "equivalent". Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.