Making Prolog familiar
While I'm a huge fan of Prolog, I definitely understand that it's syntax and behavior is too far removed from that of C-based languages (e.g., C, C++, Java, C#, JavaScript, etc.). So without sacrificing the beautiful semantics of Prolog (unification, backtracking), could we restore some familiarity to the language, and thus expose it to new users?
Let's start with the basic logical operators:
- -> ; represents if-then-else
- ; represents or
- , represents and
- = represents unification of the term on the left with the term on the right
- is represents an assignment of the value on the right to the term on the left
- ( and ) are used both for grouping and to bound lists
Problem is, of course, engineers accustomed to C-based languages read these differently:
- -> represents the pointer derference, member access operator (combination of *.)
- ; represents the end of a statement, or a separator between statements executing sequentially
- , represents either a series of expressions executed in order, or arguments to a function
- = is an assignment statement from right to left
- ( and ) are just for grouping, and do not imply a data structure
With this in mind, we can adjust the basic operators to match more closely to C:
- Instead of using -> ; for if-then-else, use the C ternary operator ? :
- Instead of ; to represent "or" of expressions (thus alternative not sequential execution), let ; be the "and" operator--so a series of expressions connected by ";" will be executed sequentially, in the typical case
- Leave , to be both the or operator and a delimiter in argument lists
- Let = be the assignment operator
- Use is as the unification operator
- Use { and } to bound lists, with elements separated by ;