Tue 06 Aug 2013 11:28:07 PM UTC, comment #3:
I'm actually working on the classdef branch in the hg repo. But according to
the 'what' script hasn't been changed between those, and that's all the patch touches.
I suppose for reliability, I should also actually build the 'default' branch and confirm that it works there too... and sure enough, it does.
|
Sat 03 Aug 2013 11:55:05 PM UTC, comment #1:
Oops, I think I mixed up pathsep and filesep in a couple of places in my original submission. Also upon further thinking, it looks like the implementation I proposed originally is not quite correct either. However, I'm attaching a patch that I think is pretty close to correct. Sorry if I didn't follow all the coding guidelines perfectly; I'm new to this.
Matlab's implementation is still slightly different (it doesn't actually call error() when no matches are found), but I'm less concerned about that than the core functionality.
(file #28752)
|
Sat 03 Aug 2013 10:33:55 PM UTC, original submission:
The "what" function is documented as
However, the test in the code doesn't actually behave this way. Specifically, the code uses strfind without any backup checks, such that you can get things like the result below, where the input to what() doesn't match the directory looked up, or even any whole directory name.
This leads to very frustrating results if I want to use what to look up the contents of any directory that has subdirectories, or any directory that happens to match any part of the path to the octave root.
The current implementation does one of two things for matching the directory name:
1. if the input DIR does not contain pathsep(), returns the last item on the user's path that matches DIR, irrespective of where that pathname matches
2. otherwise interpret DIR as being relative to the current working directory, and error if it does not exist.
This is incorrect in between 1 and 3 ways depending on how well you want to match MATLAB's behavior:
1. DIR should match the name of the directory being looked up, not earlier in the path, i.e. it should be anchored at the end of the path being matched, and should not be allowed to match partial directory names
2. DIR should be able to match locations in the user's path, even if it contains pathsep; conversely, even if DIR doesn't contain pathsep, it should match a subdirectory of the current working directory.
3. If multiple directories match, info about all of them should be returned, rather than the last one.
I'm thinking the implementation would be something like:
1. construct a list of all directories in the path and all directories in the current directory.
2. split each item in your list on pathsep(). similarly, split DIR on pathsep().
3. say the split form of DIR contains N items. remove all but the last N items from all fields in your list
4. call isequal on each item in the list vs the split form of DIR to find the ones that match
5. support returning info for multiple directories
|