def METHOD_NAME(system="gap", name="workspace", dir=None):
    r"""
    Return the filename for the GAP workspace.
    INPUT:
    - ``system`` -- the name of the system, either ``"gap"`` or
      ``"libgap"``
    - ``name`` -- the kind of workspace, usually ``"workspace"`` but
      the library interface also uses other files
    - ``dir`` -- the directory where the workspaces should be stored.
      By default, this is ``DOT_SAGE/gap``
    EXAMPLES::
        sage: from sage.interfaces.gap_workspace import gap_workspace_file
        sage: gap_workspace_file("foo", "bar", "/somewhere")
        '/somewhere/foo-bar-...'
    TESTS::
        sage: from sage.env import DOT_SAGE
        sage: D = gap_workspace_file()
        sage: D.startswith(os.path.join(DOT_SAGE, "gap", "gap-workspace-"))
        True
    Check that the name generated is independent of the session::
        sage: from subprocess import Popen, PIPE
        sage: import sys
        sage: cmd = 'import sage.all, sage.interfaces.gap_workspace; print(sage.interfaces.gap_workspace.gap_workspace_file())'
        sage: name1 = Popen([sys.executable, '-c', cmd], stdout=PIPE).communicate()[0]
        sage: name2 = Popen([sys.executable, '-c', cmd], stdout=PIPE).communicate()[0]
        sage: assert name1 == name2
    """
    if dir is None:
        dir = os.path.join(DOT_SAGE, 'gap')
    data = f'{GAP_LIB_DIR}:{GAP_SHARE_DIR}'
    for path in GAP_LIB_DIR, GAP_SHARE_DIR:
        sysinfo = os.path.join(path, "sysinfo.gap")
        if os.path.exists(sysinfo):
            data += subprocess.getoutput(f'. "{sysinfo}" && echo ":$GAP_VERSION:$GAParch"')
    h = hashlib.sha1(data.encode('utf-8')).hexdigest()
    return os.path.join(dir, f'{system}-{name}-{HOSTNAME}-{h}')