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 new sample to add predicate get_time/1 #338

Closed
wants to merge 1 commit into from

Conversation

rogersm
Copy link

@rogersm rogersm commented Oct 25, 2024

Folks,

in case you're interested I added a new example to implement get_time(-Timestamp).

Feel free to add it if you think is useful.

Roger.

Copy link
Owner

@ichiban ichiban left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @rogersm!

Even though this is a good example in general, I don't think it adds variety to the existing examples. Could you make it showcase other features we don't cover yet, please?

// Check if the input arguments are of the types you expected.
_, ok := env.Resolve(TimeStamp).(engine.Variable)
if !ok {
return engine.Error(engine.TypeError(engine.NewAtom("variable"), TimeStamp, env))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They removed type_error(variable, Culprit) from the standard in ISO/IEC 13211-1:1995/Cor.2:2012 and replaced it with uninstantiation_error(Culprit).

see https://www.complang.tuwien.ac.at/ulrich/iso-prolog/error_k#error_classes

Another predicate design I often see is to think Timestamp can be an integer but you can leave it as a variable. Let's say we call get_time(1735657200) at the right time. It should succeed, right? If you missed the timing, it fails. A variable should work fine too but for anything else, type_error(integer, Culprit).

You don't have to follow these in your get_time/1 but I prefer the ISO Prolog way in the examples.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ichiban, afais, the uninstantiation_error(Culprit) error term isn’t available in the repo. Do you think it would be a useful addition?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ccamel It's not implemented bc I didn't need it while implementing ISO predicates. Oh, wait. I should have thrown uninstantiation_error(Stream) in open/[3, 4]. #339

Yes, it would be a great addition!

@rogersm
Copy link
Author

rogersm commented Nov 3, 2024

If it adds no value to the existing examples, I'll close it.

@rogersm rogersm closed this Nov 3, 2024
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.

3 participants