Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADDED: library(options) #1134

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

ADDED: library(options) #1134

wants to merge 3 commits into from

Conversation

triska
Copy link
Contributor

@triska triska commented Dec 5, 2021

This library is mostly intended for authors of other libraries. I did not even mention it in the README, because it only contains a single predicate: option/3, to ask whether an option was specified, obtaining its value, and to use a default if the option is not stated explicitly.

Still, I think this is a useful building block, and makes option processing in various libraries easier, more correct, and less error-prone. I have used it in library(crypto) and library(charsio) to show how it works.

This library is useful mostly in other libraries, to more easily
reason about options of various predicates. Currently, the only
provided predicate is option/3 to ask for the value of an option,
and use a default value if the option is not specified explicitly.
@UWN
Copy link

UWN commented Dec 6, 2021

What happens with an unexpected option? Please note that options have been added in Cor.3. It seems you only support certain instantiation errors.

@triska
Copy link
Contributor Author

triska commented Dec 6, 2021

Yes, this is very preliminary currently, limited to selecting the needed option!

Type checks for options can be added with suitable declarations, maybe with a second predicate that goes through the options. The check may even be performed statically in some cases, using goal expansion.

@pmoura
Copy link
Contributor

pmoura commented Dec 6, 2021

An example of an options library supporting optional type-checking (follow the link to the API for details) for ideas and comparison:

https://logtalk.org/manuals/libraries/options.html

@UWN
Copy link

UWN commented Dec 6, 2021

So far, options are producing arbitrary type and domain errors, but with an incorrect option, there is only one domain_error(xxx_option,...) the additional in some sense more precise error needs to be caught and then put in the 2nd argument of error/2.

@triska triska marked this pull request as draft December 6, 2021 23:33
@triska
Copy link
Contributor Author

triska commented Dec 6, 2021

OK, I have converted this pull request to a draft for the time being, maybe there is a better or more comprehensive way to solve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants