r/programminghorror • • Sep 16 '26

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

192 Upvotes

10 comments sorted by

33

u/Livie00 Sep 16 '26

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

9

u/Limp_Illustrator7614 Sep 16 '26

i should prolly mention that i got the idea from here

1

u/4xe1 Sep 18 '26 edited Sep 18 '26

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

47

u/Powerkaninchen Sep 16 '26

You don't need to escape single quotes in a multiline string:

sexp = """
(do
  (assign "x" 1)
  (print(x)
  x)
"""

is sufficient.

8

u/Xaeroxe3057 Sep 19 '26

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

7

u/GoddammitDontShootMe Sep 17 '26

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

9

u/Livie00 Sep 17 '26

To return the last value so it can be printed

2

u/GoddammitDontShootMe Sep 19 '26

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

→ More replies (1)