4

I am trying to implement Haskell-like high-order function in Elisp, using closures.

;;; -*- lexical-binding: t -*-
(defun foo (pair)
    (car pair))
(defun* .curry (fn)
    (lambda (x y &rest args) (apply fn (cons x y) args)))

((lambda (x y) (1+ x)) 2 3)
((lambda (&rest args) (apply (.curry #'foo) args)) 2 3)
(funcall (.curry #'foo) 2 3)
((.curry #'foo) 2 3)

Problem is that last line returns error Invalid function. So, it seems closure do not considered sane function. I still can use (.curry #'foo) in mapc, but not in hooks. Is it something I can do about it?

1
  • Rewrite .curry as a macro? That is idea! Thanks for all this information! Commented Apr 11, 2013 at 5:07

1 Answer 1

2

Your ((.curry #'foo) 2 3) is invalid in any Lisp I know of except Scheme (and Scheme derivatives such as Racket). The simplest code that illustrates the issue is as follows:

(defun f () (lambda ()))
(funcall (f)) ; tested in Emacs 23 and CLISP, works
((f)) ; tested in Emacs 23 and CLISP, results in an error
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.