[erlang-patches] Support ** for recursion in filelib:wildcard

Björn Gustavsson <>
Wed Mar 14 07:23:52 CET 2012

On Mon, Feb 20, 2012 at 5:18 PM, José Valim <> wrote:
> So here is a patch that allows ** in filelib:wildcard() in order to support
> recursion.

Thanks for your contribution. I have reviewed it, and found some issues
that will need to be fixed before we can consider including it in Erlang/OTP.

Behavior: You say: "** now works similarly to bash, ruby, racf, etc".
We'll need a better description of the behavior than that. It seems to
me that bash 4 and ruby may implement '**' slightly differently, but I
cannot be sure since ruby's documentation does not fully describe what
'**' does. Bash 4's documentation of '**' is terse, but it does describe
the behavior in detail.

I suggest that you implement '**' the same way as in Bash 4.
If you don't agree, you should justify your decision in the commit

Hint: A single "**" pattern gives different result in Bash 4 and
your implementation, and so does "**/lib/**/*.xsd" (run in the
OTP source tree).

Documentation: The behavior must be better described (perhaps
similar to the description in the Bash 4 manual) so that a reader
can actually understand what it does and doesn't do. One or more
examples should also be added.

Test suite: The test suite should be improved. There is no test
for multiple '**' patterns (for example, "**/lib/**/*.xsd"), and the
directory structure created for testing only has two levels; it
seems that you are only testing that '**' can match zero or
one levels (as opposed to zero or more).

Implementation: It seems that it is possible do more work during
compilation of the wildcard and less when evaluating it. I think
that it would be easier if you represent '**' as
{double_star,Pattern} always at the end of pattern list, and
that you can just recursively match Pattern going down one
level at the time until a recursive match does not find anything
more. That should probably take care of multiple '**' patterns
(which don't seem to work now).

Code style: Looks good with a few exceptions. The indentation
is off in one place in do_wildcard_3/4. Also, there are extra
blank lines between clauses; they should not be there.

Nit picking: The first line in the commit message should not
end in a period.


Björn Gustavsson, Erlang/OTP, Ericsson AB

More information about the erlang-patches mailing list