Received: by 10.180.86.133 with SMTP id p5mr765904wiz.3.1348723443601; Wed, 26 Sep 2012 22:24:03 -0700 (PDT) Path: q10ni762228wif.0!nntp.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: comp.lang.lisp Subject: Re: Trying to make my own reverse function Date: Thu, 27 Sep 2012 07:24:02 +0200 Organization: Informatimago Lines: 73 Message-ID: <87fw643uod.fsf@kuiper.lan.informatimago.com> References: <4b301750-d684-4467-91bd-ab9207d5d382@googlegroups.com> <20120925110438.405@kylheku.com> <01359518-4544-48e4-bb6d-76b764e39043@googlegroups.com> <9985c6fe-ea50-4ab3-91fd-decb165086e4@googlegroups.com> Mime-Version: 1.0 X-Trace: individual.net +e25M/0RSIONIFel0ASYDw9/gTcleTcdJQYoQPXe75ZN6bt2QK2JPlukIF8koapeqs Cancel-Lock: sha1:MjRkOGNjNTcyZWY5NDljNDM2NDJhZWY1N2Y3NjMxOTE5NjMzYmM1Mg== sha1:Z3tF9SwtfNGtD4NFSR+qKHItkhA= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Content-Type: text/plain; charset=us-ascii "Yves S. Garret" writes: > Yup, that did it. One question, does putting let at the bottom of the > function a bad thing? In a sense that the Lisp compiler will reject > that? Lisp is mostly an orthogonal language: you can combine any feature with any feature as you want, it will always make something that's accepted by a lisp compiler. It may not do anything meaningful or useful, but there are not a lot of invalid forms in lisp. This is because lisp sources are not sequences of characters, but lisp objects. See: http://groups.google.com/group/comp.lang.lisp/msg/6ec4dab4a8d57f6e http://groups.google.com/group/comp.lang.lisp/msg/3050088218d355e5 But then, cons cells are interpreted in Common Lisp as operator applications. The car of a cons cell MUST be an operator, that is, either a symbol, or a cons cell that's a lambda expression. NO other object is a valid operator in Common Lisp, and in particular, random lists are NOT operators! (sin 42) ; sin names a function (if (= a b) 3 4) ; if names a special operator (dolist (x l) (print x)) ; dolist names a macro ((lambda (x) (* x x)) 42) ; (lambda (x) (* x x)) "names" the ; function that squares its argument. ((list 'lambda '(x) 'x) 42) ; is NOT a valid CL form. There's no operator named (list 'lambda '(x) 'x). Even if (list 'lambda '(x) 'x) is a form that evaluates to a lambda expression that "names" an operator, (list 'lambda '(x) 'x) itself is not an operator! (+ 3 4) _is_ not 7. (+ 3 4) _evaluates_ to 7. (+ 3 4) _is_ a list. (+ 3 4) _evaluates_ to an integer. That's why you cannot add parentheses (that is, you cannot put conses in car of conses) around forms. Remember ( = operator call. Now of course, there's the special case of special operators and of macros, which can interpret their subforms differently than CL:EVAL. For example, CL:LET interprets the second subform, not as a lisp form (not as an operator call), but as a list of bindings, which can themselves be lists (of a variable and an optional initial value expression), and therefore, you can have two open parentheses there, because they're not operator calls. +-- not lisp code, not an operator call! | v (let ((x 1) (y 2)) (+ x y)) (random-macro (x y z) (z a b)) ^ ^ | | +-------+--- we cannot know what those are without knowing the random-macro. data? code? Only random-macro knows. You can even write a macro that interprets the sexps as in scheme: (scheme ((list 'lambda '(x) '(* x x)) 42)) --> 1764 -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}.