Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Newbie: input file with commas like this: (, ,)
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
  14 messages - Collapse all  -  Translate all to Translated (View all originals)
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
 
a314658  
View profile  
 More options Jan 25, 9:12 pm
Newsgroups: comp.lang.lisp
From: a314658 <314...@gmail.com>
Date: Sun, 25 Jan 2009 18:12:06 -0800
Local: Sun, Jan 25 2009 9:12 pm
Subject: Newbie: input file with commas like this: (, ,)
One of the sexp's in a file that I'm trying to read has the following:

(foo (bar baz) (, ,) )

and when I try to read it in I get error: comma is illegal outside of
backquote. what is a way around that?

thanks,
-Victor Piousbox, a student


    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.
D Herring  
View profile  
 More options Jan 25, 6:14 pm
Newsgroups: comp.lang.lisp
From: D Herring <dherr...@at.tentpost.dot.com>
Date: Sun, 25 Jan 2009 18:14:31 -0500
Local: Sun, Jan 25 2009 6:14 pm
Subject: Re: Newbie: input file with commas like this: (, ,)

a314658 wrote:
> One of the sexp's in a file that I'm trying to read has the following:

> (foo (bar baz) (, ,) )

> and when I try to read it in I get error: comma is illegal outside of
> backquote. what is a way around that?

