# Using lazy\_lists module to give out hash of a Swipl installer in Windows

**URL:** <https://swi-prolog.discourse.group/t/using-lazy-lists-module-to-give-out-hash-of-a-swipl-installer-in-windows/6584>\
**Category:** General\
**Created:** [May 28, 2023, 6:56pm UTC](https://swi-prolog.discourse.group/t/using-lazy-lists-module-to-give-out-hash-of-a-swipl-installer-in-windows/6584 "2023-05-28T18:56:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PasiK](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/pasik/32/84_2.png) [@PasiK](https://swi-prolog.discourse.group/u/PasiK)\
**Post date:** [May 28, 2023, 6:56pm UTC](https://swi-prolog.discourse.group/t/using-lazy-lists-module-to-give-out-hash-of-a-swipl-installer-in-windows/6584/1 "2023-05-28T18:56:01Z")

</div>

The lazy\_lists are mysterious to me … the page should have few simple examples in [Lazy list handling](https://www.swi-prolog.org/pldoc/doc/_SWI_/library/lazy_lists.pl).

Well I was motivated today to learn about them and got a grip this time …

The [Swi-Prolog download page](https://www.swi-prolog.org/download/devel/bin/swipl-9.1.10-1.x64.exe.envelope) download site does show this SHA256.  
I was really impressed how fast this is! I first tried to load the executable with read\_file\_to\_codes/3 and get the sha256 with that, it took like 15 seconds (in my Windows 10 laptop)

Then checked how fast the linux sha256sum command is, it is lighting fast.  
This is also lightning fast compared to 15 seconds … lazy\_list\_materialize … sounds like some Harry Potter command 🙂 … it has zero explanations at documentaion.

```prolog
tst5(M):-
    open('../../downloads/swipl-9.1.10-1.x64.exe',read,Stream,[type(binary)]),
    stream_to_lazy_list(Stream,LList),
    lazy_list_materialize(LList),
    sha_hash(LList, Hash, [algorithm(sha256),encoding(octet)]),
    hash_atom(Hash,M),
    close(Stream).

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [May 30, 2023, 9:00am UTC](https://swi-prolog.discourse.group/t/using-lazy-lists-module-to-give-out-hash-of-a-swipl-installer-in-windows/6584/2 "2023-05-30T09:00:00Z")

</div>

The download page uses this to compute the hashes. Note that it computes them only once such that they stay the same, even if someone manages to hack the server and modify the download file.

```prolog
compute_file_checksum(Path, Sum) :-
	crypto_file_hash(Path, Sum,
			 [ encoding(octet),
			   algorithm(sha256)
			 ]),
	assert_sha256(Path, Sum).

```

Using a Prolog list as intermediate is rather slow …

Anyway, _lazy lists_ are basically lists that end in an _attributed variable_ rather than `[]`. If you unify this variable to something it is replaced by the next _chunk_ of the list that (again) ends in an attributed variable. If the lazy list is finite, the last chunk ends the normal list way (`[]`).

They are mostly there to process huge amounts of data in finite memory. This implies they are mostly interesting for running algorithms that consider the list as an (possibly infinite) _stream_.

The thing you typically do not want to do with a lazy list is to _materialize_ it 🙂

The library is a generalization of library(pure\_input).
