Add UserHomeContract as inverse of UserHomeExpand#6262
Add UserHomeContract as inverse of UserHomeExpand#6262
UserHomeContract as inverse of UserHomeExpand#6262Conversation
AI assistance: Codex implemented the function, tests, and docs. Co-authored-by: Codex <codex@openai.com>
reiniscirpons
left a comment
There was a problem hiding this comment.
Hi Max, looks good. One minor improvement below and one minor concern: what if the GAPInfo.UserHome variable had a trailing slash? I think with the current implementation we are in trouble:
gap> GAPInfo.UserHome := "/tmp/gap-home/";;
gap> UserHomeContract("/tmp/gap-home/.gap");
~.gapThis is of course not a concern for the expand function since slashes get undoubled in paths.
I can't seem to find any documentation on GAPInfo.UserHome on whether or not trailing slashes are permitted. Certainly gap doesn't complain if I set my userhome with a trailing slash. It seems they are uncommon for the $HOME env variable, but also not strictly prohibited. Probably best to add a check in this function just in case, also I don't know if this is a worry at all on Windows.
| BIND_GLOBAL("UserHomeContract", function(str) | ||
| if IsString(str) and Length(str) > 0 | ||
| and IsString(GAPInfo.UserHome) and Length(GAPInfo.UserHome) > 0 | ||
| and PositionSublist(str, GAPInfo.UserHome) = 1 then |
There was a problem hiding this comment.
| and PositionSublist(str, GAPInfo.UserHome) = 1 then | |
| and IsMatchingSublist(str, GAPInfo.UserHome) then |
Minor, but I think IsMatchingSublist (https://docs.gap-system.org/doc/ref/chap21_mj.html#X83F8EC7C7BF27EFC) might be better here, since we only care whether we match a prefix and the implementation is almost surely faster than for PositionSublist.
AI assistance: Codex implemented the function, tests, and docs.