~/ 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/100c0102-7408-4c93-ad6d-07ca6fb21ea7/flashcard utf-8 LF