Skip to content

Add UserHomeContract as inverse of UserHomeExpand#6262

Open
fingolfin wants to merge 1 commit intomasterfrom
codex/user-home-contract
Open

Add UserHomeContract as inverse of UserHomeExpand#6262
fingolfin wants to merge 1 commit intomasterfrom
codex/user-home-contract

Conversation

@fingolfin
Copy link
Member

AI assistance: Codex implemented the function, tests, and docs.

AI assistance: Codex implemented the function, tests, and docs.

Co-authored-by: Codex <codex@openai.com>
@fingolfin fingolfin added kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements topic: library release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes labels Mar 11, 2026
Copy link
Member

@reiniscirpons reiniscirpons left a comment

Choose a reason for hiding this comment

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

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");
~.gap

This 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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes topic: library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants