this post was submitted on 03 Jan 2025
0 points (NaN% liked)

Programmer Humor

37126 readers
66 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 

something is a person if it is either Adam or Eve, or if it has a mother. We can express this in a single rule as follows:

person(X) :- (X=adam; X=eve; mother(X, Y)).

top 8 comments
sorted by: hot top controversial new old
[–] [email protected] 0 points 6 months ago (1 children)

Can someone explain where the Y comes from? Is this something like, there exists a mother relation between this X and some Y?

[–] [email protected] 1 points 6 months ago

mother can be used in several ways. If both X and Y variables are uninitialized, then it looks for all mother relationships. If one of them is initialized, it looks for matching relationships. If both are initialized, it returns true if such a relationship exists.

[–] [email protected] 0 points 6 months ago (1 children)

I learned Prolog in university and it was instructive. But has anyone ever professionally used it?

[–] [email protected] 1 points 6 months ago
[–] [email protected] 0 points 6 months ago (2 children)

I'll admit I don't speak prolog but doesn't this definition lack a recursive case to ensure that the mother is either Eve or a descendent of Eve? And there should probably be a father case in there as well?

[–] [email protected] 1 points 6 months ago* (last edited 6 months ago) (1 children)

Depends on how you want to define your domain knowledge.

The thing you need to define for sure is the predicate mother/2 (Which has arity 2, or in other words, two arguments). From then on, multiple options are available:

  1. Take mother(X, Y) as an "axiom", and define mother terms for all elements:
mother(abel, eve).
mother(isaac, sarah).
  1. Derive mother(X, Y) from female(X) and parent(X, Y) terms.
mother(X, Y) :- 
  parent(X, Y), 
  female(Y).
  1. Smash the institutional gender power structures and define only parent/2 terms instead of mother/2 and father/2.
[–] [email protected] 1 points 6 months ago

I never saw such a potent combination of gender politics and prolog

[–] [email protected] 1 points 6 months ago* (last edited 6 months ago)

doesn’t this definition lack a recursive case to ensure that the mother is either Eve or a descendent of Eve

We don’t see the definition of mother. It might already encode that Y is a person.

And there should probably be a father case in there as well?

While every person does also have a father, it’s completely redundant, since being a person can fully be described by [Edit: ~~being~~ having] a mother (or being Adam or Eve).