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

std/misc/func: pred-and & pred-or #514

Merged
merged 1 commit into from
May 23, 2020

Conversation

thibran
Copy link

@thibran thibran commented May 22, 2020

pred-and allows to check if a pred holds on multiple circumstances without constructing a filtered list of to-be-checked items beforehand.

@thibran thibran force-pushed the misc/func/pred-and-pred-or branch from 0616516 to a6bb977 Compare May 23, 2020 08:12
@vyzo
Copy link
Collaborator

vyzo commented May 23, 2020

I was actually thinking of not invoking the predicate at all if we are short-circuiting; not sure if it can be written with chain though.

@thibran thibran force-pushed the misc/func/pred-and-pred-or branch from a6bb977 to eade74b Compare May 23, 2020 08:31
(def (pred-and pred)
(def res #t)
(lambda (v)
(match res
Copy link
Collaborator

Choose a reason for hiding this comment

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

we don't quite need match here, just an if will do :)

(def res #t)
(lambda (v)
(match res
(#t (set! res (and res (pred v))) res)
Copy link
Collaborator

Choose a reason for hiding this comment

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

no need to and, it's already #t.

(def (pred-or pred)
(def res #f)
(lambda (v)
(match res
Copy link
Collaborator

Choose a reason for hiding this comment

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

similarly here, just if.

(def res #f)
(lambda (v)
(match res
(#f (set! res (or res (pred v))) res)
Copy link
Collaborator

Choose a reason for hiding this comment

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

and here the or is unnecessary.

Copy link
Author

Choose a reason for hiding this comment

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

I'll should go and sleep again

Copy link
Collaborator

Choose a reason for hiding this comment

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

haha, yeah, I have mornings like that too...

@thibran thibran force-pushed the misc/func/pred-and-pred-or branch from eade74b to 825411e Compare May 23, 2020 08:38
@thibran thibran force-pushed the misc/func/pred-and-pred-or branch from 825411e to 01cb74a Compare May 23, 2020 08:40
Copy link
Collaborator

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

thank you!

@vyzo vyzo merged commit 70711cf into mighty-gerbils:master May 23, 2020
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