variables - In Lisp, how do you call a function from a macro, by name passed as an argument? -
In Lisp, how do you call the macro, the function whose name is the symbol value of the symbol? I may be wrong, but I think that I am right that the symbol is a variable.
What I currently have here:
(defmacro cfunc (ab) (list works (cfunc my-func data); works foo to evaluate my symbol value. I have to add. (cfunc foo data) and I call the function (foo data) instead of (my-func data) Is that I instead define cfunc # 'foo is not working, which gives (function foo) which is cfunc and call ((function foo) data) . (symbol-value foo) can not work either, so I'm thinking that I will get the I can not change what is changed on cfunc , but I make the function cfunc .
If any one is a specific page of a resource that gives me < Evaluate and use the code> defmacro I can appreciate it or I can search keywords for special characters such as # and so on, if I can also share it .
First of all, as (cfunc foo data) , what do you do Is the reference to data ? I have not found any definition about it, it is simply coincidentally referred to as the parameter of the my-func function, which is not available for the expansion of your cfunc is. Perhaps you hope that data will later be available as a special variable.
In any case, the problem you are running is that the general Lisp is a "Lisp-2"; A variable at the top of someone does not exist, for a function it does not automatically get its function cell to reach it for its function. In your case, foo is not a function bound in the environment; It is a variable whose value is a symbol ( my-func ) is the one which is in turn obliged to function. To navigate this additional level of interception, you have to request that the function of the symbol be accessed by the cell, either through funcall or in other cases function .
Here are some comments from REPL:
& gt; (Symbol-value 'FU) MY-FUNC & gt; (Undiscovered errors (symbol-function 'FU)) Zero # & amp; UNDEFINED-FUNCTION FOO {1004E22D23} & gt; & Gt; (Fbongpi 'Foo) Zero & gt; (Undiscovered errors (symbol-value 'my-joke)) zero # & lt; Unbound-variable IARFUNC {1005324E93} & gt; & Gt; (Symbol-Function 'Mary-Funk) # & lt; FUNCTION MY-FUNC & gt; & Gt; Here we see that in the symbol foo in value binding รข ???? (Fboundp 'my-func) t This is an variable , but it has no compulsive work after I my-func via foo , we see that the My-func does not have any value, but functions are binding in it.
To do this, your cfunc macro should be written as:
(defmacro cfunc (ab) (list 'funcall Ab)) Alternatively, you can write it like this:
(defmacro cfunc (ab) `(funcall, a, b )) You originally mentioned that the purpose of
(cfunc my-func data) Works with, with my proposed revision above, it will not work anymore, because now as the argument for my-func to funcall Ulyankn to be considered as price , in fact it has no value cell (because it is a function). Therefore, you have to customize the form for:
(cfunc # 'my-func data) This is saying, "Look Function The symbol 'my-func' in the name space, grab its value, and provide that argument as an argument. "
For more precise treatment on the difference in dealing with such symbols - point out To do the work in Lisp-1 and -2, see Gabriel in a special way, see section 5, "Notional simplicity"
Comments
Post a Comment