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
READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)
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 26 - 50 of 61 - Collapse all  -  Translate all to Translated (View all originals) < Older  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
 
Marco Antoniotti  
View profile  
 More options May 19 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Marco Antoniotti <marc...@copernico.parades.rm.cnr.it>
Date: 1999/05/19
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)

I have a better one.

(equalp P NP) => t nil

Cheers :)

--
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa


 
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.
Sam Steingold  
View profile  
 More options May 19 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Sam Steingold <s...@goems.com>
Date: 1999/05/19
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)
>>>> In message <87zp31cd75....@pc-hrvoje.srce.hr>
>>>> On the subject of "Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)"
>>>> Sent on 19 May 1999 17:05:18 +0200
>>>> Honorable Hrvoje Niksic <hnik...@srce.hr> writes:

 >> Sam Steingold <s...@goems.com> writes:
 >> > >>>> Honorable Hrvoje Niksic <hnik...@srce.hr> writes:
 >> >  >> strings such as "2+3i",
 >> > oh please!  "2+3i" is a complex number while "2+3j" is a symbol.
 >>
 >> "2+3j" is not a symbol here because we're talking about a
 >> hypothetical PARSE-NUMBER, not about the Lisp reader.  Anyway, you

all right, an error then.

 >> could also allow "2+3j", for all I care.  I don't like being dragged

what about "2i"?  "2i+3"? "2i+4j"?

 >> too far into this discussion -- it's not like I have any idea why
 >> 2+3i would be any worse than 2+3j.

what about "2+3k"? how about "1+2i+3j+4k"?

 >> >  >> "2 + 3i"  as complex numbers.
 >> > so, what should (parse-number "2 + 3i") return? 2? or #C(2 3)?
 >> The latter.

why?  you mean `parse-number' will return something different from
`parse-integer'?  

--
Sam Steingold (http://www.goems.com/~sds) running RedHat6.0 GNU/Linux
Micros**t is not the answer.  Micros**t is a question, and the answer is Linux,
(http://www.linux.org) the choice of the GNU (http://www.gnu.org) generation.
A man paints with his brains and not with his hands.


 
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.
Barry Margolin  
View profile  
 More options May 19 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Barry Margolin <bar...@bbnplanet.com>
Date: 1999/05/19
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)
In article <sfwg14t5jjz....@world.std.com>,
Kent M Pitman  <pit...@world.std.com> wrote:

>cba...@2xtreme.net (Christopher R. Barry) writes:

>> Kent M Pitman <pit...@world.std.com> writes:

>> > I recall a proposal a long time ago to make

>> >  (setf (format nil "~D:~D:~D" x y z) "1:36:12.2")

>> > work.  [Don't think too hard about it.  It has a lot of problems.

>> Couldn't stop myself. Were these problems along the lines of
>> constraining and defining the details of how exactly this would work
>> or otherwise?

>Thinks about (setf (format nil "~D~D" x y) "123")

The problem is no different from something like C's sscanf("123", "%d%d",
&x, &y).  Obviously an input parser won't be a complete inverse of an
output formatter.  But this doesn't mean that the use of SETF of FORMAT as
the interface is flawed.

--
Barry Margolin, bar...@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.


 
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.
Christopher R. Barry  
View profile  
 More options May 20 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: cba...@2xtreme.net (Christopher R. Barry)
Date: 1999/05/20
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)

Barry Margolin <bar...@bbnplanet.com> writes:
> >Thinks about (setf (format nil "~D~D" x y) "123")

> The problem is no different from something like C's sscanf("123", "%d%d",
> &x, &y).  Obviously an input parser won't be a complete inverse of an
> output formatter.  But this doesn't mean that the use of SETF of FORMAT as
> the interface is flawed.

I also thought along these lines. This is what gcc does:

  sscanf("", "%d%d%d", &x, &y, &z);
  printf("%d %d %d\n", x, y, z);
    => 0 1 1073787888

  sscanf("1", "%d%d%d", &x, &y, &z);
  printf("%d %d %d\n", x, y, z);
    => 1 1 1073787888

  sscanf("12", "%d%d%d", &x, &y, &z);
  printf("%d %d %d\n", x, y, z);
    => 12 1 1073787888

  sscanf("123", "%d%d%d", &x, &y, &z);
  printf("%d %d %d\n", x, y, z);
    => 123 1 1073787888

  sscanf("123456", "%d%d%d", &x, &y, &z);
  printf("%d %d %d\n", x, y, z);
    => 123456 1 1073787888

