From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Helmut Eller Newsgroups: gmane.emacs.help Subject: Re: lambda inside a let or letrec Date: Thu, 10 Jun 2010 09:22:33 +0200 Message-ID: References: <6b121cee-8a28-4e27-a733-40d22028e05d@i28g2000yqa.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1291830529 5252 80.91.229.12 (8 Dec 2010 17:48:49 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 8 Dec 2010 17:48:49 +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 Dec 08 18:48:44 2010 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.69) (envelope-from ) id 1PQO8C-0005BN-2T for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 18:48:44 +0100 Original-Received: from localhost ([127.0.0.1]:36461 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQO8B-0005Co-BO for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 12:48:43 -0500 Original-Path: usenet.stanford.edu!postnews.google.com!news2.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.kpnqwest.it!news.kpnqwest.it.POSTED!not-for-mail Original-NNTP-Posting-Date: Thu, 10 Jun 2010 02:22:33 -0500 Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:+SoORnl7mUCxvrbiy+qOCx4HjO0= Original-Lines: 61 X-Usenet-Provider: http://www.giganews.com Original-NNTP-Posting-Host: 212.46.181.9 Original-X-Trace: sv3-4iPsfs4sgMhFkZaN30TMR2DbXWzR4RFj/f/CkPsaxfxhi0u4idb4MtvtXQkb7j0aDbOBeChKEHpwNLy!qazn7c+yxCP96NnreniAsBPOrjweoThd+aPGR4w7ldQBjqBQa8qptIpTWj9U X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 Original-Xref: usenet.stanford.edu gnu.emacs.help:178793 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:75728 Archived-At: * bolega [2010-06-10 07:34+0200] writes: > My apologies in advance to comp.lang.scheme and comp.lang.lisp. > > I am trying to run a certain syntax inside emacs lisp. > > I know basically how let works > > (let (list of pairs of var value) (function)) > > This is like a lambda function call , only the order is different. > > But the novelty i saw reading a book on common lisp or scheme is this > and i failed to run in emacs. plz tell what modifications are needed > and i know they are different. > > ( (lambda (n) (+ 1 n)) 3) ;;; works in emacs > > (let > ((a (lambda (n) (+ 1 n))) (b 3)) (a b)) ;;; does NOT work in emacs > > basically we are trying to use / abuse the let in that in the pair we > define a equal to a lambda. Then another pair where a value of b is > defined. > > next, we want a to operate on b. > > Why does it fail ? The first element of a call like (FUN ARG0 ARG1 ...), that is FUN, is special. FUN must be one of: 1) be the name of function (like "+") 2) the name of a macro (like "save-excursion") 3) the name of a special form (like "let", or "while") 4) a lambda form (e.g ((lambda (x) (+ x x) 1))) So if you write the (a b) the evaluation rules for a are different as the rules for b. In your example "a" is a variable but not a function. In techical terms one would say that a is bound in the variable namespace but not in the function namespace. The simplest solution to call a variable is: (funcall a b) > The scheme/lisp book/paper where it was seen (forgot) used letrec. It was probably a Scheme book, because the rules are different in this regard in Scheme. In Scheme a call (FUN ARG0 ...) is essentially the same as (funcall FUN ARG0 ...) in Lisp > Can someone enlighten me how set! and let can be used to formulate > recursion when the let has no recursion built in it ? Well, in Emacs Lisp it's easy: (let ((fac (lambda (x) (if (zerop x) 1 (* x (funcall fac (1- x))))))) (funcall fac 10)) that works because Emacs uses dynamic scoping, so you don't need setq. Helmut