Python syntax in Lisp and Scheme
Marco Antoniotti
marcoxa at cs.nyu.edu
Tue Oct 7 09:30:49 EDT 2003
David Eppstein wrote:
> In article <blsbpf$i9n$1 at newsreader2.netcologne.de>,
> Pascal Costanza <costanza at web.de> wrote:
>
>
>>I don't know a lot about Python, so here is a question. Is something
>>along the following lines possible in Python?
>>
>>(with-collectors (collect-pos collect-neg)
>> (do-file-lines (l some-file-name)
>> (if (some-property l)
>> (collect-pos l)
>> (collect-neg l))))
>>
>>
>>I actually needed something like this in some of my code...
>
>
> Not using simple generators afaik. The easiest way would probably be to
> append into two lists:
>
> collect_pos = []
> collect_neg = []
> for l in some_file_name:
^^^^^^^^^^^^^^
Please be precise. You are missing the definition of 'some_file_name'.
The CL macro can hide the fact that you are passing the iterator
either a string or a structured pathname or an iterator instance. In
Python you have to include the definition of 'some_file_name'.
In CL the following will work (assuming that the DO-FILE-LINES CL macro
is written correctly)
(let ((some-file-name "/tmp/foo.txt"))
(with-collectors (collect-pos collect-neg)
(do-file-lines (l some-file-name)
(if (some-property l)
(collect-pos l)
(collect-neg l)))))
In Pyhton
some_file_name = '/tmp/foo.txt'
collect_pos = []
collect_pos = []
for l in some_file_name:
will happily bind 'l' to the characters in '/tmp/foo.txt'.
Cheers
--
Marco
More information about the Python-list
mailing list