The analogous thing in Lisp with SETF of FORMAT should signal errors.

Christopher


 
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.
Guy Footring  
View profile  
 More options May 20 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Guy Footring <footr...@thcsv01.trafford.ford.com>
Date: 1999/05/20
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)

Sam Steingold <s...@goems.com> writes:

> >>>> In message <87zp31cd75....@pc-hrvoje.srce.hr>
> >>>> On the subject of "Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)"
> >>>> Sent on 19 May 1999 17:05:18 +0200
> >>>> Honorable Hrvoje Niksic <hnik...@srce.hr> writes:
>  >> Sam Steingold <s...@goems.com> writes:
>  >> > >>>> Honorable Hrvoje Niksic <hnik...@srce.hr> writes:
>  >> >  >> strings such as "2+3i",
>  >> > oh please!  "2+3i" is a complex number while "2+3j" is a symbol.

>  >> "2+3j" is not a symbol here because we're talking about a
>  >> hypothetical PARSE-NUMBER, not about the Lisp reader.  Anyway, you

[...]

>  >> >  >> "2 + 3i"  as complex numbers.
>  >> > so, what should (parse-number "2 + 3i") return? 2? or #C(2 3)?
>  >> The latter.

> why?  you mean `parse-number' will return something different from
> `parse-integer'?  

What about 1.23? You mean parse-number WON'T return something different from
parse-integer??


 
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.
Sam Steingold  
View profile  
 More options May 20 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Sam Steingold <s...@goems.com>
Date: 1999/05/20
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)
>>>> In message <wtwvy4m9s4....@thcsv01.trafford.ford.com>
>>>> On the subject of "Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)"
>>>> Sent on 20 May 1999 09:21:15 +0100
>>>> Honorable Guy Footring <footr...@thcsv01.trafford.ford.com> writes:

 >> Sam Steingold <s...@goems.com> writes:
 >> >
 >> >  >> >  >> "2 + 3i"  as complex numbers.
 >> >  >> > so, what should (parse-number "2 + 3i") return? 2? or #C(2 3)?
 >> >  >> The latter.
 >> >
 >> > why?  you mean `parse-number' will return something different from
 >> > `parse-integer'?  
 >>
 >> What about 1.23? You mean parse-number WON'T return something
 >> different from parse-integer??

Sorry, I should have been more specific.

when both `parse-integer' and `parse-number' return, they should return
the same number.  when `parse-number' returns a non-integer,
`parse-integer' should signal an error.

--
Sam Steingold (http://www.goems.com/~sds) running RedHat6.0 GNU/Linux
Micros**t is not the answer.  Micros**t is a question, and the answer is Linux,
(http://www.linux.org) the choice of the GNU (http://www.gnu.org) generation.
NY survival guide: when crossing a street, mind cars, not streetlights.


 
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.
Guy Footring  
View profile  
 More options May 20 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Guy Footring <footr...@thcsv01.trafford.ford.com>
Date: 1999/05/20
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)

Both (parse-integer "1 + 2i") and (parse-integer "1.23") raise an
error unless :junk-allowed T is specified (at least under LWW4.1 ACL5.0 and an oldish
Lucid Unix release).

I don't see that there is a problem with
(parse-integer "1.23") => error
(parse-integer "1.23" :junk-allowed t) => 1
(parse-float "1.23") => 1.23s0 ;should parse-float take a float type specifier?
(parse-number "1.23") => 1.23s0
(parse-integer "1 + 3i") => error
(parse-integer "1 + 3i" :junk-allowed t) => 1
(parse-float "1 + 3i") => error
(parse-float "1 + 3i" :junk-allowed t) => error? 1.0s0?
(parse-number "1 + 3i") => #C(1 3)


 
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.
Erik Naggum  
View profile  
 More options May 20 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Erik Naggum <e...@naggum.no>
Date: 1999/05/20
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)
* cba...@2xtreme.net (Christopher R. Barry)
| The analogous thing in Lisp with SETF of FORMAT should signal errors.

  FYI, SSCANF returns the number of objects successfully assigned.  if you
  use the previous value of unassigned variables, it's your own problem.

  BTW, I'd much prefer a binding form than a setting form, complete with
  &OPTIONAL and &REST and all, like DESTRUCTURING-BIND.

