2 ms·
To try and put it another way to the other answers, Python functions take inputs in parentheses, do a calculation, and return results to the left of the name. A
by jodrellblank 6y ago
To try and put it another way to the other answers, Python functions take inputs in parentheses, do a calculation, and return results to the left of the name. A definite arrow-of-time, inputs first, then calculation, then results. e.g. in this line of code you pass in a width and height, and out comes an area, no other way round:
area = rectangle_area(width, height)
Prolog doesn't have that arrow-of-time, instead (subtle difference) you declare that Area, Width and Height are related by equality and multiplication in some abstract sense:
rectangle_length_width_area(Length, Width, Area)
It's a pattern, not a computation; as well as the obvious giving Legnth, Width and calculating Area, you can fill in Area and Width and get Length. You can fill just Length and get Widths and Areas (plurals) that could go with a fixed Length. You give whichever values you have and Prolog will search for the missing ones trying to match the pattern of how they relate to each other. If you give values for all of them, it will check them out and see if they do relate to each other in this rectangular way and tell you yes or no. If there might be more than one value that can fill in the gap(s) you left, it can generate many answers.
This is one of the ways Prolog can do impressive things - the code you write can express more and do so at a more abstract level than the same amount of code in Python. Downside is is can bloat past what any computer could run in a reasonable time. Function modes remove some of the Prolog magic and add constraints e.g. Length and Width are inputs, Area is an output. Slap on an arrow-of-time, lose the general purpose search and solve, bring Prolog down from magic to mortal realms, gain something that runs on a normal computer.