Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I thought what you wrote wasn't valid because xx isn't defined in the scope of the inequality... however I now realize that's because Hacker News deletes the asterisks. In any case, it's

[x [asterisk] x for x in [1,2,3,4] if x[asterisk] x < 10]

which is still a little annoying because the x [asterisk] x gets computed twice. This is one of those little details that really annoys mathematicians, as I saw with SageMath for decades (I started SageMath -- which uses Python -- and got no end of complaints about the above). In the Magma programming language there is a "where" version of comprehensions that eloquently solves this problem as explained here: http://magma.maths.usyd.edu.au/magma/handbook/text/10

For example,

{ xx : x in [1 .. 4] | xx lt 10 where xx is x*x}

which you can try at http://magma.maths.usyd.edu.au/calc/



> however I now realize that’s because Hacker News deletes the asterisks

You can escape asterisks with a backslash. \* => *




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: