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)

Sebastian
  • 365
  • 3
  • 17

2 Answers2

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.

kaya3
  • 47,440
  • 4
  • 68
  • 97
  • Thanks @kaya3 ! Adding "library" to my search really helped, at least in the duckduckgo-search ... It seems to me now that also [SAT-solving](https://duckduckgo.com/?q=java+sat+solving&t=ffab&ia=web) (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. – Sebastian Aug 09 '21 at 17:26
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.

JustAnotherDeveloper
  • 2,061
  • 2
  • 10
  • 24
  • 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 ... – Sebastian Aug 09 '21 at 10:36
  • 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 Aug 09 '21 at 11:00
  • @kaya3 I have ammended my answer to "similar" instead of "equivalent". Thank you. – JustAnotherDeveloper Aug 09 '21 at 12:39