~/ learn/ comp-456/ cards/ Prolog programming drills
1 of 6

Type the Q3 product-of-list predicate (Prolog)

Type the Q3 product-of-list predicate (Prolog)

Answer

product([], 1). product([H|T], P) :- product(T, PT), P is H * PT.

Base value is 1 (multiplicative identity). The recursive clause splits [H|T], solves the tail, then multiplies the head back in — the standard list-fold shape.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/fbdd936d-d20f-4dca-b2ab-fed9af924091/flashcard utf-8 LF