New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
the f"" prefix is not supported (python3.6) #1239
Comments
It would really be nice if Hy supported this other Python versions, too...it seems like it wouldn't he too hard to compile... |
It seems that the replacement can be most any Python expression (possibly followed by format specifiers):
For Hy, It would perhaps make more sense to allow a Hy expression instead of a Python expression. |
yes, we definitely want to allow hy expressions:
I think we have the advantage of being to bring this feature back to python 2.7 (by generating old code), ie:
it's very close to the code that needs to be generated for python 3.6:
that is, we just insert the generated code in the {} in the string and replace the .format call with an f prefix. |
The main advantage of f-strings seems to be the format specifiers. I'm not sure how that should look in Hy. If you don't need that part, you can get pretty close with a => (setv a 2 b 3)
a = 2
b = 3
(a, b)
(2, 3)
=> (defn f [&rest xs] (.join "" (map str xs)))
from hy.core.language import map
def f(*xs):
return ''.join(map(str, xs))
=> (f "the sum of "a" and "b" is "(+ a b)"")
f('the sum of ', a, ' and ', b, ' is ', (a + b), '')
'the sum of 2 and 3 is 5' It doesn't look quite as nice in the Python translation, but HyExpressions don't use comma separators. |
I figured that |
FWIW I've started work in this, but it'll be a while before it's done... |
@kirbyfan64 You might try implementing only forms like |
It occurs to me that you could get the same effect on any version of Python with a pretty simple macro:
It would take work to make this permit things like nested fields and backslash-escaped |
if the backend is python 3.6, the f prefix for strings should be supported. see this for more information.
example:
The text was updated successfully, but these errors were encountered: