English 中文(简体)
如何调用 lambda 通过 LISP 中的参数 [重复]
原标题:How to call lambda passed a parameter in LISP [duplicate]
  • 时间:2012-05-25 05:56:15
  •  标签:
  • lisp
  • elisp
This question already has an answer here:
Closed 11 years ago.

Possible Duplicate:
How to pass a lambda expression in Elisp

我有以下代码:

(defun my-map (p l)
  (mapcar (lambda (el) (p el)) l))

(defun test ()
  (my-map (lambda (x) (+ x 1)) (list 1 2 3)))

它抱怨它找不到功能p:

Debugger entered--Lisp error: (void-function p)
  (p el)
  (lambda (el) (p el))(1)
  mapcar((lambda (el) (p el)) (1 2 3))
  my-map((lambda (x) (x + 1)) (1 2 3))
  test()
  eval((test) nil)
  eval-expression((test) nil)
  call-interactively(eval-expression nil nil)
  recursive-edit()
  debug(error (void-variable test))
  eval(test nil)
  eval-expression(test nil)
  call-interactively(eval-expression nil nil

我猜它把 p 作为符号,而不在外部范围中受变量的约束。 如何使其发挥作用?

最佳回答

您想要使用 funcall

“C源代码”中的自定义功能是“C”源代码。

(未点名的功能 & amp; rest 指令)

Call first argument as a function, passing remaining arguments to it. Return the value that function returns. Thus, (funcall cons x y) returns (x . y).

问题回答

暂无回答




相关问题
Lisp code called from Java

Long story: I am doing a project for my functional programing class, and I thought of writing an AI controller in Lisp, for the Mario AI competition. I was looking over frameworks/libraries/ways of ...

Emacs, Zen-Coding mode, and Putty

I use emacs via Putty and since Putty doesn t send certain key combinations to the remote console I generally need to re-bind them to other key combinations. After installing the amazing Zen-Coding ...

In Which Cases Is Better To Use Clojure? [closed]

I develop in Lisp and in Scheme, but I was reading about Clojure and then I want to know, in which cases is better to use it than using Lisp or Scheme? Thanks

lambda-gtk negative pointer

I was trying to write my own put-pixel on (Gdk) pixbuf in Lisp. When I finally realized how I can operate on C pointers in CL, new obstacle came along - (gdk:pixbuf-get-pixels pb) returns me negative ...

Is there a common lisp package naming convention?

I have created some of my own user packages and have run into a name clash. In Java, the naming convention is to use your domain name in the package name: e.g. import com.example.somepackage;. Are ...

SOAP request from within an AutoLISP/AutoCAD macro

We have built a webservice for a client that uses AutoCAD. They have a macro that runs in AutoCAD that builds a SOAP request. But they have not figured out how to actually send() the soap request to ...

热门标签