Permalink
Browse files

Add predicate `optional(_)::or_else_fail/1`

  • Loading branch information...
pmoura committed Dec 4, 2017
1 parent aaf6580 commit 8aa1e8e277d4912feaf8fbd0ff1ce8f914cc342c
Showing with 53 additions and 11 deletions.
  1. +4 −2 RELEASE_NOTES.md
  2. +1 −1 docs/index.html
  3. +1 −1 docs/optional_0.html
  4. +23 −3 docs/optional_1.html
  5. +10 −0 docs/predicate_index.html
  6. +14 −4 library/optional.lgt
View
@@ -46,8 +46,8 @@ sequence of `context/1` and `throw/1` method calls.
* FIXED: Detection of variable file terms and reporting of the corresponding
instantiation errors when processing `include/1` directives.
* FIXED: Error when calling `logtalk_make(check)` with missing predicates
found in included files.
* FIXED: Runtime error when calling `logtalk_make(check)` with missing
predicates found in included files.
Prolog adapter and integration files
------------------------------------
@@ -73,6 +73,8 @@ Library
* ADDED: Options `prefixes/1` and `suffixes/1` to the `os::directory_files/3`
predicate.
* ADDED: Predicate `optional(_)::or_else_fail/1`.
Tools
-----
View
@@ -16,6 +16,6 @@ <h1>Documentation index</h1>
<li><a href="entity_index.html">Entity index</a></li>
<li><a href="predicate_index.html">Predicate index</a></li>
</ul>
<p>Generated on Mon Nov 27 21:06:18 GMT 2017</p>
<p>Generated on Mon Dec 4 22:53:59 WET 2017</p>
</body>
</html>
View
@@ -11,7 +11,7 @@
<p class="type">object</p>
<h1 class="code">optional</h1>
<blockquote>
<p class="comment">Constructors for optional references. An optional reference represents a term that may or may not be present. Optional references should be regarded as opaque terms and always used with the "optional(_)" object by passing the reference as a parameter.</p>
<p class="comment">Constructors for optional term references. An optional reference represents a term that may or may not be present. Optional references should be regarded as opaque terms and always used with the "optional(_)" object by passing the reference as a parameter.</p>
</blockquote>
</div>
<div class="entity">
View
@@ -23,11 +23,11 @@ <h1 class="code">optional(Reference)</h1>
</dd>
<dt class="key">version:</dt>
<dd class="value">
<code>1.2</code>
<code>1.3</code>
</dd>
<dt class="key">date:</dt>
<dd class="value">
<code>2017/11/3</code>
<code>2017/12/4</code>
</dd>
</dl>
<dl class="properties">
@@ -265,7 +265,7 @@ <h3 id="or_else_get/2" class="code">or_else_get/2</h3>
<div class="section">
<h3 id="or_else_call/2" class="code">or_else_call/2</h3>
<blockquote>
<p class="comment">Returns the optional reference term if not empty or calls a goal deterministically if the optional is empty. Often called from within all solutions predicates as an alternative to the get/1 predicate by using fail/0 as the goal to skip empty optionals.</p>
<p class="comment">Returns the optional reference term if not empty or calls a goal deterministically if the optional is empty. Can be used e.g. to generate an exception for empty optionals.</p>
</blockquote>
<dl class="properties">
<dt class="key">compilation flags:</dt>
@@ -286,6 +286,26 @@ <h3 id="or_else_call/2" class="code">or_else_call/2</h3>
</dd>
</dl>
</div>
<div class="section">
<h3 id="or_else_fail/1" class="code">or_else_fail/1</h3>
<blockquote>
<p class="comment">Returns the optional reference term if not empty. Fails otherwise. Usually called to skip over empty optionals.</p>
</blockquote>
<dl class="properties">
<dt class="key">compilation flags:</dt>
<dd class="value">
<code>static</code>
</dd>
<dt class="key">template:</dt>
<dd class="value">
<code>or_else_fail(Term)</code>
</dd>
<dt class="key">mode &ndash; number of proofs:</dt>
<dd class="value">
<code>or_else_fail(--term) &ndash; zero_or_one</code>
</dd>
</dl>
</div>
</div>
<div class="protected">
<h2>Protected interface</h2>
View
@@ -3945,6 +3945,16 @@ <h1 class="code">
</code>
</dd>
</dl>
<dl>
<dt id="or_else_fail/1">
<code>or_else_fail/1</code>
</dt>
<dd class="code">
<code>
<a href="optional_1.html#or_else_fail/1">optional(Reference)</a>
</code>
</dd>
</dl>
<dl>
<dt id="or_else_get/2">
<code>or_else_get/2</code>
View
@@ -25,7 +25,7 @@
version is 1.2,
author is 'Paulo Moura',
date is 2017/08/08,
comment is 'Constructors for optional references. An optional reference represents a term that may or may not be present. Optional references should be regarded as opaque terms and always used with the "optional(_)" object by passing the reference as a parameter.',
comment is 'Constructors for optional term references. An optional reference represents a term that may or may not be present. Optional references should be regarded as opaque terms and always used with the "optional(_)" object by passing the reference as a parameter.',
remarks is [
'Type-checking support' - 'This object also defines a type "optional" for use with the "type" library object.'
],
@@ -86,9 +86,9 @@
:- object(optional(_Reference)).
:- info([
version is 1.2,
version is 1.3,
author is 'Paulo Moura',
date is 2017/11/03,
date is 2017/12/04,
comment is 'Optional reference predicates. Requires passing an optional reference constructed using the "optional" object as a parameter.',
parnames is ['Reference'],
see_also is [optional]
@@ -174,10 +174,17 @@
:- meta_predicate(or_else_call(*, 0)).
:- mode(or_else_call(--term, +callable), zero_or_one).
:- info(or_else_call/2, [
comment is 'Returns the optional reference term if not empty or calls a goal deterministically if the optional is empty. Often called from within all solutions predicates as an alternative to the get/1 predicate by using fail/0 as the goal to skip empty optionals.',
comment is 'Returns the optional reference term if not empty or calls a goal deterministically if the optional is empty. Can be used e.g. to generate an exception for empty optionals.',
argnames is ['Term', 'Goal']
]).
:- public(or_else_fail/1).
:- mode(or_else_fail(--term), zero_or_one).
:- info(or_else_fail/1, [
comment is 'Returns the optional reference term if not empty. Fails otherwise. Usually called to skip over empty optionals.',
argnames is ['Term']
]).
is_empty :-
parameter(1, empty).
@@ -256,4 +263,7 @@
; Reference = the(Term)
).
or_else_fail(Term) :-
parameter(1, the(Term)).
:- end_object.

0 comments on commit 8aa1e8e

Please sign in to comment.