Absolute Truth in programming languages
August 22, 2014 [C++, Lisp, Programming, Programming Languages, Python, ruby, Scheme, Tech]Is enforcing truthfulness the opposite of beauty?
Can 2 + 2 = 5?
Improvements, corrections, further contributions are welcome.
$ cat five.cpp #include <iostream> int operator+( int x, int y ) { return 5; } int main() { std::cout << 2 + 2 << std::endl; } $ g++ five.cpp five.cpp:2:29: error: ‘int operator+(int, int)’ must have an argument of class or enumerated type
$ python >>> int.__add__ = lambda y: 5 TypeError: can't set attributes of built-in/extension type 'int'
$ cat five.hs import Prelude hiding ((+)) x + y = 5 main = print ( 2 + 2 ) $ ghc five.hs && ./five 5
$ cat five.rb class Fixnum def +(y) 5 end end print 2 + 2 $ ruby five.rb 5
$ mzscheme > (define (+ x y) 5) > (+ 2 2) 5