gilch / hissp

It's Python with a Lissp.
https://gitter.im/hissp-lang/community
Apache License 2.0
369 stars 9 forks source link

Handle qualified names in `attach` #188

Closed gilch closed 1 year ago

gilch commented 1 year ago

The attach macro uses the variable name as the attribute name, unless a new attribute name is provided. Attrs are backed by dicts, so they can have any hashable key, but to use the attribute access syntax, they must be identifier strings. That's why qualified symbols don't work properly. They contain dots, so they're not valid identifiers. The macro doesn't detect the problem, but the docstring has a warning.

Kwargs in Hissp can have qualifiers, but they get stripped. They're added automatically by the template quote syntax, so it would be awkward to have to remember to suppress that every time. The attach macro could be made to work the same way, keeping only the final segment as the attribute name. It's probably a simple matter of splitting on the last dot, which wouldn't complicate the macro too much. It's no harder than detecting the error, and more useful, so that would be my preferred solution. I'll have to add some tests though.