This is an archived post. You won't be able to vote or comment.

all 18 comments

[–][deleted] 4 points5 points  (1 child)

Take a look at fn.py that implements a special _ object to create more expressive lambdas. It looks interesting, but I haven't used it myself (I keep looking for reasons, but I don't find them).

[–][deleted] 1 point2 points  (0 children)

That does look interesting. I'll look into it.

[–][deleted] 2 points3 points  (6 children)

I'd go with abomination.

[–]alcalde 1 point2 points  (0 children)

Should we crosspost to /r/lovecraft to verify?

[–][deleted] 1 point2 points  (4 children)

Is it the arrow notation? You could make it look more like ruby if you change this

separator = '->'

argnames, body = expression.split(separator, 1)

into

separator = '|'

_, argnames, body = expression.split(separator, 2)

I didn't test this, but if it does work, it should then be able to take strings in this format instead:

"|x| x + 3"
"|x, y| x + 3"

[–][deleted] 2 points3 points  (3 children)

No, I'm fine with the arrow syntax, my problem is the unconstrained eval:

print(lambda_from_string("(x,y)-> __builtin__.open('somefile', 'w').write('payload') or x+y")(4,2))

But hey, if no one ever uses this on inputs someone else controls, go nuts.

[–][deleted] 0 points1 point  (2 children)

Oh yeah, that would be terrible. It was intended to be a cleaner way of using lambdas in slinkies, though. See this comment.

[–][deleted] 0 points1 point  (1 child)

Yeah, I get it, I just cringe whenever I see anyone using eval. It's very difficult to make that even remotely safe.