Re:Swap_8_and_9: A simple import can modify the Python inter...
by fbdab103 on Wednesday August 09, 2023 @12:57AM
(#37058856)
I legit burst out laughing at the C solution (https://codegolf.stackexchange.com/a/28889). Definitely got me.
Re:Swap_8_and_9: A simple import can modify the Python inter...
by codeflo on Wednesday August 09, 2023 @02:55AM
(#37059490)
The Haskell one is not that spectacular if you understand that operators are just functions in that language:
λ> let 2+2=5 in 2+2
5
This simply defines a new local function that happens to be called "+". It's no different than something like this in JavaScript: let Math = { sqrt: (x) => 42 };
console.log(Math.sqrt(16));
Re:Swap_8_and_9: A simple import can modify the Python inter...
by lloeki on Wednesday August 09, 2023 @03:45AM
(#37059756)
The Ruby versions are a bit underwhelming, this is not 2+2=5 but much more underhanded:
https://youtube.com/watch?v=F3feRCr6S64
(recommend watching it by doing the four "tests" before going to the reveal)
Re:Swap_8_and_9: A simple import can modify the Python inter...
by jacketing on Wednesday August 09, 2023 @04:12AM
(#37059928)
Forth is probably cheating considering it has no restrictions when naming symbols.
: 4 5 ;
2 2 + .
Re:Swap_8_and_9: A simple import can modify the Python inter...
by jstanley on Wednesday August 09, 2023 @04:45AM
(#37060125)
Did you try this? This won't work.
What you did will make inputting a 4 yield a 5, but it won't change the behaviour of outputting a 4. (And it will only turn an input 4 into a 5 if your interpreter checks for words before checking for numbers which is not universally the case).
Re:Swap_8_and_9: A simple import can modify the Python inter...
by pgeorgi on Wednesday August 09, 2023 @06:26AM
(#37060702)
Try : + drop drop 5 ;
Re:Swap_8_and_9: A simple import can modify the Python inter...
by m6g6a on Wednesday August 09, 2023 @04:37AM
(#37060067)
this is how javascript works
Re:Swap_8_and_9: A simple import can modify the Python inter...
by bityard on Wednesday August 09, 2023 @12:56PM
(#37065500)
This reminds me of an SO user that was eventually banned because he (or possibly she, we will never know) had a hobby of writing fairly detailed questions that looked totally innocent on the surface but got strange once you started digging into them. Those that suffered through would eventually realize the whole thing was masterfully crafted to waste your time. There was once an excellent collection of these but I can't find it now and wish for the life of me I could.
https://codegolf.stackexchange.com/questions/28786/write-a-p...
Really shows you the skeletons hiding in some languages. My favorite is Haskell, which will happily do what you tell it to.