diff --git a/hy/__init__.py b/hy/__init__.py index 3a38caec5..dcd95c94c 100644 --- a/hy/__init__.py +++ b/hy/__init__.py @@ -24,11 +24,8 @@ def __call__(self, module_name): import importlib return importlib.import_module(module_name) def __getattr__(self, s): - import re - return self(hy.mangle(re.sub( - r'/(-*)', - lambda m: '.' + '_' * len(m.group(1)), - hy.unmangle(s)))) + from hy.reader.mangling import slashes2dots + return self(slashes2dots(s)) I = I() diff --git a/hy/reader/mangling.py b/hy/reader/mangling.py index 74b2c932b..538c38c4f 100644 --- a/hy/reader/mangling.py +++ b/hy/reader/mangling.py @@ -106,3 +106,11 @@ def unmangle(s): s = s.replace("_", "-") return prefix + s + suffix + + +def slashes2dots(s): + 'Interpret forward slashes as a substitute for periods.' + return mangle(re.sub( + r'/(-*)', + lambda m: '.' + '_' * len(m.group(1)), + unmangle(s)))