What does foo expect the commas to be?
(foo (bar baz) (", ,"))
(foo (bar baz) (#\, #\,))
(foo (bar baz) (|, ,|))
...

- Daniel


    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.
a314658  
View profile  
 More options Jan 25, 9:23 pm
Newsgroups: comp.lang.lisp
From: a314658 <314...@gmail.com>
Date: Sun, 25 Jan 2009 18:23:10 -0800
Local: Sun, Jan 25 2009 9:23 pm
Subject: Re: Newbie: input file with commas like this: (, ,)
Er... I can't change the dataset. But it's just a tree of constants, no
functions. It goes something like this:

( (S
     (VP (VBD brought)
       (PP
         (NP (PRP him) ))
       (NP
         (NP (DT a) (NN mixture) )
         (, ,)
         (PP (IN of))))
     (. .) ))

And so the (. .) and (, ,) part is giving me trouble.


    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.
Rainer Joswig  
View profile  
 More options Jan 25, 6:57 pm
Newsgroups: comp.lang.lisp
From: Rainer Joswig <jos...@lisp.de>
Date: Mon, 26 Jan 2009 00:57:04 +0100
Local: Sun, Jan 25 2009 6:57 pm
Subject: Re: Newbie: input file with commas like this: (, ,)
In article <497cf18e$0$3340$6e1ed...@read.cnntp.org>,

 a314658 <314...@gmail.com> wrote:
> One of the sexp's in a file that I'm trying to read has the following:

> (foo (bar baz) (, ,) )

> and when I try to read it in I get error: comma is illegal outside of
> backquote. what is a way around that?

> thanks,
> -Victor Piousbox, a student

See readtables in Common Lisp.

To make , a whitespace use:

CL-USER 60 > (defparameter *data* "(foo (bar baz) (, ,) )")
*DATA*

CL-USER 61 > (defparameter *rt* (copy-readtable))
*RT*

CL-USER 62 > (set-syntax-from-char #\, #\space *rt* *rt*)
T

CL-USER 63 > (let ((*readtable* *rt*)) (read-from-string *data*))
(FOO (BAR BAZ) NIL)
22

You can also have them read as something.
Here I read the character #\, as the symbol |,|.
The symbol comma can also be printed as \, .

CL-USER 64 > (defparameter *rt* (copy-readtable))
*RT*

CL-USER 65 > (set-macro-character #\, (lambda (stream char) '|,|) nil *rt*)
T

CL-USER 66 > (let ((*readtable* *rt*)) (read-from-string *data*))
(FOO (BAR BAZ) (\, \,))
22

You should not change the existing readtable, but create your
own and change that - as I did in the example.

Then binding *readtable* to your readtable
around calls to the read functions (read, read-from-string, ...)
will make them use the new readtable - thanks to dynamic
binding.

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


    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.
Pascal J. Bourguignon  
View profile  
(2 users)  More options Jan 25, 7:07 pm
Newsgroups: comp.lang.lisp
From: p...@informatimago.com (Pascal J. Bourguignon)
Date: Mon, 26 Jan 2009 01:07:21 +0100
Local: Sun, Jan 25 2009 7:07 pm
Subject: Re: Newbie: input file with commas like this: (, ,)

a314658 <314...@gmail.com> writes:
> Er... I can't change the dataset. But it's just a tree of constants,
> no functions. It goes something like this:

> ( (S
>     (VP (VBD brought)
>       (PP
>         (NP (PRP him) ))
>       (NP
>         (NP (DT a) (NN mixture) )
>         (, ,)
>         (PP (IN of))))
>     (. .) ))

> And so the (. .) and (, ,) part is giving me trouble.

If you cannot change the data, then you will have to implement your
own reader (or use a library reader), because unfortunately, the
Common Lisp standard doesn't allow changing the constituent traits of
characters, therefore nothing can be done to read the dot not as an
invalid token by CL:READ.  For the comma, you can just remove the
reader macro normally attached to it.  But for the dot, you need to
change the whole reader.

(It would probably be much easier to copy your data file substituting
these characters:

      sed -e 's/\([.,]\)/\\\1/g' < daat  > data-for-cl

and use data-for-cl with the normal readtable, but if you cannot
change the dataset, perhaps you are forbidden to do that too...)

Have a look at:
http://darcs.informatimago.com/lisp/common-lisp/reader.lisp
http://www.informatimago.com/develop/lisp/index.html

--
__Pascal Bourguignon__


    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.
joswig@corporate-world.li sp.de  
View profile  
(1 user)  More options Jan 25, 7:24 pm
Newsgroups: comp.lang.lisp
From: "jos...@corporate-world.lisp.de" <jos...@corporate-world.lisp.de>
Date: Sun, 25 Jan 2009 16:24:58 -0800 (PST)
Local: Sun, Jan 25 2009 7:24 pm
Subject: Re: Newbie: input file with commas like this: (, ,)
On 26 Jan., 01:07, p...@informatimago.com (Pascal J. Bourguignon)
wrote:

(defparameter *data* "(foo (bar baz) (, ,) (. .))")
(defparameter *rt* (copy-readtable))

(set-macro-character #\. (lambda (stream char) '|.|) nil *rt*)
(set-macro-character #\, (lambda (stream char) '|,|) nil *rt*)
(set-macro-character #\( (lambda (stream char) (read-delimited-list #
\) stream)) t *rt*)

(let ((*readtable* *rt*))
  (with-input-from-string (s *data*)
    (read s)))

->  (FOO (BAR BAZ) (\, \,) (\. \.))

Works for me...


    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.
Pascal J. Bourguignon  
View profile  
(1 user)  More options Jan 25, 8:44 pm
Newsgroups: comp.lang.lisp
From: p...@informatimago.com (Pascal J. Bourguignon)
Date: Mon, 26 Jan 2009 02:44:35 +0100
Local: Sun, Jan 25 2009 8:44 pm
Subject: Re: Newbie: input file with commas like this: (, ,)

Yes, it works here too.  I must have done something wrong in my own tests...

--
__Pascal Bourguignon__


    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.
Kaz Kylheku  
View profile  
(1 user)  More options Jan 25, 9:01 pm
Newsgroups: comp.lang.lisp
From: Kaz Kylheku <kkylh...@gmail.com>
Date: Mon, 26 Jan 2009 02:01:13 +0000 (UTC)
Local: Sun, Jan 25 2009 9:01 pm
Subject: Re: Newbie: input file with commas like this: (, ,)
On 2009-01-26, a314658 <314...@gmail.com> wrote:

> Er... I can't change the dataset. But it's just a tree of constants, no
> functions. It goes something like this:

> ( (S
>      (VP (VBD brought)
>        (PP
>          (NP (PRP him) ))
>        (NP
>          (NP (DT a) (NN mixture) )
>          (, ,)
>          (PP (IN of))))
>      (. .) ))

> And so the (. .) and (, ,) part is giving me trouble.

What D Herring is asking is what these commas and periods represent.

You can't solve this problem if you don't know what these are.

Is it okay to just discard these forms, so they turn into nothing?

If they mean nothing, why are they in the data?

Let's put it this way: can you fill in this blank?

   Syntax:            Reads as this Lisp object:

   a                  A
   (a . nil)          (A)
   #xFF               255
   (, ,)              ______ ???

If /you/ can't fill in this blank, how can you write a computer
program which fills in the blank?


    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.
a314658  
View profile  
 More options Jan 26, 9:48 pm
Newsgroups: comp.lang.lisp
From: a314658 <314...@gmail.com>
Date: Mon, 26 Jan 2009 18:48:43 -0800
Local: Mon, Jan 26 2009 9:48 pm
Subject: Re: Newbie: input file with commas like this: (, ,)

  It works! I feared that I'd have to read the files a char at a time,
or do pre-parsing, which would not be graceful. Your solution is
graceful. Thanks a lot ;-)

-Victor


    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.
a314658  
View profile  
 More options Jan 26, 9:54 pm
Newsgroups: comp.lang.lisp
From: a314658 <314...@gmail.com>
Date: Mon, 26 Jan 2009 18:54:40 -0800
Local: Mon, Jan 26 2009 9:54 pm
Subject: Re: Newbie: input file with commas like this: (, ,)

Discarding data is a very subtle business ;-) I'd be content with
translating (, ,) as (\, \,) and (. .) as (\. \.).

    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.
Kaz Kylheku  
View profile  
(1 user)  More options Jan 26, 7:27 pm
Newsgroups: comp.lang.lisp
From: Kaz Kylheku <kkylh...@gmail.com>
Date: Tue, 27 Jan 2009 00:27:17 +0000 (UTC)
Local: Mon, Jan 26 2009 7:27 pm
Subject: Re: Newbie: input file with commas like this: (, ,)
On 2009-01-27, a314658 <314...@gmail.com> wrote:

> Discarding data is a very subtle business ;-) I'd be content with
> translating (, ,) as (\, \,) and (. .) as (\. \.).

