Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Nested mapcar* application and possibly some variation of Y combinator

Path: g2news1.google.com!postnews.google.com!o9g2000vbo.googlegroups.com!not-for-mail
From: Swami Tota Ram Shankar <tota_...@india.com>
Newsgroups: gnu.emacs.help,comp.lang.lisp,comp.emacs,gnu.emacs,comp.lang.scheme
Subject: Re: Nested mapcar* application and possibly some variation of Y combinator
Date: Fri, 26 Aug 2011 01:18:07 -0700 (PDT)
Organization: http://groups.google.com
Lines: 51
Message-ID: <037331fe-2032-4e44-a930-ffd1867a1109@o9g2000vbo.googlegroups.com>
References: <2caa0c6e-9f98-446b-b5d5-3d09535efc13@f1g2000pre.googlegroups.com>
 <8762lm9h8f.fsf@fencepost.gnu.org> <m3bovda5pb.fsf@barry_fishman.acm.org>
 <m37h61a432.fsf@barry_fishman.acm.org> <m3ippkbqh6.fsf@barry_fishman.acm.org> <91851b9e-f750-4de8-be04-6e620ce254f9@en1g2000vbb.googlegroups.com>
NNTP-Posting-Host: 75.28.154.86
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1314346687 13251 127.0.0.1 (26 Aug 2011 08:18:07 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 26 Aug 2011 08:18:07 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: o9g2000vbo.googlegroups.com; posting-host=75.28.154.86; posting-account=dlefMQoAAABzowG6c0cULB8igkwPchCd
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2)
 Gecko/20100115 Firefox/3.6,gzip(gfe)

On Aug 26, 12:24=A0am, Swami Tota Ram Shankar <tota_...@india.com>
wrote:
> On Aug 26, 12:07=A0am, Barry Fishman <barry_fish...@acm.org> wrote:
>
>
>
> > On 2011-08-25 11:44:17 EDT, Barry Fishman wrote:
>
> > > On 2011-08-25 11:09:20 EDT, Barry Fishman wrote:
> > > And maybe, since this function is only useful processing trees:
>
> > > (defun maptree (fun tree)
> > > =A0 (lexical-let ((sfun nil)
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 (afun fun))
> > > =A0 =A0 (setq sfun #'(lambda (x)
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(if (sequencep x)
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(mapcar sfun x)
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(funcall afun x))))
> > > =A0 =A0 (funcall sfun tree)))
>
> > I thought I was done with this, but at 3 AM I woke up thinking,
> > "This no longer requires a closure", =A0so it can be simplified to:
>
> This means that you dont have a strong enough intuition about the
> lexical closures. I studied it a year ago in connection with
> javascript. Javascript has scope chaining. In C you can create a local
> scope using {}, but this is not the case in javascript. All the
> variables from the outside are visible inside unless over-ridden by a
> local redefinition. This is called scope chaining. In JS, lexical
> scoping means, that functions create their environment (scope) ie
> symbol-value pairs in the table when they are defined and not when
> they are executed. I guess, I need someone to discuss with slightly
> different elementary series of examples to make it clear and crisp. It
> shall help the author also.

useful link on lexical closures

http://c2.com/cgi/wiki?LexicalClosure

>
> > (defun maptree (func tree)
> > =A0 (let ((sfunc nil))
> > =A0 =A0 (setq sfunc (lambda (x)
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (if (sequencep x)
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (mapcar sfunc x)
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (funcall func x))))
> > =A0 =A0 (funcall sfunc tree)))
>
> > --
> > Barry Fishman