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

Fixes issue #555 #608

Merged
merged 1 commit into from
Jul 11, 2017
Merged

Conversation

DonyorM
Copy link
Contributor

@DonyorM DonyorM commented May 1, 2017

This fixes issue #555

This modifies the file-filter function so that if the criteria seq is
empty, it simply returns an empty list.

An empty list was chosen instead of simply returning nil because an empty list allows seq functions (conj, cons, etc.) to continue to work.

->file #(if (tmp? %) (io/file (tmp-path %)) (io/file %))
pred (apply juxt (mapv mkpred criteria))]
(filter-files #(pred (->file %)) files negate?))))
(if (empty? criteria)
Copy link
Contributor

Choose a reason for hiding this comment

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

this works, but a more idiomatic way would be:

(when (seq criteria))
 ....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would that not result in a nil return if the seq was empty? I'm still new to Clojure and Boot, so I may be missing something.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep it returns nil.
I have been thought that you should always check using (seq coll) if the collection contains stuff (wonderfully in The Joy of Clojure). This has to do with how lazy sequences where implemented in Clojure and it is very different from how things are done in other Lisps (you can google nil punning and nil punning next rest in Clojure).

@DonyorM
Copy link
Contributor Author

DonyorM commented May 1, 2017

Huh, I just noticed that #600 fixed this issue as well. hit023 said for me to do ahead and fix it, and I hadn't thought about checking pull requests.

Anyway, this does have the advantage of passing the tests.

@DonyorM
Copy link
Contributor Author

DonyorM commented May 2, 2017

@arichiardi Updated it to match your suggestions.

@arichiardi
Copy link
Contributor

You know I have been thinking about this and I was wondering whether it is a good idea to filter all the items if no criterias are given...Maybe this is why the behavior was to crash..Is nil the same as passing an identity function? Does it need to flip behavior when negate? is true?

The least surprising thing is maybe to return all the files in case of empty criteria, maybe, thoughts?

@DonyorM
Copy link
Contributor Author

DonyorM commented May 2, 2017

Though I assume you were asking that as a more general, question, I'll still put my thoughts down.

This is basically a divide by zero situation. Does nothing match anything?

More concretely, my suggest would to be return nil following from the divide by zero situation. If you do something impossible, return a result that's basically "undefined." (Ok the analogy is a stretch).

@arichiardi
Copy link
Contributor

But ok, so if the behavior is undefined, maybe it is better to throw the error then, this is my biggest doubt.

@DonyorM
Copy link
Contributor Author

DonyorM commented May 15, 2017

Soooo, what do we want to do with this?

@arichiardi
Copy link
Contributor

Seeking advice? 😀 The undefined behavior above that you describe is good, but I still think nil carries some other connotation. Dunno maybe it is just me, I'd like to hear more opinions.

@DonyorM
Copy link
Contributor Author

DonyorM commented May 15, 2017

I was partially seeking those other opinions :)

@arichiardi arichiardi mentioned this pull request May 27, 2017
@martinklepsch
Copy link
Member

How about

(assert (seq criteria) "by-path requires a list of matching paths, if you want all files use boot.core/ls")

Or something like that. Perhaps added to all the by-* functions individually. It seems that passing no critera should essentially be undefined behavior, especially in combination with :negate? it can become weird.

What do you think?

@arichiardi
Copy link
Contributor

arichiardi commented Jun 2, 2017 via email

@arichiardi
Copy link
Contributor

@DonyorM what do you think? Shall we finish this off? 😁

@DonyorM
Copy link
Contributor Author

DonyorM commented Jun 16, 2017

@arichiardi @martinklepsch Updated the commit. Let me know if I should ask anything else.

@@ -1218,6 +1218,7 @@
"A file filtering function factory. FIXME: more documenting here."
[mkpred]
(fn [criteria files & [negate?]]
(assert (seq criteria) "file-filet (called from by-*) requires a list of matching paths, if you want all files use boot.core/ls")
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a lil' typo there and I would drop the if you want ... because if you call it from by-ext is a weird message back...my proposal:

boot.core/file-filter requires a list of criteria but null was passed in, make sure your `by-*` calls are passing them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks good to me. Just pushed a new commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still don't see it, GitHub seems a bit slow today

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, sorry, somehow didn't commit the changes.

@DonyorM DonyorM force-pushed the fix-emptyPathError-555 branch 2 times, most recently from de783e4 to 9d8446f Compare June 16, 2017 21:33
@arichiardi
Copy link
Contributor

A part for Changelog and better working ( I am using to pass twice there lol) I think this is finally good to go 😀

@DonyorM
Copy link
Contributor Author

DonyorM commented Jun 17, 2017

@arichiardi Added changes.md. I put this under improved, since it's kind of new behavior

@arichiardi
Copy link
Contributor

Thanks a lot @DonyorM and sorry for this long conversation, I maybe swayed you a bit from the final solution but I see this is an improvement. I spent myself quite some time trying to figure out what the failure was and opened the issue in frustration 😁😁 this will avoid the trouble for other folks 👍 Good job!

@DonyorM
Copy link
Contributor Author

DonyorM commented Jun 17, 2017

@arichiardi No problem. It wasn't simple to figure out the best way to do this. Thanks for your help!

@DonyorM
Copy link
Contributor Author

DonyorM commented Jul 9, 2017

Anything else I need to do for this?

@arichiardi
Copy link
Contributor

No 👍 I think @alandipert or @micha will merge it eventually.

@martinklepsch
Copy link
Member

👍

@@ -1218,6 +1218,7 @@
"A file filtering function factory. FIXME: more documenting here."
[mkpred]
(fn [criteria files & [negate?]]
(assert (seq criteria) "boot.core/file-filter requires a list of criteria but null was passed in, make sure your `by-*` calls are passing them.")
Copy link
Member

Choose a reason for hiding this comment

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

actually null could be nil here but not too important haha :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha, I was stuck in java land there. Just pushed an update to change it.

This modifies the file-filter function so that if the criteria seq is
empty, it throws an error.
@alandipert alandipert merged commit cb923ee into boot-clj:master Jul 11, 2017
@alandipert alandipert added this to the next-release milestone Jul 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants