List sum

Description

Determining the length of a list using stack.

Source: PROLOG str. 195 Wydawnictwo PLJ Warszawa 1991 ISBN 83-85190-63-5

Download

Program source code: list_sum.pl

Listing

suma([], Sum, Sum, Ilosc, Ilosc).
suma([H|T], Sum, Sum1, Ilosc, Ilosc1) :- Nilosc is Ilosc + 1,
Nsuma is Sum1 + H, suma(T, Sum, Nsuma, Ilosc, Nilosc).
 
test :- suma([1, 2, 3, 4, 4, 5], S, 0, Ilosc, 0).

Comments

pl/prolog/pllib/list_sum.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0