3 ms·
I was personally blown away when I read PG's summary of McCarthy's paper where he came up with a few primitives and built literally any function based on them,
by behnamoh 4y ago
I was personally blown away when I read PG's summary of McCarthy's paper where he came up with a few primitives and built literally any function based on them, including the `eval' function itself. All of this based on some really basic primitives like `atom' and `lambda'.
If writing `eval' is possible in the same language you started with, then you must be able to write your own eval, no? Or redefine the primitives? But then what happens if you accidentally set DEFINE to be 5? Restart the buffer? Is there any way to get back to your original definition of DEFINE after corrupting it?
- mtlmtlmtlmtl 4y agoI was gonna respond that you can't redefine the primitives because they're not functions or macros but special forms. And this seems true in Common Lisp. I can't define a function named SETQ(the primitive for assignment in CL, also called set! in other lisps) because it's a reserved name. But then I thought I'd try it in Guile and there I was allowed to (define define 5). Even though define is also a special form in Guile. Which made me unable to define further things, telling me 5 is not a valid argument to APPLY. And no I don't know how to fix it...
- deleted 4y ago[deleted]
- JadeNB 4y agoEvery language has the errors that it thinks you should not be allowed to make, and the errors that it trusts you to make on the assumption that you can determine whether you meant to make them better than the compiler. People complain on both sides of the permissiveness spectrum—they want a language that allows them to make exactly the errors that they want to make, but, of course, that set of errors differs from person to person!
- lispm 4y agoIn Common Lisp you can have namespaces, where you can have your own SETQ: CL-USER 53 > (defpackage mylisp (:use "COMMON-LISP") ; everything from Common Lisp (:shadow CL:SETQ)) ; but not SETQ #<The MYLISP package, 1/16 internal, 0/16 external> CL-USER 54 > (in-package "MYLISP") #<The MYLISP package, 1/16 internal, 0/16 external> MYLISP 55 > (defun setq (a b c) (print (list a b c))) SETQ MYLISP 56 > (setq (+ 1 2) 4 5) (3 4 5) (3 4 5) MYLISP 57 > (cl:setq a 12) 12 Most implementations also have a way to protect core symbols against redefinition and a way to do it anyway (possibly shooting yourself into the foot).
- mtlmtlmtlmtl 4y agoRight, I forgot about packages. Been far too long since I had an excuse to write Common Lisp :(
- easeout 4y agoHere's what happens in Chicken Scheme: #;1> (define define 5) Error: during expansion of (define ...) - redefinition of currently used defining form: (define define 5) Call history: <syntax> (define define 5) <--