#:Erik
--
@1999-07-22T00:37:33Z -- pi billion seconds since the turn of the century


 
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.
Barry Margolin  
View profile  
 More options May 20 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Barry Margolin <bar...@bbnplanet.com>
Date: 1999/05/20
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)
In article <3136210744251...@naggum.no>, Erik Naggum  <e...@naggum.no> wrote:

>* cba...@2xtreme.net (Christopher R. Barry)
>| The analogous thing in Lisp with SETF of FORMAT should signal errors.

>  FYI, SSCANF returns the number of objects successfully assigned.  if you
>  use the previous value of unassigned variables, it's your own problem.

>  BTW, I'd much prefer a binding form than a setting form, complete with
>  &OPTIONAL and &REST and all, like DESTRUCTURING-BIND.

>#:Erik

If it weren't done using the SETF syntax (which I also don't really care
for -- its only virtue is "coolness factor"), I would probably just use a
function that returns each of the parsed items as multiple values, which
could be bound using MULTIPLE-VALUE-BIND:

(with-input-from-string (s "123 abcde 10")
  (multiple-value-bind (a b c)
      (parse-formatted "~d ~s ~o" s)
    (list a b c))) =>
(123 ABCDE 8)

--
Barry Margolin, bar...@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.


 
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.
Christopher R. Barry  
View profile  
 More options May 20 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: cba...@2xtreme.net (Christopher R. Barry)
Date: 1999/05/20
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)

Erik Naggum <e...@naggum.no> writes:
>   BTW, I'd much prefer a binding form than a setting form, complete with
>   &OPTIONAL and &REST and all, like DESTRUCTURING-BIND.

How would the filter be specified? What is your idea of that this
would look like?

  (format-bind <lambda list>
      <string-with-format-controls>
      <string>
    <implicit-progn>)

  (format-bind (a b)
      "~R"
      "one hundred fifty-three"
    (list a b))
   ==> Error: insufficient arguments error occurred when associating a value
       with B

  (format-bind (a &optional b)
      "~R"
      "one hundred fifty-three"
    (list a b))
   ==> (153 nil)

  (format-bind (a b c)
      "~D~D~D"
      "123456"
    (list a b c))
   ==> Error: insufficient arguments error occurred when associating a value
       with B
    or
   ==> (123456 nil nil)
    or something else???

?

Christopher


 
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.
Hrvoje Niksic  
View profile  
 More options May 20 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Hrvoje Niksic <hnik...@srce.hr>
Date: 1999/05/20
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)

Guy Footring <footr...@thcsv01.trafford.ford.com> writes:
> I don't see that there is a problem with
> (parse-integer "1.23") => error
> (parse-integer "1.23" :junk-allowed t) => 1
> (parse-float "1.23") => 1.23s0 ;should parse-float take a float type specifier?
> (parse-number "1.23") => 1.23s0

Note that the whole point of introducing PARSE-NUMBER is to remove the
need for a PARSE-FLOAT.

 
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.
Hrvoje Niksic  
View profile  
 More options May 20 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Hrvoje Niksic <hnik...@srce.hr>
Date: 1999/05/20
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)

Sam Steingold <s...@goems.com> writes:
>  >> could also allow "2+3j", for all I care.

> what about "2i"?  "2i+3"? "2i+4j"?

I imagine that the last could be an error, if you insist -- and so
would be "2 + 3".  Why are you asking me all this?

>  >> too far into this discussion -- it's not like I have any idea why
>  >> 2+3i would be any worse than 2+3j.

> what about "2+3k"?

Is "k" used somewhere to denote the imaginary part of a complex
number?  How frequent is it?

>  >> >  >> "2 + 3i"  as complex numbers.
>  >> > so, what should (parse-number "2 + 3i") return? 2? or #C(2 3)?
>  >> The latter.

