-
Notifications
You must be signed in to change notification settings - Fork 18
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
support $
interpolation in glob"..."
macro?
#27
Comments
As discussed in #47 , you can use This strategy is analogous to regex: Instead of allowing for string interpolation in |
Using Regexes are different, because |
I see your point and I agree with you! Thank you for your clarification. While we are at it, I also wish the standard string concatenation worked on Globs. With Regex, you can do something like this: a = r"hello"
b = r".*\.jpg"
m = match(a*b, "hello3.jpg") # matches You sometimes prefer string interpolation and sometimes concatenation, depending on the complexity. |
I would make concatenation a separate issue, because its implementation seems entirely separate from (and much simpler than) that of interpolation. |
Note that @vtjnash commented on this issue on discourse and also #47 (comment) He noted that if you are using this to interpolate path components then you have to be careful, because arbitrary paths might contain glob metacharacters that should be escaped to be treated as literals within a glob. |
Right, as I mentioned there, this is somewhat intentionally unimplemented, as putting a path into the fnmatch is rather risky (it doesn't work well on Windows with the path separator is different or on Unix where metacharacters are legal in the path itself), so doing exactly raw text seemed the least surprising, and the most similar to fnmatch in a shell We also could do something slightly special (relative to most shells), where fnmatch treats the contents of the |
As I said, I understand your point, but my argument is different . . . If we didn't have a = "hello"
for file in readdir()
m = match(Regex("$(a).*\\.jpg")) # You have to be careful!
isnothing(m) && continue # skip the file if it doesn't match the pattern
# . . .
end The same risk as you are talking about exists in the above code. For that reason, I didn't understand why you needed to emphasize this risk. (It seemed to me that you were pointing to the risk as an argument not to implement these features.) |
I am not opposed, but just noting that since globs are not filepaths (e.g. glob"a//b" does not match the path "a//b" and starting with "/" isn't legal), there seems like a lot of hidden complexity in what happens if someone does try to include something there other than a simple file path ending in |
Since
$
isn't used for glob patterns, it might be nice to implement Julia interpolation when a non-backslashed$
is encountered inglob"..."
rather than treating it as a literal dollar sign.(See also discourse.)
The text was updated successfully, but these errors were encountered: