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
reading file to list
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 43 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
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
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Drew Krause  
View profile  
 More options Jan 16 2009, 3:29 pm
Newsgroups: comp.lang.lisp
From: Drew Krause <drkra...@mindspring.com>
Date: Fri, 16 Jan 2009 14:29:37 -0600
Local: Fri, Jan 16 2009 3:29 pm
Subject: reading file to list
OK, I want to create a nested list in Lisp (always of only integers) from a
text file, such that each line in the text file would be represented as a
sublist in the 'imported' list.

Like this:

(defun make-list-from-text filename)
        ....

"blob.txt" is
3 10 2
4 1
11 18

so..
(make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18))

Any help would be greatly appreciated!

Thanks, DK


 
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.
w_a_x_...@yahoo.com  
View profile  
 More options Jan 16 2009, 4:16 pm
Newsgroups: comp.lang.lisp
From: w_a_x_...@yahoo.com
Date: Fri, 16 Jan 2009 13:16:13 -0800 (PST)
Local: Fri, Jan 16 2009 4:16 pm
Subject: Re: reading file to list
On Jan 16, 2:29 pm, Drew Krause <drkra...@mindspring.com> wrote:

Ruby:

IO.readlines("blob.txt").map{|line| line.split }


 
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.
blandest  
View profile  
 More options Jan 16 2009, 5:05 pm
Newsgroups: comp.lang.lisp
From: blandest <Valentin.Ba...@gmail.com>
Date: Fri, 16 Jan 2009 14:05:24 -0800 (PST)
Local: Fri, Jan 16 2009 5:05 pm
Subject: Re: reading file to list
On Jan 16, 10:29 pm, Drew Krause <drkra...@mindspring.com> wrote:

(defun make-list-from-file (filename)
  (with-open-file (in filename)
    (loop for line = (read-line in nil nil)
       while line
       collect (read-from-string (concatenate 'string "(" line
")")))))
CL-USER> (make-list-from-file "tmp")
((3 10 2) (4 1) (11 18))

 
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.
Thomas A. Russ  
View profile  
 More options Jan 16 2009, 5:17 pm
Newsgroups: comp.lang.lisp
From: t...@sevak.isi.edu (Thomas A. Russ)
Date: 16 Jan 2009 14:17:17 -0800
Local: Fri, Jan 16 2009 5:17 pm
Subject: Re: reading file to list

What have you got so far?

--
Thomas A. Russ,  USC/Information Sciences Institute


 
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.
Ross Lonstein  
View profile  
 More options Jan 16 2009, 8:08 pm
Newsgroups: comp.lang.lisp
From: Ross Lonstein <rlonst...@pobox.com>
Date: Fri, 16 Jan 2009 20:08:02 -0500
Local: Fri, Jan 16 2009 8:08 pm
Subject: Re: reading file to list
Here's my take on it....

(defun split (delim line)
  "Return a list of subsequences separated by a one character delimiter, delim itself is not returned"
  (loop :for mark = 0 :then (1+ point)
        :for point = (position delim line :start mark)
        :collect (subseq line mark point)
        :while point))