> why?  you mean `parse-number' will return something different from
> `parse-integer'?

Yes.  (parse-integer "2 + 3i") signals an error, at least in CLISP and
CMU CL, where I tried it.

 
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.
Hrvoje Niksic  
View profile  
 More options May 20 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Hrvoje Niksic <hnik...@srce.hr>
Date: 1999/05/20
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)
cba...@2xtreme.net (Christopher R. Barry) writes:

> I also thought along these lines. This is what gcc does:

[...]

Gcc?!  You mean the C library on your system?


 
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.
Kent M Pitman  
View profile  
 More options May 21 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Kent M Pitman <pit...@world.std.com>
Date: 1999/05/21
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)

Hrvoje Niksic <hnik...@srce.hr> writes:
> Guy Footring <footr...@thcsv01.trafford.ford.com> writes:

> > I don't see that there is a problem with
> > (parse-integer "1.23") => error
> > (parse-integer "1.23" :junk-allowed t) => 1
> > (parse-float "1.23") => 1.23s0 ;should parse-float take a float type specifier?
> > (parse-number "1.23") => 1.23s0

> Note that the whole point of introducing PARSE-NUMBER is to remove the
> need for a PARSE-FLOAT.

But the whole point of introducing PARSE-FLOAT is to do what standards do
best: to publish what with certainty all implementations already have.

The problem with PARSE-NUMBER is that it is, as described, almost
certainly something no implementation presently has or needs, and for
any given choice of textual representation of complexes it will likely
satisfy only part of the community that thinks it wants a PARSE-NUMBER.
(Sort of the way any specific religion like Catholicism or Protestantism or
Judaism will satisfy only some subset of the people who think that
religion should be taught in school because people always
overoptimistically assume that when they ask for a cool thing under a
general name that it will do the specifics in a way that is not only
not general but that is fortuitously what suits them personally... so while
all of Jews and Catholics and Protestants might sign letters to Congress
saying they want religion in schools, many would end up also later signing
letters saying "get that OTHER religion out of schools" if anyone ever
took their proposal seriously.)  I think people only want PARSE-NUMBER
because they imagine they would all be able to agree on a semantics or
that it doesn't matter to them that others won't like their choice because
they're assuming they won't be in the set that gets the version they
don't like.  In practice, if PARSE-NUMBER parses floats and there is no
PARSE-FLOAT, then people will be having to do contorted things to screen
out representations they don't want (like rationals or complexes) and to
reformat other representations they want to be more palatable to PARSE-NUMBER.
I'd rather just give them building-blocks of PARSE-INTEGER and PARSE-FLOAT
because those are surely in the implementation anyway and then
let them build up anything application-specific that they need beyond that.


 
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.
Philip Lijnzaad  
View profile  
 More options May 21 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Philip Lijnzaad <lijnz...@ebi.ac.uk>
Date: 1999/05/21
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)

> sscanf("123456", "%d%d%d", &x, &y, &z);
> printf("%d %d %d\n", x, y, z);
> => 123456 1 1073787888

sscanf allows you to specify a maximum field width too:

  sscanf("123456789", "%2d %3d 4%d", &x, &y, &z);
  printf("%d %d %d\n", x, y, z);

  12 345 6789

whereas

  sscanf("123456789", "%4d %3d %2d", &x, &y, &z);
  printf("%d %d %d\n", x, y, z);

  1234 567 89.

The number between the '%' and 'd' is the maximum length to scan, but the
scan stops earlier if a non-digit is found. Also, scan always skips any white
space before it starts reading the next number. All a bit of a mess, really,
and not idempotent (which is what you'd like).

Incidentally, whitespace in the scan format is not significant,
strangely. But this is not comp.lang.c. So, anyway, I suppose that for (setf
(format ...) ...) you could also use the field widths of the format
specifiers, to get over the problem of (setf (format nil "~D~D" x y) "123")
(which I think should just make x 123 and y nil).
                                                                      Philip

--
The mail transport agent is not liable for any coffee stains in this message
--------------------------------------------------------------------------- --
Philip Lijnzaad, lijnz...@ebi.ac.uk | European Bioinformatics Institute
+44 (0)1223 49 4639                 | Wellcome Trust Genome Campus, Hinxton
+44 (0)1223 49 4468 (fax)           | Cambridgeshire CB10 1SD,  GREAT BRITAIN
PGP fingerprint: E1 03 BF 80 94 61 B6 FC  50 3D 1F 64 40 75 FB 53


 
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.
Johan Kullstam  
View profile  
 More options May 21 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Johan Kullstam <kulls...@ne.mediaone.net>
Date: 1999/05/21
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)

