Doc needs fix
Maybe change the parameter name from Int to Length.
Notes
Some potentially useful notes
A length which never throws, and only fails
This is very low-hanging fruit, but may be useful:
- Code (raw code)
- New to modules? TL;DR for installation
Example
?- length(L,-1,lenient). false. ?- length(L,-1,strict). ERROR: Domain error: `not_less_than_zero' expected, found `-1' ?- length(L,-1,swi). ERROR: Domain error: `not_less_than_zero' expected, found `-1'
Extension of length∕2: probe_length∕3 and probe_length∕4
probe_length(@MaybeList, ?Length, ?What) probe_length(@MaybeList, ?Length, ?What, @Options)
probe_length∕3 and probe_length∕4 probe the length of an potentially open list without modifying it and tell you what the actual class of this maybe-list object is!
- Code (raw code)
- Unit tests (raw code)
- New to modules? TL;DR for installation
Examples:
?- probe_length([],Length,What). Length = 0, What = closed.
?- probe_length([a,b,c],Length,What). Length = 3, What = closed.
?- probe_length(_, Length, What). Length = 0, What = var.
?- probe_length([a,b,c,d|foo], Length, What). Length = 4, What = nonlist.