(defun make-list-from-text (fn)
  "assemble list of lists of numbers parsed from file, posed by drkrause on cll 2009-01-16"
  (with-open-file (stream fn)
    (loop :for line = (read-line stream nil nil)
          :while line
          :collect (mapcar #'parse-integer (split #\Space line)))))

CL-USER> (make-list-from-file "/tmp/blob.txt")
((3 10 2) (4 1) (11 18))

- Ross


 
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.
joswig@corporate-world.li sp.de  
View profile  
 More options Jan 16 2009, 10:36 pm
Newsgroups: comp.lang.lisp
From: "jos...@corporate-world.lisp.de" <jos...@corporate-world.lisp.de>
Date: Fri, 16 Jan 2009 19:36:22 -0800 (PST)
Local: Fri, Jan 16 2009 10:36 pm
Subject: Re: reading file to list
On Jan 16, 11:17 pm, t...@sevak.isi.edu (Thomas A. Russ) wrote:

Let's try a more exotic 'solution':

On Jan 16, 10:16 pm, w_a_x_...@yahoo.com wrote:

Why not try something new? No need to allocate lines, split the and
then parse integer from the parts.

(defun read-lines (stream &aux result list (rt (copy-readtable)))
  (flet ((newline-reader (stream char)
           (declare (ignore stream char))
           (when list
             (push (nreverse list) result)
             (setf list nil))
           nil))
    (set-macro-character #\newline #'newline-reader nil rt)
    (let ((*readtable* rt))
      (loop for item = (read stream nil stream)
            until (eq item stream)
            when item do (push item list)
            finally (when list (push (nreverse list) result)))
      (nreverse result))))


 
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.
William James  
View profile  
 More options Jan 17 2009, 12:45 am
Newsgroups: comp.lang.lisp
From: "William James" <w_a_x_...@yahoo.com>
Date: 17 Jan 2009 05:45:39 GMT
Local: Sat, Jan 17 2009 12:45 am
Subject: Re: reading file to list

If you want to convert the strings to integers:

IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }}


 
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.
budden  
View profile  
 More options Jan 17 2009, 7:02 am
Newsgroups: comp.lang.lisp
From: budden <budden-l...@mail.ru>
Date: Sat, 17 Jan 2009 04:02:32 -0800 (PST)
Local: Sat, Jan 17 2009 7:02 am
Subject: Re: reading file to list
Hi!
 There are multiple split-sequence library implementations, no need to
write one's own. E.g.

http://www.cliki.net/SPLIT-SEQUENCE

 I wonder why everyone suggest one's own split-sequence function
instead of pointing OP to the existing library. There are more
interesting tasks for lisp coding that reinventing a wheel.


 
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.
Ross Lonstein  
View profile  
 More options Jan 17 2009, 9:41 am
Newsgroups: comp.lang.lisp
From: Ross Lonstein <rlonst...@pobox.com>
Date: Sat, 17 Jan 2009 09:41:48 -0500
Local: Sat, Jan 17 2009 9:41 am
Subject: Re: reading file to list
budden <budden-l...@mail.ru> writes:

    [snip]

> I wonder why everyone suggest one's own split-sequence function
> instead of pointing OP to the existing library.

My thinking was that if the OP can't manage writing this particular bit
of code, they probably haven't worked out ASDF yet. I expected that
someone would point it out.

> There are more interesting tasks for lisp coding that reinventing a
> wheel.

Compared to SPLIT-SEQUENCE, a caster.

And answering on c.l.l. is already a form of recreation (pun intended)
;)

- Ross


 
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.
Xah Lee  
View profile  
 More options Jan 17 2009, 12:16 pm
Newsgroups: comp.lang.lisp, comp.lang.scheme, comp.lang.functional, comp.lang.python, comp.lang.ruby
From: Xah Lee <xah...@gmail.com>
Date: Sat, 17 Jan 2009 09:16:07 -0800 (PST)
Local: Sat, Jan 17 2009 12:16 pm
Subject: Re: reading file to list
comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp. lang.ruby

Here's a interesting toy problem posted by Drew Krause to
comp.lang.lisp:

------------------------
On Jan 16, 2:29 pm, Drew Krause wrote [paraphrased a bit]:

OK, I want to create a nested list in Lisp (always of only integers)
from a text file, such that each line in the text file would be
represented as a sublist in the 'imported' list.

example of a file's content

3 10 2
4 1
11 18

example of programing behavior
(make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18))

-----------------
Here's a emacs lisp version:

(defun read-lines (file)
  "Return a list of lines in FILE."
  (with-temp-buffer
    (insert-file-contents file)
    (split-string
     (buffer-substring-no-properties 1 (point-max)) "\n" t)
    )
  )

(defvar mylist '() "result list" )
(setq mylist '()) ; init in case eval'd again

(mapc
 (lambda (x) (setq mylist
                   (cons (split-string x " ") mylist )) )
 (read-lines "xxblob.txt")
 )

The above coding style is a typical maintainable elisp.

In a show-off context, it can be reduced to by about 50%, but still
far verbose than ruby or say perl (which is 1 or 2 lines. (python
would be 3 or 5)).

Note that the result element is string, not numbers. There's no easy
way to convert them on the fly. 3 or so more lines will be needed to
do that.

The “read-lines” function really should be a built-in part of elisp.
It is not so mostly because emacs people have drawn themselves into a
elitist corner, closing off to the outside world. (i am sending a
suggestion to the official emacs dev list on adding read-line now.)

-----------------

w_a_x_...@yahoo.com gave a ruby solution:

  IO.readlines("blob.txt").map{|line| line.split }

augumented by Jilliam James for result to be numbers:

  IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }}

Very beautiful.

-------------------

That's really the beauty of Ruby.

This problem and ruby code illustrates 2 fundamental problems of lisp,
namely, the cons problem, and the nested syntax pain. Both of which
are practically unfixable.

The lisp's cons fundamentally makes nested list a pain to work with.
Lisp's nested syntax makes functional sequencing cumbersome.

In the ruby code, its post-fix sequential notation (as a side effect
of its OOP notation) brings out the beauty of functional sequencing
paradigm (sometimes known as functional chain, sequencing, filtering,
unix piping).

its list, like all modern high level langs such as perl, php, python,
javascript, don't have the lisp's cons problem. The cons destroys the
usability of lists up-front, untill you have some at least 2 full-time
years of coding lisp to utilize cons properly. (and even after that,
it is still a pain to work with, and all you gain is a bit of speed
optimization in rare cases that requires largish data, most of which
has better solutions such as a database.)

Both of these problems i've published articles on.

For more detail on the cons problem, see
the section “The Cons Business” at

• Fundamental Problems of Lisp
  http://xahlee.org/UnixResource_dir/writ/lisp_problems.html

For more detail on the nested syntax problem for function chaining,
see
the section “How Purely Nested Notation Limits The Language's Utility”
at:

• The Concepts and Confusions of Prefix, Infix, Postfix and Fully
Nested Notations
  http://xahlee.org/UnixResource_dir/writ/notations.html

  Xah
http://xahlee.org/



 
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.
Xah Lee  
View profile  
 More options Jan 17 2009, 12:34 pm
Newsgroups: comp.lang.lisp, comp.lang.scheme, comp.lang.functional, comp.lang.python, comp.lang.ruby
From: Xah Lee <xah...@gmail.com>
Date: Sat, 17 Jan 2009 09:34:39 -0800 (PST)
Local: Sat, Jan 17 2009 12:34 pm
Subject: Re: reading file to list
On Jan 17, 9:16 am, Xah Lee <xah...@gmail.com> wrote:

> Here's a interesting toy problem posted by Drew Krause to
> comp.lang.lisp:
> ...

The code in my previous elisp code got a bump. It should be:

(defun read-lines (file)
  "Return a list of lines in FILE."
  (with-temp-buffer
    (insert-file-contents file)
    (split-string
     (buffer-substring-no-properties 1 (point-max)) "\n" t)
    )
  )

(mapcar
 (lambda (x) (split-string x " ") )
 (read-lines "xxblob.txt")
 )

The article is now archived at:

• A Ruby Illustration of Lisp Problems
  http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html

  Xah
http://xahlee.org/



 
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.
Xah Lee  
View profile  
 More options Jan 17 2009, 12:55 pm
Newsgroups: comp.lang.lisp, comp.lang.scheme, comp.lang.functional, comp.lang.python, comp.lang.ruby
From: Xah Lee <xah...@gmail.com>
Date: Sat, 17 Jan 2009 09:55:43 -0800 (PST)
Local: Sat, Jan 17 2009 12:55 pm
Subject: Re: reading file to list
On Jan 17, 9:34 am, Xah Lee <xah...@gmail.com> wrote:

> The code in my previous elisp code got a bump. It should be:
> ...
> • A Ruby Illustration of Lisp Problems
>  http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html

Sorry again. More correction:

(defun read-lines (file)
  "Return a list of lines in FILE."
  (with-temp-buffer
    (insert-file-contents file)
    (split-string
     (buffer-substring-no-properties 1 (point-max)) "\n" t)
    )
  )

(mapcar
 (lambda (x)
   (mapcar
    (lambda (y) (string-to-number y) )
    (split-string x " ")
    )
   )
 (read-lines "xxblob.txt")
 )

this is last post of correction.

  Xah
http://xahlee.org/



 
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.
André Thieme  
View profile  
 More options Jan 17 2009, 3:30 pm
Newsgroups: comp.lang.lisp, comp.lang.scheme, comp.lang.functional, comp.lang.python, comp.lang.ruby
From: André Thieme <address.good.until.2009.may...@justmail.de>
Date: Sat, 17 Jan 2009 21:30:49 +0100
Local: Sat, Jan 17 2009 3:30 pm
Subject: Re: reading file to list
Xah Lee schrieb:

*Of course* Xah is wrong, as always.
Who would expect anything else?
In the Lisp style Clojure for example one does exactly the same as
Jillian James (JJ) did in Ruby:
(map #(map (fn [s] (Integer/parseInt s)) (.split % "\\s")) (line-seq
(reader "blob.txt")))

