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

argument checking: use "assume" or always call error? #354

Open
jpellegrini opened this issue Jan 10, 2022 · 2 comments
Open

argument checking: use "assume" or always call error? #354

jpellegrini opened this issue Jan 10, 2022 · 2 comments

Comments

@jpellegrini
Copy link
Contributor

Hi @egallesio !

Some SRFIs use assume in arguments checking (like SRFI-214, flexvectors). Others always raise an error.
Maybe this should be standardized? Either always one of them, or always the other?
I can slowly change the SRFIs to always use assume if you think this is OK.

@egallesio
Copy link
Owner

The pro of assume is that the test is not done if you are not in debug mode (it's expansion is #void, so it's fast 😄). The con is that if the user doesn't set the debug flag, its code could fail miserably. In this way, its very similar to the C assert function.

IMHO, assume should be used for internal functions to assume that a certain property is true at a given point, but if the test involves a data given by the user error is better. So both can probably cohabit in a program.

For instance:

(define (public-foo n)
  (unless (integer? n)
    (error "bad integer" n))
  (internal-bar (* n n)))

(define (internal-bar n)
  (assume (positive? n))
  .....
  .....)

This is just my opinion, conforming of what STklos is able to do with assume (SRFI 145 depicts situations the compiler cannot handle).

@jpellegrini
Copy link
Contributor Author

Ok, I'll review some of the SRFIs later and see if we need to change anything

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

No branches or pull requests

2 participants