Google Groups Home
Help | Sign in
Message from discussion Python syntax in Lisp and Scheme
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Erann Gat  
View profile
 More options Oct 6 2003, 3:59 pm
Newsgroups: comp.lang.lisp, comp.lang.python, comp.lang.scheme, comp.lang.functional
From: my-first-name.my-last-n...@jpl.nasa.gov (Erann Gat)
Date: Mon, 06 Oct 2003 12:19:54 -0700
Local: Mon, Oct 6 2003 3:19 pm
Subject: Re: Python syntax in Lisp and Scheme
In article <eppstein-9700A3.10461306102...@news.service.uci.edu>, David

Eppstein <eppst...@ics.uci.edu> wrote:
> In article
> <my-first-name.my-last-name-0610030955090...@k-137-79-50-101.jpl.nasa.go
> v>,
>  my-first-name.my-last-n...@jpl.nasa.gov (Erann Gat) wrote:

> > > : Here's another example of what you can do with macros in Lisp:

> > > : (with-collector collect
> > > :   (do-file-lines (l some-file-name)
> > > :     (if (some-property l) (collect l))))

> > > : This returns a list of all the lines in a file that have some property.

> > > OK, that's _definitely_ just a filter: filter someproperty somefilename
> > > Perhaps throw in a fold if you are trying to abstract "collect".

> > The net effect is a filter, but again, you need to stop thinking about the
> > "what" and start thinking about the "how", otherwise, as I said, there's
> > no reason to use anything other than machine language.

> Answer 1: literal translation into Python.  The closest analogue of
> with-collector etc would be Python's simple generators (yield keyword)
> and do-with-file-lines is expressed in python with a for loop.  So:

> def lines_with_some_property(some_file_name):
>     for l in some_file_name:
>         if some_property(l):
>             yield l

You left out the with-collector part.

But it's true that my examples are less convincing given the existence of
yield (which I had forgotten about).  But the point is that in pre-yield
Python you were stuck until the langauge designers got around to adding
it.

I'll try to come up with a more convincing short example if I find some
free time today.

E.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google