Hrvoje Niksic <hnik...@srce.hr> writes:
> Guy Footring <footr...@thcsv01.trafford.ford.com> writes:

> > I don't see that there is a problem with
> > (parse-integer "1.23") => error
> > (parse-integer "1.23" :junk-allowed t) => 1
> > (parse-float "1.23") => 1.23s0 ;should parse-float take a float type specifier?
> > (parse-number "1.23") => 1.23s0

> Note that the whole point of introducing PARSE-NUMBER is to remove the
> need for a PARSE-FLOAT.

just because you have a PARSE-NUMBER doesn't mean PARSE-FLOAT
PARSE-SINGLE-FLOAT, PARSE-DOUBLE-FLOAT PARSE-COMPLEX &c shouldn't
exist.  having the specific forms may be useful in declaring what
exactly you mean.

PARSE-NUMBER may be implemented as a wrapper for the specific
instances.  how about requiring a type in addition to the string?

(PARSE-NUMBER 'DOUBLE-FLOAT "2.718281828")
2.7183d0

(PARSE-NUMBER 'INTEGER "415")
415

a fancier implementation could default to infering the type (much as
the reader does), i.e., 1 is an integer, 1/2 is a rational, 1s3 is a
single-float &c, and take a :type key argument to allow you to
specify.

--
johan kullstam


 
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.
Marco Antoniotti  
View profile  
 More options May 24 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Marco Antoniotti <marc...@copernico.parades.rm.cnr.it>
Date: 1999/05/24
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)

(PARSE-NUMBER "2.718281828" :type 'double-float)

Would be better.  Contrary to CONCATENATE there is no &rest argument
to deal with.  However what would you do with

(PARSE-NUMBER "2" :type 'NUMBER)

?

Cheers

--
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa


 
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.
Discussion subject changed to "PARSE-NUMBER" by Juanma Barranquero
Juanma Barranquero  
View profile  
 More options May 24 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: barranqu...@laley-actualidad.es (Juanma Barranquero)
Date: 1999/05/24
Subject: PARSE-NUMBER
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 24 May 1999 11:33:44 +0200, Marco Antoniotti

<marc...@copernico.parades.rm.cnr.it> wrote:
>However what would you do with

>(PARSE-NUMBER "2" :type 'NUMBER)

>?

Return a number of the type (type-of 2) would return in the given
implementation. In my system (and most of them, I'd expect), a FIXNUM.
And

(parse-number "536870912" :type 'number)

would return a BIGNUM because (type-of 536870912) says it is a BIGNUM
(again, in my ACL).

                                                       /L/e/k/t/u

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.0.2i

iQA/AwUBN0kabP4C0a0jUw5YEQJ61wCgyQIZpWCRF4AvbCq3ory6hOoD8jMAnA5r
wroYDlptMC1CuJpGLW/B8HCd
=Ds/C
-----END PGP SIGNATURE-----


 
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.
Marco Antoniotti  
View profile  
 More options May 24 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Marco Antoniotti <marc...@copernico.parades.rm.cnr.it>
Date: 1999/05/24
Subject: Re: PARSE-NUMBER

Therefore,

(PARSE-NUMBER "12" :type 'bignum)

should signa an error, shouldn't it?

--
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa


 
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.
Juanma Barranquero  
View profile  
 More options May 24 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: barranqu...@laley-actualidad.es (Juanma Barranquero)
Date: 1999/05/24
Subject: Re: PARSE-NUMBER
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

>Therefore,

>(PARSE-NUMBER "12" :type 'bignum)

>should signa an error, shouldn't it?

Yes.

I think a reasonable behavior for

(parse-number NUMBER-AS-STRING :type 'TYPE)

could be as follows:

Let's define N as (read-from-string NUMBER-AS-STRING) and TN as
(type-of N).

Then, if (subtypep TN TYPE) == t, the number returned would be N of
type TN; else parse-number should signal an error (or return nil, or
whatever).

You cannot force N to be of type TYPE unless is possible to have
objects for which (type-of OBJECT) == TYPE. Since BIGNUM and FIXNUM
are an exhaustive partition of INTEGER, I suppose (perhaps I'm wrong)
that if N is an INTEGER, an implementation will return BIGNUM or
FIXNUM for (type-of N), and not INTEGER, so

(parse-number N :type 'INTEGER)

should return either a FIXNUM or a BIGNUM as appropriate.

So if someone wants to parse an INTEGER with parse-number, he should
use :type 'INTEGER. Using :type 'BIGNUM should be a promise that
*really* a BIGNUM is expected.

A problem: May seem counter-intuitive to have

(parse-number "1.0" :type 'DOUBLE-FLOAT)

to return an error, but (typep 1.0 'DOUBLE-FLOAT) is nil, so is not
totally illogical. Hmmm...

                                                       /L/e/k/t/u

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.0.2i

iQA/AwUBN0lKW/4C0a0jUw5YEQK3mwCgwSAA8ZcLc045U20JU35P5fE39DgAoMJL
aWkfz3fibp4zVfYQOmdu3E7h
=S+cx
-----END PGP SIGNATURE-----


 
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.
Barry Margolin  
View profile  
 More options May 24 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Barry Margolin <bar...@bbnplanet.com>
Date: 1999/05/24
Subject: Re: PARSE-NUMBER
In article <37514102.345811...@news.mad.ttd.net>,

Juanma Barranquero <barranqu...@laley-actualidad.es> wrote:
>A problem: May seem counter-intuitive to have

>(parse-number "1.0" :type 'DOUBLE-FLOAT)

>to return an error, but (typep 1.0 'DOUBLE-FLOAT) is nil, so is not
>totally illogical. Hmmm...

Not illogical, but it seems counter to what PARSE-NUMBER seems to be
intended for.  I thought we were discussing a function that could be used
to parse data that isn't necessarily from a Lisp source, e.g. a user.  We
may want to read in a float, but does that mean that a user who is totally
unfamiliar with Lisp should be expected to know that floats have to have an
embedded decimal point?  It would seem more useful, in this context, to
have

(parse-number S :type T)

perform something similar to

(coerce (read-from-string S) T)

--
Barry Margolin, bar...@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.


 
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.
Christopher R. Barry  
View profile  
 More options May 24 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: cba...@2xtreme.net (Christopher R. Barry)
Date: 1999/05/24
Subject: Re: PARSE-NUMBER

barranqu...@laley-actualidad.es (Juanma Barranquero) writes:

[...]

> (parse-number "1.0" :type 'DOUBLE-FLOAT)

> to return an error, but (typep 1.0 'DOUBLE-FLOAT) is nil, so is not
> totally illogical. Hmmm...

If you want 1.0 to be read as a DOUBLE-FLOAT, then you write it as
1.0d0. You could have also tried (COERCE 1.0 'DOUBLE-FLOAT) =>
1.0d0. You should be able to parse floats as any subtype of FLOAT that
you wish, even allowing truncation, since you can do

  USER(8): pi
  => 3.141592653589793d0

  USER(9): (coerce pi 'single-float)
  => 3.1415927

Christopher


 
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.
Discussion subject changed to "READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)" by Johan Kullstam
Johan Kullstam  
View profile  
 More options May 24 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Johan Kullstam <kulls...@ne.mediaone.net>
Date: 1999/05/24
Subject: Re: READ-FROM-STRING considered unsafe? (was Re: Simple Function Question)

yes.  this reads better.

> (PARSE-NUMBER "2" :type 'NUMBER)

well, anything that would be a number equal to two, i think it would
be ok.  so as long as

(setq x (parse-number "2" :type 'number))

(and (numberp x) (= x 2))

returns t, i would be happy.

thus 2 or 2d0 could be valid values.

i think using the most specific type possible for the return would be
best.  hence i might be surprised if i didn't get a fixnum in the
above case.

if you want a more specific answer, it would behoove you to be more
specific!

 * * *

the general reading problem, as i see it, is this:

in printing from lisp, you have lots of information such as the type.
therefore format can make do with things like ~A which work with most
anything.

when you read, you have no idea what you're reading.  the type
information needs to be inferred from syntax (like the full
lisp-reader) or supplied from somewhere else (like parse-integer
explicitly calls out integer).

in light of the asymmetry of knowledge wrt to type information,
something like

(setf x (format "2" "~A"))

has no hope of working.

C has no idea what type anything is in.  you have to explicitly supply
types in the format string in both input and output cases.  therefore
printf and scanf format strings look (mostly) the same.[1]

since this problem is not limited to numbers, how would one go about
reading some arbitrary type such as a vector or structure?  perhaps we
should say nothing about hash-tables.

[1] C cannot pass floats, only doubles hence both floats and doubles
are printed with %f but scanned with %f and %lf respectively.

--
johan kullstam


 
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.
Discussion subject changed to "PARSE-NUMBER" by Juanma Barranquero
Juanma Barranquero  
View profile  
 More options May 24 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: barranqu...@laley-actualidad.es (Juanma Barranquero)
Date: 1999/05/24
Subject: Re: PARSE-NUMBER
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, 24 May 1999 15:05:00 GMT, Barry Margolin

<bar...@bbnplanet.com> wrote:
>I thought we were discussing a function that could be used
>to parse data that isn't necessarily from a Lisp source, e.g. a user.

Then

(parse-number "1.0" :type 'FLOAT)

will do (or 'REAL, 'NUMBER). Use as general a type as needed. I
assumed :type 'BIGNUM or 'DOUBLE-FLOAT or other more specific types
would be used for reading data where we *know for sure* what's being
read (not from the user, but from a C-generated file, for example). I
see no contradiction.

>We may want to read in a float, but does that mean that a user who is
>totally unfamiliar with Lisp should be expected to know that floats
>have to have an embedded decimal point?

Then (float (parse-number NUMBER-AS-STRING :type 'REAL) 1.0d0) and
check for errors.

>It would seem more useful, in this context, to have

>(parse-number S :type T)

>perform something similar to

>(coerce (read-from-string S) T)

What you're proposing is not very different of what I've suggested in
my previous post, I think. I suppose you say "something similar to"
because of that:

USER(56): (coerce (read-from-string "1") 'bignum)
Error: Can't coerce 1 to type BIGNUM.
  [condition type: SIMPLE-ERROR]

so in fact, as Marco Antoniotti pointed to me, if you want generality
at read time, you're *forced* to ask for a more general type and
coerce to (type-of N), i.e., a subtype of T and not T.

That's why I said that parse-number *cannot* always return the asked
for type, but only a subtype of it. As I see it, it's a no-win
situation. There are two sensible ways to define the return value of:

(parse-number N-AS-S :type T)

1.- You expect parse-number to coerce the number to T (with an error
if it cannot deliver, as in the BIGNUM example), or

2.- parse-number returns a number of the most appropriate subtype of
T, and you manually coerce the number and/or check for errors (as in
the 'REAL example above) if needed.

I prefer the second alternative.

                                                       /L/e/k/t/u

P.S.: Sorry if I'm not being very intelligible; I've rewritten this
message a couple times, but my English is failing me miserably :(

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.0.2i

iQA/AwUBN0lmRv4C0a0jUw5YEQJixQCfeg0xK3Jk4qApW+yLI5wcxcIjXQoAn3Qf
JtixIp73HMBGNQGLgkyXRQjv
=ZHXQ
-----END PGP SIGNATURE-----


 
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.
Tim Bradshaw  
View profile  
 More options May 25 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Tim Bradshaw <t...@tfeb.org>
Date: 1999/05/25
Subject: Re: PARSE-NUMBER

* Juanma Barranquero wrote:
> (parse-number "1.0" :type 'DOUBLE-FLOAT)
> to return an error, but (typep 1.0 'DOUBLE-FLOAT) is nil, so is not
> totally illogical. Hmmm...

* (type-of 1.0)
double-float

* *read-default-float-format*
double-float

PARSE-FLOAT is so much easier.


 
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 26 - 50 of 61 < Older  Newer >
« Back to Discussions « Newer topic     Older topic »