i i i i i i i ooooo o ooooooo ooooo ooooo I I I I I I I 8 8 8 8 8 o 8 8 I \ `+' / I 8 8 8 8 8 8 \ `-+-' / 8 8 8 ooooo 8oooo `-__|__-' 8 8 8 8 8 | 8 o 8 8 o 8 8 ------+------ ooooo 8oooooo ooo8ooo ooooo 8
Добро пожаловать GNU CLISP 2.46 (2008-07-02) <http://clisp.cons.org/> Copyright (c) Bruno Haible, Michael Stoll 1992, 1993 Copyright (c) Bruno Haible, Marcus Daniels 1994-1997 Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998 Copyright (c) Bruno Haible, Sam Steingold 1999-2000 Copyright (c) Sam Steingold, Bruno Haible 2001-2008 Напечатайте :h и нажмите Ввод для получения справки. [1]> (defmacro infix (e) `(destructuring-bind (x f y) ,e (funcall f x y))) INFIX [2]> (infix (5 + 4)) *** - EVAL: 5 не является именем функции, попробуйте какой-нибудь символ Имеются следующие варианты продолжения: USE-VALUE :R1 Вы можете ввести новое значение для использования. ABORT :R2 Прервать главный цикл Break 1 [3]> :r2 [4]> (infix '(5 + 4)) 9 [5]> All, I give up! :) On 27 сен, 21:44, Mark Rathwell <mark.rathw...@gmail.com> wrote: > > In this point I want to cite Clojure doc, that say nothing about > > expansion and runtime, once more: "..If the operator of a call is a > > symbol that names a global var that is a macro function, that macro > > function is called and is passed the /unevaluated/ operand forms. " > > So, when I write the macro function body, I expect that operands are > > unevaluated when my body is executed to get an expanded form (finally > > expanded), that will be executed afterward to get a result (at > > runtime, as you say). But this is not the case in the very first > > example: > > Yes, it is the case. The operands are not evaluated in the expansion > of the macro call, they are evaluated when that expanded code is > executed at run time. > > > user=> (defmacro infix [e] `(let [[x# f# y#] ~e] (f# x# y#))) > > #'user/infix > > user=> (infix (5 + 4)) > > java.lang.ClassCastException: java.lang.Integer cannot be cast to > > clojure.lang.IFn (NO_SOURCE_FILE:0) > > > I insist that expansion is not quite correct. Am I right? > > No, you are incorrect. The expansion happens as would be expected, > and is completely consistent with the documentation. If you use > macroexpand here, it is clear what is going on. The expansion of your > macro contains a call to a function '5', which is an integer, and > cannot be cast to a function. As I stated previously, you want a list > here, not a function call. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en