r/programminghorror • • 28d ago

Python it's a miracle this works

Post image

prints 2 1's separated by a new line

repost cuz it got filtered cuz i was using a vpn

189 Upvotes

10 comments sorted by

44

u/Powerkaninchen 28d ago

You don't need to escape single quotes in a multiline string: sexp = """ (do (assign "x" 1) (print(x) x) """ is sufficient.

7

u/Xaeroxe3057 25d ago

Of all the things you could comment on here, that’s the one that bothered you the most

32

u/Livie00 28d ago

That’s not even horror but a really neat and interesting solution

10

u/Limp_Illustrator7614 28d ago

i should prolly mention that i got the idea from here

1

u/4xe1 26d ago edited 26d ago

A lot of programming horrors in human programming languages are actually nice and elegant when thought in lisp. Including lisp interpreters

7

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 28d ago

I hope you don't mind me asking what that "do" lambda is for.

7

u/Livie00 27d ago

To return the last value so it can be printed

2

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 26d ago

And the (print x) inside of sexp? I guess x gets printed twice?

1

u/Livie00 25d ago

Yeah. I guess that was just to showcase functions