I.e. commas and periods are token constituent characters. Easily arranged in
the readtable.

Any tricky cases? Could the data contain instances of the dot which are in fact
consing dot notation and must be treated as such?

Is the lack of whitespace, in your examples, between the left or right
parenthesis, and the following or leading dot, significant? Does ( . . ) mean
something different from (. .) ?

Also, what is the lexical analysis to make of this?

 (. .)
  \ /
  / \
 ( v )

Hmm ....


    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.
 
View profile  
 More options Jan 28, 9:19 am
Newsgroups: comp.lang.lisp
From: http://rem.intarweb.org?tinyurl.com?u...@MaasInfo.Org (Robert Maas)
Date: Wed, 28 Jan 2009 06:19:46 -0800
Local: Wed, Jan 28 2009 9:19 am
Subject: Re: Newbie: input file with commas like this: (, ,)

> From: a314658 <314...@gmail.com>
> One of the sexp's in a file that I'm trying to read has the following:
> (foo (bar baz) (, ,) )

I don't know what you mean by "sexp", but that's not a valid
s-expression in any version of lisp I've ever seen/used. You need
to contact whoever made that file to find out what his/her
intention was. Only when you know the intention of those commas
will you be able to convert them to something usable in CL.

If this is a class assignment, ask your instructor.
If this is a work assignment, ask your boss/supervisor.
If your instructor/boss/supervisor refuses to tell you the
intention of those commas, but still expects you to deal with them,
file a grievance.

If this is a random file you found on the net, you're wasting your
time, and our time.
If this is a file you generated yourself, please tell us how you
generated it.


    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.
Pascal J. Bourguignon  
View profile  
 More options Jan 28, 10:13 am
Newsgroups: comp.lang.lisp
From: p...@informatimago.com (Pascal J. Bourguignon)
Date: Wed, 28 Jan 2009 16:13:53 +0100
Local: Wed, Jan 28 2009 10:13 am
Subject: Re: Newbie: input file with commas like this: (, ,)

http://rem.intarweb.org?tinyurl.com?u...@MaasInfo.Org (Robert Maas) writes:
>> From: a314658 <314...@gmail.com>
>> One of the sexp's in a file that I'm trying to read has the following:
>> (foo (bar baz) (, ,) )

> I don't know what you mean by "sexp", but that's not a valid
> s-expression in any version of lisp I've ever seen/used.

Old lisps had not yet backquotes, so you could name a symbol by a
single comma.  For the dot, I don't remember if in LISP 1.5 there was
already the pair syntax or not, I'll have to check the sources.

> You need
> to contact whoever made that file to find out what his/her
> intention was. Only when you know the intention of those commas
> will you be able to convert them to something usable in CL.

> If this is a class assignment, ask your instructor.
> If this is a work assignment, ask your boss/supervisor.
> If your instructor/boss/supervisor refuses to tell you the
> intention of those commas, but still expects you to deal with them,
> file a grievance.

Customer is king.  You don't file grievances when a customer comes
with his requirements, however strange they may seem to you.

> If this is a random file you found on the net, you're wasting your
> time, and our time.

Not really, CL is perfectly able to read this file, as other answers
demonstrated.

> If this is a file you generated yourself, please tell us how you
> generated it.

--
__Pascal Bourguignon__

    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.
Andrew Philpot  
View profile  
 More options Jan 28, 10:58 am
Newsgroups: comp.lang.lisp
From: Andrew Philpot <phil...@isi.edu>
Date: 28 Jan 2009 15:58:24 GMT
Local: Wed, Jan 28 2009 10:58 am
Subject: Re: Newbie: input file with commas like this: (, ,)

> http://rem.intarweb.org?tinyurl.com?u...@MaasInfo.Org (Robert Maas) writes:

>>> From: a314658 <314...@gmail.com>
>>> One of the sexp's in a file that I'm trying to read has the following:
>>> (foo (bar baz) (, ,) )

>> You need
>> to contact whoever made that file to find out what his/her
>> intention was. Only when you know the intention of those commas
>> will you be able to convert them to something usable in CL.

From inspection, it's Penn treebank (parsed natural language).  CARs
are tags, CADRs are subtrees or leaves (lexemes), etc.  The first ","
thus is the class (tag) of all comma-like punctuation sequences, the
second is the actual comma encountered.  These files also often have
bare : and ; and . characters, and may have the lexemes "'s" and "'nt"
and don't forget the embedded comma as digits separator "1,000".  I've
also seen extended versions where the lexeme tokens may themselves
include colons, weirdly escaped whitespace, potnums, etc.

I've read simple versions of these successfully with the stock CL
reader by modifying the syntax of a few characters, but now I use
Pascal Bourguingon's portable CL reader with a custom token
recognizer.

--
Andrew Philpot
USC Information Sciences Institute
phil...@isi.edu


    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.
End of messages
« Back to Discussions « Newer topic     Older topic »

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