This is slightly longer, simply because the functions have longer names.
Integer/parseInt  vs  to_i

Also the function split takes a regexp, so I have to add the "\\s" here.
I don’t know though if Jillians version also handles any kind of
whitespac per line.
And the last thing is, that the function reader returns a BufferedReader.
So in general this is more valuable in real programs as opposed to one-
line scripts. If we combine line-seq and reader into readline and apply
the two other changes we would say:
(map #(map (fn [s] (to_i s)) (.split %)) (readlines "blob.txt"))
vs
IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }}

So, obviously Xah is far away from any reality.
It took him hours of his life to write up all his ideas about Lisp.
Sad to see that all that time was wasted. All of it was wrong.
Poor Xah :(

And btw, Drew Krause is just a Lisp newbie. No Lisper would ever store
data for his programs in the format
3 10 2
4 1
11 18

but instead as
(3 10 2)
(4 1)
(11 18)

And then read it back into the program with:
(map read-string (line-seq (reader "blob.txt")))

André
--


 
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.
K Livingston  
View profile  
 More options Jan 17 2009, 7:25 pm
Newsgroups: comp.lang.lisp
From: K Livingston <kevinlivingston.pub...@gmail.com>
Date: Sat, 17 Jan 2009 16:25:50 -0800 (PST)
Local: Sat, Jan 17 2009 7:25 pm
Subject: Re: reading file to list
On Jan 16, 9:36 pm, "jos...@corporate-world.lisp.de" <jos...@corporate-

I agree, no need to read and re-read everything, like all the split
people want.  The lisp reader can be made to take care of this so
easily.  But why does everyone want to traverse the data at least 2
times.  (in the above case 3, but the last push/nreverse could be
trivially changed to a collect to avoid that)

CommonLisp give us READ-DELIMITED-LIST - we don't need to define it,
or bring in a package to do it.  Lisp readers are highly optimized,
let's let it do the work for us.

Now unfortunately, read-delimited-list reads right though whitespace
so we can't trivially say
(read-delimited-list #\newline stream)
as it won't see the newline like we want it to.

But that's easy enough to fix, let's just change the readtable
temporarily to think that newline is a terminating, non-constituent
character.  What else is one of those?  right-parenthesis will do, so
let's just make it behave like that temporarily.  And since we don't
want to do this over and over and over again, let just store it in a
variable (it could be in a closure around the function too if you
wanted to be fancier, and if you didn't ever need this readtable for
anything else, but... that's for another day).

(defvar *newline-not-white-readtable*
  (let ((*readtable* (copy-readtable nil)))
    (set-syntax-from-char #\newline #\))
    *readtable*))

Ok now we have a readtable, lets make a function to read a single
line...

Inside the function, we'll temporarily switch to our new readtable, so
that we can stop when we see a newline.  Also, since read-delimited-
list doesn't fail gracefully, we will have to catch the EOF condition
it generates.  (There might be an easier/shorter way to do that, but
this works, and just returns the stream when EOF is encountered. Why
can't it return nil?  OP didn't say what should happen with an empty
line, e.g. just a newline character, so assuming that is valid, and
since we have to look for something anyway, it may as well be the
stream.)

(defun read-list-insides (s)
  (let ((*readtable* *newline-not-white-readtable*))
    (handler-bind
        ((end-of-file #'(lambda (c)
                          (declare (ignore c))
                          (return-from read-list-insides s))))
      (read-delimited-list #\newline s))))

Now to get all the lines in one list.

(with-open-file (s *data-file*)
  (loop for item = (read-list-insides s)
    until (eq item s)
    collect item))

There it is - one pass, and barely any code.

Questions for the reader/OP:

1. if you don't really want to collect all the values/lines but just
operate on them one at a time, how could you change the loop call, or
what else could you do.

2. if you do need to collect them all, is it worth moving the loop
inside of the let for the readtable and the handler-bind.  Does that
buy you anything?

3. what happens if there isn't an newline at the end of the file / at
the end of the last sequence of numbers?  does this code expect there
to be one?

good luck,
Kevin


 
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.
Xah Lee  
View profile  
 More options Jan 17 2009, 7:30 pm
Newsgroups: comp.lang.lisp, comp.lang.scheme, comp.lang.functional, comp.lang.python, comp.lang.ruby
From: Xah Lee <xah...@gmail.com>
Date: Sat, 17 Jan 2009 16:30:24 -0800 (PST)
Local: Sat, Jan 17 2009 7:30 pm
Subject: Re: reading file to list

Xah Lee wrote:
> • A Ruby Illustration of Lisp Problems
>  http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html

On Jan 17, 12:30 pm, André Thieme <address.good.until.

2009.may...@justmail.de> wrote:
> In the Lisp style Clojure for example one does exactly the same as
> Jillian James (JJ) did in Ruby:
> (map #(map (fn [s] (Integer/parseInt s)) (.split % "\\s")) (line-seq
> (reader "blob.txt")))

Note that you have nested map. This is a problem of function chaning
as i detailed.

The other problem of cons, is commonly seen. Just about every week, we
see some perhaps beginning lisper asking how to do various trivial
list
manipulation problem, which you don't see such question or frequency
in any of modern high level lang forms.

The frequently asked list manipulation question we see include how to
append, prepend, or anything involving nested list such as
partitioning, reordering sublists, getting leaves, interpretation of
leaves, etc. This is caused by the cons.

associated lisp problem compound the issue. Namely, the not exactly
regular syntax, and the eval model of sometimes symbol sometimes
uneval'd symbol, e.g. “'(...)”, “`(...,@ ...)” things.

The clojure example you gave above, apparently inherited the irregular
syntax problem. (you see the #, [], % things, which is breaks the
lisp's sexp idea) Also, all modern lisp basically all get fucked up by
inheriting the cons (e.g. clojure, NewLisp, Arc lisp, Liskell). Often,
they change the semantic a bit apparently as a mesaure towards solving
the cons problem. (and Qi Lisp creates a huge bag of ad hoc, extremely
ugly, syntax soup)

Advice: if you are creating a lispy lang, two things:

• stick to a _pure_ nested syntax, no exception whatsoever. (e.g. no
more ` ' # % shits) If you want, add a transparent layer on top to
support arbitrary algeraic notation. (e.g. look at Mathematica, CGOL)

• get rid of the cons. (you can still implement the so-called linked
list, but no where it should be shown to the programer)

Further readings:

• Fundamental Problems of Lisp
  http://xahlee.org/UnixResource_dir/writ/lisp_problems.html

  Xah
http://xahlee.org/



 
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.
K Livingston  
View profile  
 More options Jan 17 2009, 7:45 pm
Newsgroups: comp.lang.lisp
From: K Livingston <kevinlivingston.pub...@gmail.com>
Date: Sat, 17 Jan 2009 16:45:53 -0800 (PST)
Local: Sat, Jan 17 2009 7:45 pm
Subject: Re: reading file to list
On Jan 17, 2:30 pm, André Thieme <address.good.until.

2009.may...@justmail.de> wrote:
> And btw, Drew Krause is just a Lisp newbie. No Lisper would ever store
> data for his programs in the format
> 3 10 2
> 4 1
> 11 18

> but instead as
> (3 10 2)
> (4 1)
> (11 18)

Maybe he doesn't get to designate the format he has to read?

But really, why wouldn't a Lisper consider that format?  If it really
is just sequences of numbers you're just adding a lot of funny
parenthesis in your data file, making it larger for no good reason,
when you already have delimiters.

Assuming he does get to pick the format and it is just numbers, why
not just store them as sequences of bytes/integers etc. instead of
text?

All that said, with usual combined goals of laziness (for the effort
of the programmer) and the desire to have something (mostly) human
readable/editable, I usually go with the format you are advocating.

But, I think people are selling lisp short / forgetting the tools they
have, when they assume or promote that there needs to be parenthesis
in a data file for lisp code to read it easily or efficiently.

at least, that's my two cents,
Kevin


 
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.
André Thieme  
View profile  
 More options Jan 17 2009, 8:07 pm
Newsgroups: comp.lang.lisp
From: André Thieme <address.good.until.2009.may...@justmail.de>
Date: Sun, 18 Jan 2009 02:07:58 +0100
Local: Sat, Jan 17 2009 8:07 pm
Subject: Re: reading file to list
K Livingston schrieb:

If it were really like that, if those parenthesis would be there for
no good reason, then it would make no sense, I agree.
But they are there for a reason.
Their presence makes it easier to read them back.
No splitting needed, no conversion to integers, not two mappings.
And writing out the data is also trivial.
For small amounts of data that’s all we need. If we want bigger
datasets there is always a DB system waiting.

André
--


 
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.
joswig@corporate-world.li sp.de  
View profile  
 More options Jan 17 2009, 8:14 pm
Newsgroups: comp.lang.lisp
From: "jos...@corporate-world.lisp.de" <jos...@corporate-world.lisp.de>
Date: Sat, 17 Jan 2009 17:14:23 -0800 (PST)
Local: Sat, Jan 17 2009 8:14 pm
Subject: Re: reading file to list
On Jan 18, 1:45 am, K Livingston <kevinlivingston.pub...@gmail.com>
wrote:

If I would make it easy for Lisp, then I would make it just one list:

((3 10 2)(4 1)(11 18))

or

((3 10 2)
(4 1)
(11 18))

or

(
(3 10 2)
(4 1)
(11 18)
)

Then I would use just one READ.


 
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.
André Thieme  
View profile  
 More options Jan 17 2009, 8:25 pm
Newsgroups: comp.lang.lisp, comp.lang.scheme, comp.lang.functional, comp.lang.python, comp.lang.ruby
From: André Thieme <address.good.until.2009.may...@justmail.de>
Date: Sun, 18 Jan 2009 02:25:00 +0100
Subject: Re: reading file to list
Xah Lee schrieb:

Yes, Jillian also has nested maps:
IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }}

> The other problem of cons, is commonly seen. Just about every week, we
> see some perhaps beginning lisper asking how to do various trivial
> list
> manipulation problem, which you don't see such question or frequency
> in any of modern high level lang forms.

You see questions about trivial problems every week in all forums about
programming languages.
It has nothing to do with conses. Wrong road.

> The frequently asked list manipulation question we see include how to
> append, prepend, or anything involving nested list such as
> partitioning, reordering sublists, getting leaves, interpretation of
> leaves, etc. This is caused by the cons.

Yes, same with all containers in all programming languages.

> The clojure example you gave above, apparently inherited the irregular
> syntax problem. (you see the #, [], % things, which is breaks the
> lisp's sexp idea)

My code used 8 “mysterious symbols”:
(  )  #  [  ]  .  "  %

The Ruby version had these 7:
(  )  |  {  }  .  "

And of course, neither in Ruby nor Clojure they break any idea.

> Also, all modern lisp basically all get fucked up by
> inheriting the cons (e.g. clojure, NewLisp, Arc lisp, Liskell). Often,
> they change the semantic a bit apparently as a mesaure towards solving
> the cons problem. (and Qi Lisp creates a huge bag of ad hoc, extremely
> ugly, syntax soup)

Funny.
What you write is an english text with words that most people can
understand.
You trick them into thinking that it actually makes sense what you say.
It is so technical, that a random would believe it.
But what you really say is about as meaningful as saying that it is
impossible to write good programs in Python, because it adds whitespace
to its syntax.

> • Fundamental Problems of Lisp
>   http://xahlee.org/UnixResource_dir/writ/lisp_problems.html

You wasted lots of your time. Or was this maybe generated by a bot?
Maybe http://pdos.csail.mit.edu/scigen/ or something like that?
I also found this paper that you wrote:
http://apps.pdos.lcs.mit.edu/scicache/184/scimakelatex.7076.Xah+Lee.html
Another crap posting of you. But a random person might be impressed.

André
--


 
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.
Xah Lee  
View profile  
 More options Jan 17 2009, 10:07 pm
Newsgroups: comp.lang.lisp, comp.lang.scheme, comp.lang.functional, comp.lang.python, comp.lang.ruby
From: Xah Lee <xah...@gmail.com>
Date: Sat, 17 Jan 2009 19:07:24 -0800 (PST)
Local: Sat, Jan 17 2009 10:07 pm
Subject: Re: reading file to list

a idiot  wrote:
> Yes, Jillian also has nested maps:

the issue here, is not about whether Ruby has nested map or not. It is
about illustrating a lisp problem. In particular, nested syntax
impedes the functional programing paradigm of function chaining.

• A Ruby Illustration of Lisp Problems
  http://xahlee.org/UnixResource_dir/writ/lisp_problems_by_ruby.html

a idiot wrote:
> My code used 8 “mysterious symbols”:
> (  )  #  [  ]  .  "  %

> The Ruby version had these 7:
> (  )  |  {  }  .  "

The issue here is not about which lang employs more special chars. The
issue is about the irregularities in lisp's syntax damaged its power
of its otherwise believed superior regular syntax.

• Fundamental Problems of Lisp
  http://xahlee.org/UnixResource_dir/writ/lisp_problems.html

  Xah
http://xahlee.org/



 
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.
K Livingston  
View profile  
 More options Jan 17 2009, 10:10 pm
Newsgroups: comp.lang.lisp
From: K Livingston <kevinlivingston.pub...@gmail.com>
Date: Sat, 17 Jan 2009 19:10:23 -0800 (PST)
Local: Sat, Jan 17 2009 10:10 pm
Subject: Re: reading file to list
On Jan 17, 7:07 pm, André Thieme <address.good.until.

The read-delimited-list solution above works in a single pass and is
not hindered in the slightest by the absence of parentheses.  (and
it's only a few lines of code)

> And writing out the data is also trivial.

for the data format above mapping
(format stream "~{~S~^ ~}~%" list-of-numbers)
seems pretty trivial.

or if you really want it in one line
(format stream "~:{~@{~S~^ ~}~%~}" list-of-list-of-numbers)

Anyway, all I've been trying to point out is that the absence or
presence of parentheses has pretty much no bearing on ones ability to
read, manipulate, or print data.  (The belief that it does comes up
often.)  For the most part any straightforward data format is as
trivial as any other to do whatever you want with.  The lisp reader by
default reads s-expressions, but that doesn't mean that's all you can
input in lisp.  A few tweaks here or there to the reader covers most
of the cases I've ever seen.  CommonLisp gives you a lot of power by
exposing all these tools to you, and I, for one, would rather go back
to my toolbox and pick up my screwdriver, than sit there hammer in
hand and say "why are all these screws in my way."

-Kevin


 
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.
Xah Lee  
View profile  
 More options Jan 18 2009, 3:31 am
Newsgroups: comp.lang.python, comp.lang.ruby, comp.lang.lisp
From: Xah Lee <xah...@gmail.com>
Date: Sun, 18 Jan 2009 00:31:15 -0800 (PST)
Local: Sun, Jan 18 2009 3:31 am
Subject: Re: reading file to list
On Jan 17, 10:25 am, Tino Wildenhain <t...@wildenhain.de> wrote:

> > [[int(x) for x in line.split()] for line in open("blob.txt")]

Nice (python code).

Few comments:

• the above code is borderline of atypical. e.g. it is not a average
python code would produce or one'd seen in corporate python code.

• voodoo like the above makes me dislike python. To me, the one
advantage of python is its clarity enforced by its syntax.
Specifically, the forced indendation and quite simple semantics.
However, the way i've seen Guido's propensities and how python 3 is
moving to, it is becoming more mumbo jumbo of computer sciency OOP
jargons with syntax soup. (with iterators, enumerators, list
comprehension... shits forced upon the users)

The above line illustrate well the ad hoc syntax soup nature python is
moving into.

Further readings:

• Perl-Python Tutorial: List Comprehension
  http://xahlee.org/perl-python/list_comprehension.html

• Lambda in Python 3000
  http://xahlee.org/perl-python/python_3000.html

  Xah
http://xahlee.org/



 
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.
Rainer Joswig  
View profile  
 More options Jan 18 2009, 4:39 am
Newsgroups: comp.lang.lisp
From: Rainer Joswig <jos...@lisp.de>
Date: Sun, 18 Jan 2009 10:39:39 +0100
Local: Sun, Jan 18 2009 4:39 am
Subject: Re: reading file to list
In article
<3e5f02cb-2a50-4013-adaa-03dd06f58...@q30g2000prq.googlegroups.com>,
 K Livingston <kevinlivingston.pub...@gmail.com> wrote:

...

> CommonLisp give us READ-DELIMITED-LIST - we don't need to define it,
> or bring in a package to do it.  Lisp readers are highly optimized,
> let's let it do the work for us.

...

> 3. what happens if there isn't an newline at the end of the file / at
> the end of the last sequence of numbers?  does this code expect there
> to be one?

I thought about the read-delimited-list version, too.
But it does not return a list when it sees an
eof during read. So a line with numbers with
no newline at the end can't be read with it.

It might (?) be useful to have another version
of read-delimited list, where the end of the list could
be determined by other factors: amount of
items read, sequence as end marker, eof, eol, predicate
on reading an item ... It might even have a filter than does
include only those elements that pass a filter.

Left as an programming exercise. ;-)

--
http://lispm.dyndns.org/


 
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.
William James  
View profile  
 More options Jan 18 2009, 5:53 pm
Newsgroups: comp.lang.lisp
From: "William James" <w_a_x_...@yahoo.com>
Date: 18 Jan 2009 22:53:59 GMT
Local: Sun, Jan 18 2009 5:53 pm
Subject: Re: reading file to list

In other words, don't try to do anything in Lisp that isn't trivial.
The data has to be changed to suit Lisp; the Lisp program can't be
changed to suit the data.

> For small amounts of data that’s all we need. If we want bigger
> datasets there is always a DB system waiting.

For non-trivial tasks, don't attempt to use Lisp.  It's too CLumsy.
Use a database.

 
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.
William James  
View profile  
 More options Jan 18 2009, 6:29 pm
Newsgroups: comp.lang.lisp, comp.lang.scheme, comp.lang.functional, comp.lang.python, comp.lang.ruby
Followup-To: comp.lang.lisp
From: "William James" <w_a_x_...@yahoo.com>
Date: 18 Jan 2009 23:29:57 GMT
Local: Sun, Jan 18 2009 6:29 pm
Subject: Re: reading file to list

That fails when numbers are separated by more than one space.
And what about leading or trailing space?

> This is slightly longer, simply because the functions have longer
> names.  Integer/parseInt  vs  to_i

> Also the function split takes a regexp, so I have to add the "\\s"
> here.  I don’t know though if Jillians version also handles any
> kind of whitespac per line.

irb(main):003:0> puts "  foo   \t   bar  "
  foo              bar
=> nil
irb(main):004:0> "  foo   \t   bar  ".split
=> ["foo", "bar"]
irb(main):005:0> "foo...bar?-!hoo".split /\W+/
=> ["foo", "bar", "hoo"]

> And the last thing is, that the function reader returns a
> BufferedReader.  So in general this is more valuable in real programs
> as opposed to one- line scripts. If we combine line-seq and reader
> into readline and apply the two other changes we would say:
> (map #(map (fn [s] (to_i s)) (.split %)) (readlines "blob.txt"))

That is not a complete program.

> vs
> IO.readlines("blob.txt").map{|line| line.split.map{|s| s.to_i }}

That is the complete program.

Perhaps the data was stored by someone else.  Understand?

> And then read it back into the program with:
> (map read-string (line-seq (reader "blob.txt")))

You make a very strong case that Lisp is very feeble at
processing data.  I'm almost convinced.

Ruby isn't feeble, so data like this is fine:

shall we begin?
or lotus135? 1984 times!
The 3 stooges: COBOL,LISP,FORTRAN.
3.14, si11y L00KING

Extracting the unsigned integers:

IO.readlines('data').map{|s| s.scan(/\d+/).map{|s| s.to_i}}
    ==>[[], [135, 1984], [3], [3, 14, 11, 0]]


 
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.
Messages 1 - 25 of 43   Newer >
« Back to Discussions « Newer topic     Older topic »