Closed philoskim closed 7 years ago
{:vat 1.05}
This doesn't do what you think it does!! Try running Hy with --spy
and you'll see what I mean.
(But the short version is that :val
in any context other than keyword arguments is compiled to \UNICODECHARCTERval
, including here.)
Interestingly, this does work with symbols:
=> (total-purchase #* [10 15] #** {'vat 1.05})
165.375
If you were splicing into a function call in a quasiquote (like for a macro), then you do have to use keywords:
=> (eval `(total-purchase ~@[10 15 ':vat 1.05]))
165.375
To be precise, both symbols and keywords are subclasses of str
(or unicode
) and hence can be used as keyword arguments, but the keyword :foo
has the string value "\ufdd0:foo"
, not "foo"
. The reason that (total-purchase 10 15 :vat 1.05)
works is that a literal keyword in a function call is magical: it compiles to a keyword argument (in the Python sense of the word "keyword"), and the leading "\ufdd0:"
is stripped.
I got an error like this in 'hy 0.13.0+50.gd9a5acb using CPython(default) 3.5.3 on Linux'.