I am trying to pass a function as an argument and call that function in another function.
Part of my code looks like this:
(defun getmove(strategy player board printflag) (setq move (funcall strategy player board)) (if printflag (printboard board))
passed as a character represented in a two-dimensional list, like something like "randomstrategy
I keep getting the error: "FUNCALL:" RANDOMSTRATEGY is not a function name, try using the symbol instead ...
When I replace the "randomstrategy" strategy, it works fine. I can also name a random strategy myself. What is the problem?
? # ' . #. ( ) "
? funcall call evaluted. - . Variabe "RANDOMSTRATEGY. funcall . , ?
:
1) Symbol may denote variable with functional value 2) Symbol may denote global function (symbol-function - is the accessor in this case. 3) Symbol may denote local function (flet, labels and so on)
, RANDOMSTRATEGY
(defun RANDOMSTRATEGY ..)
FUNCALL: 'RANDOMSTRATEGY
, ( setq '' RANDOMSTRATEGY)?
"RANDOMSTRATEGY. " ? 'RANDOMSTRATEGY <= > (quote RANDOMSTRATEGY)
, strategy randomstrategy, (!) 'randomstrategy ( (quote randomstrategy)).
strategy
randomstrategy
'randomstrategy
(quote randomstrategy)
, , second, , , , - . , , getmove, 'randomstrategy, randomstrategy, . (, ?)
second
getmove
, , (funcall 'randomstrategy ...): 'randomstrategy, , , randomstrategy.
(funcall 'randomstrategy ...)
? .
(setq strategy 'randomstrategy) (setq move (funcall strategy player board))
Without seeing the code, I imagine that you are doing something like this:
(defun randomstrategy (abc) ...)
and then do the following:
(getmove 'randomstrategy xyz)
What you want to do is pass the "randomstrategy" function to getmove with # ':
(getmove # 'randomstrategy xyz)
In CommonLisp, # 'returns the function associated with the character that you want to pass to getmove.
Source: https://habr.com/ru/post/1721117/More articles:Database management in open source projects - databasePython email lib - Как удалить вложение из существующего сообщения? - pythonA design pattern for a class that works with a collection of other objects? - language-agnosticHow to add parent directory in SVN? - directoryHow to execute javascript after updating the update panel (cannot get Sys.WebForms.PageRequestManager.getInstance (). Add_endRequest (); work) - javascriptHow often should applications be subjected to load or load? - testingHow to invalidate cache when changing a page using Ajax? - jqueryMoving focus in response to keyboard events in XAML - wpfHow to distribute variable sized structures in memory? - c ++Subversion Automation with C # - c #All Articles