From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: srinik001@hotmail.com Newsgroups: gmane.emacs.help Subject: Functions returning functions in Emacs Lisp Date: Tue, 15 Apr 2008 20:18:09 -0700 (PDT) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1208327814 13980 80.91.229.12 (16 Apr 2008 06:36:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 16 Apr 2008 06:36:54 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Apr 16 08:37:25 2008 connect(): Connection refused Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Jm1Bk-0004ta-VI for geh-help-gnu-emacs@m.gmane.org; Wed, 16 Apr 2008 08:32:13 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jm1B6-0006B1-7p for geh-help-gnu-emacs@m.gmane.org; Wed, 16 Apr 2008 02:31:32 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!l28g2000prd.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 40 Original-NNTP-Posting-Host: 24.6.229.192 Original-X-Trace: posting.google.com 1208315889 5093 127.0.0.1 (16 Apr 2008 03:18:09 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 16 Apr 2008 03:18:09 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: l28g2000prd.googlegroups.com; posting-host=24.6.229.192; posting-account=80yX_goAAADR1ljaDcvuAw9eDZS-8Z3p User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13,gzip(gfe),gzip(gfe) Original-Xref: shelby.stanford.edu gnu.emacs.help:157956 X-Mailman-Approved-At: Wed, 16 Apr 2008 02:31:14 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:53324 Archived-At: Hi, I am trying to learn Emacs Lisp. I know a bit of (Common) Lisp and was trying the following on Emacs. This is to define a function called derivative, which returns as its result a function which is the derivative of the argument function fn, when the numerical calculation is done over delta. So I did the following. (defun derivative (fn delta) #'(lambda(x) (/ (- (funcall fn (+ x delta)) (funcall fn x)) delta))) --> this seemed to work (i.e. no error on C-x C-e) (setq c (derivative #'sin 0.001)) --> this seemed to work (again, no error on evaluation) (funcall c (/ 3.1415 2)) --> this threw up an error. The error is the following: Debugger entered--Lisp error: (void-variable fn) (funcall fn (+ x delta)) (- (funcall fn (+ x delta)) (funcall fn x)) (/ (- (funcall fn ...) (funcall fn x)) delta) (lambda (x) (/ (- ... ...) delta))(1.57075) funcall((lambda (x) (/ (- ... ...) delta)) 1.57075) eval((funcall c (/ 3.1415 2))) eval-last-sexp-1(nil) eval-last-sexp(nil) call-interactively(eval-last-sexp) I tried lambda expressions on mapcar, and it seemed to work on Emacs the way it does in Common Lisp. Could someone please tell me if I am doing something wrong vis-a-vis Emacs, or if Emacs does not support this? Thanks. Regards, SK