1. value()

Hey gang blink,

trying to parse STR, value(STR) is returning {GET_SUCCESS, SOMEVAL}.

1) is there any way to tell how much of STR value() "ate"?

2) what is the simplest way to get SOMEVAL as returned back from
value() into a character string again? I'll do it if I have to, no
worry, but there just *must* be a better way than puts(fn,SOMEVAL) and
reading it back in again!

Pete

new topic     » topic index » view message » categorize

2. Re: value()

--=======1E037A3F=======

At 01:18 AM 2/18/03 +0000, you wrote:

>
>Hey gang blink,
>
>trying to parse STR, value(STR) is returning {GET_SUCCESS, SOMEVAL}.
>
>1) is there any way to tell how much of STR value() "ate"?
>
>2) what is the simplest way to get SOMEVAL as returned back from
>value() into a character string again? I'll do it if I have to, no
>worry, but there just *must* be a better way than puts(fn,SOMEVAL) and
>reading it back in again!
>
>Pete

Regarding point 2): Use x = sprintf( "%d", {SOMEVAL} ).

Right from the manual:

  SYNTAX:
  s = sprintf(st, x)

  DESCRIPTION:
  This is exactly the same as printf(), except that the output is
  returned as a sequence of characters, rather than being sent to a
  file or device. st is a format string, x is the value or sequence
  of values to be formatted. printf(fn, st, x) is equivalent to
  puts(fn, sprintf(st, x)).

  COMMENTS:
  Some typical uses of sprintf() are:

  1. Converting numbers to strings.
  2. Creating strings to pass to system().
  3. Creating formatted error messages that can be passed to a
  common error message handler.

  EXAMPLE:

  s = sprintf("%08d", 12345)
  -- s is "00012345"


  SEE ALSO:
  printf, value, sprint, get, system

                         Bob

--=======1E037A3F=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert;
x-avg-checked=avg-ok-C6F1758
Content-Disposition: inline


---

--=======1E037A3F=======--

new topic     » goto parent     » topic index » view message » categorize

3. Re: value()

On Tue, 18 Feb 2003 01:18:12 +0000, Pete Lomax <petelomax at blueyonder.co.uk> 
wrote:

>
> Hey gang blink,
>
> trying to parse STR, value(STR) is returning {GET_SUCCESS, SOMEVAL}.
>
> 1) is there any way to tell how much of STR value() "ate"?

Not with value() there isn't. I've written a convert-to-number routine tha 
does tell you this info. I can mail it if you like.

> 2) what is the simplest way to get SOMEVAL as returned back from
> value() into a character string again? I'll do it if I have to, no
> worry, but there just *must* be a better way than puts(fn,SOMEVAL) and
> reading it back in again!

  sequence x
  if integer(SOMEVAL) then
	x = sprintf("%d", SOMEVAL)
  else
      x = sprintf("%15.15f",SOMEVAL)
      -- Remove trailing zeros.
      for i = length(x) to 1 by -1 do
       if x[i] != '0' then
         exit
       end if
       x = x[1..i-1]
      end for
  end if




-- 

cheers,
Derek Parnell

new topic     » goto parent     » topic index » view message » categorize

4. Re: value()

On Mon, 17 Feb 2003 21:16:47 -0500, Robert Elia
<bobelia200 at netzero.net> wrote:

>>trying to parse STR, value(STR) is returning {GET_SUCCESS, SOMEVAL}.
>>
>>2) what is the simplest way to get SOMEVAL as returned back from
>>value() into a character string again? I'll do it if I have to, no
>>worry, but there just *must* be a better way than puts(fn,SOMEVAL) and
>>reading it back in again!
>
>Regarding point 2): Use x =3D sprintf( "%d", {SOMEVAL} ).

Sorry, SOMEVAL may be integer, for which the above works fine, or a
float, for which %g works fine, but I really should have said it is
sequences on which I'm stumped. Thanks anyway Bob.

Pete

new topic     » goto parent     » topic index » view message » categorize

5. Re: value()

On Tue, 18 Feb 2003 13:19:25 +1100, Derek Parnell
<ddparnell at bigpond.com> wrote:

Thanks Derek, I really ought to have pointed out it was sequences
giving me jip on point 2. Guess I'll go the puts(fn) route.

Pete

new topic     » goto parent     » topic index » view message » categorize

6. Re: value()

On Tue, 18 Feb 2003 02:36:14 +0000, Pete Lomax <petelomax at blueyonder.co.uk> 
wrote:

>
> On Mon, 17 Feb 2003 21:16:47 -0500, Robert Elia
> <bobelia200 at netzero.net> wrote:
>
>>> trying to parse STR, value(STR) is returning {GET_SUCCESS, SOMEVAL}.
>>>
>>> 2) what is the simplest way to get SOMEVAL as returned back from
>>> value() into a character string again? I'll do it if I have to, no
>>> worry, but there just *must* be a better way than puts(fn,SOMEVAL) and
>>> reading it back in again!
>>
>> Regarding point 2): Use x = sprintf( "%d", {SOMEVAL} ).
>
> Sorry, SOMEVAL may be integer, for which the above works fine, or a
> float, for which %g works fine,

Actually, "%g" truncates digits so I never use it anymore.

> but I really should have said it is
> sequences on which I'm stumped. Thanks anyway Bob.

The print() routine might be what you are looking for.

-- 

cheers,
Derek Parnell

new topic     » goto parent     » topic index » view message » categorize

7. Re: value()

On Tue, 18 Feb 2003 00:30:04 -0300, <rforno at tutopia.com> wrote:

>
> Derek:
> What do you mean by "truncating digits"? The only digits I see that %g
> truncates are zeroes at the right of the decimal part, that perhaps is 
> what
> the user wants. Is this what you mean?

printf(1, "%g", 12.3456789)  ==> 12.3457
printf(1, ".16g%", 12.3456789) ==> 12.3456789

-- 

cheers,
Derek Parnell

new topic     » goto parent     » topic index » view message » categorize

8. Re: value()

>From: Derek Parnell <ddparnell at bigpond.com>
>Subject: Re: value()
>
>
>On Tue, 18 Feb 2003 02:36:14 +0000, Pete Lomax <petelomax at blueyonder.co.uk> 
>wrote:
>
>>
>>On Mon, 17 Feb 2003 21:16:47 -0500, Robert Elia
>><bobelia200 at netzero.net> wrote:
>>
>>>>trying to parse STR, value(STR) is returning {GET_SUCCESS, SOMEVAL}.
>>>>
>>>>2) what is the simplest way to get SOMEVAL as returned back from
>>>>value() into a character string again? I'll do it if I have to, no
>>>>worry, but there just *must* be a better way than puts(fn,SOMEVAL) and
>>>>reading it back in again!
>>>
>>>Regarding point 2): Use x = sprintf( "%d", {SOMEVAL} ).
>>
>>Sorry, SOMEVAL may be integer, for which the above works fine, or a
>>float, for which %g works fine,
>
>Actually, "%g" truncates digits so I never use it anymore.
>
>>but I really should have said it is
>>sequences on which I'm stumped. Thanks anyway Bob.
>
>The print() routine might be what you are looking for.
>

Perhaps you mean sprint(). From the Library documentation:

Syntax: include misc.e
s = sprint(x)

Description: The representation of x as a string of characters is returned. 
This is exactly the same as print(fn, x), except that the output is returned 
as a sequence of characters, rather than being sent to a file or device. x 
can be any Euphoria object.

Comments: The atoms contained within x will be displayed to a maximum of 10 
significant digits, just as with print().

Example 1:
s = sprint(12345)
-- s is "12345"

Example 2:
s = sprint({10,20,30}+5)
-- s is "{15,25,35}"

>
>cheers,
>Derek Parnell

new topic     » goto parent     » topic index » view message » categorize

9. Re: value()

On Tue, Feb 18, 2003 at 01:18:12AM +0000, Pete Lomax wrote:
> 
> Hey gang blink,
> 
> trying to parse STR, value(STR) is returning {GET_SUCCESS, SOMEVAL}.
> 
> 1) is there any way to tell how much of STR value() "ate"?

You'd have to modify the Get() procedure in get.e, to return the value
of the integer string_next. (Or maybe get_ch(). I dunno.)

Or, make the variable string_next global instead of local. Or add a new
function to return the value of string_next() (and, if reading from a file,
perhaps to return the value of where()).

> 
> 2) what is the simplest way to get SOMEVAL as returned back from
> value() into a character string again? I'll do it if I have to, no
> worry, but there just *must* be a better way than puts(fn,SOMEVAL) and
> reading it back in again!

Use sprint(), or get print.e (which makes a human-readable string, i.e.
{65, 66, 67} becomes "ABC").

> 
> Pete
> 

jbrown

> ==^^===============================================================
> This email was sent to: jbrown1050 at hotpop.com
> 
> 
> TOPICA - Start your own email discussion group. FREE!

-- 
 /"\  ASCII ribbon              | http://www.geocities.com/jbrown1050/
 \ /  campain against           | Linux User:190064
  X   HTML in e-mail and        | Linux Machine:84163
 /*\  news, and unneeded MIME   |

new topic     » goto parent     » topic index » view message » categorize

10. Re: value()

Heello,
	From what you say, iit is likely that my val() function solves this. It
is in the utilities for EuRegExp.
	This function is given a sequence (hopefully of chars) and returns a
sequence with three terms. First is the value read, if any (or 0),
second is the number of chars this ate (0 if no value read). Third is
for handling values that are atoms rather thah integers. Doesn't handle
floats though - I didn't need that in the context-, but handles hex
numbers as well.
	HTH
	CChris

> ------------------------------
> 
> Date: Tue, 18 Feb 2003 01:18:12 +0000
> From: Pete Lomax <petelomax at blueyonder.co.uk>
> Subject: value()
> 
> Hey gang blink,
> 
> trying to parse STR, value(STR) is returning {GET_SUCCESS, SOMEVAL}.
> 
> 1) is there any way to tell how much of STR value() "ate"?
> 
> 2) what is the simplest way to get SOMEVAL as returned back from
> value() into a character string again? I'll do it if I have to, no
> worry, but there just *must* be a better way than puts(fn,SOMEVAL) and
> reading it back in again!
> 
> Pete
>

new topic     » goto parent     » topic index » view message » categorize

11. Re: value()

On Mon, 17 Feb 2003 23:37:15 -0500, Elliott Sales de Andrade
<quantum_analyst at hotmail.com> wrote:

>Perhaps you mean sprint().

Cheers! Must have got a bit blinkered by sprintf, or just getting a
bit blind in my old age!

Pete

new topic     » goto parent     » topic index » view message » categorize

12. Re: value()

Hi Derek,

you wrote:

<snip>
> This will work for both integers and floating point values...
>
>       x = sprintf("%.16g",SOMEVAL)
>
> It displays it at maximum precision which is 16 digits with trailing zeros
> removed and leading spaces removed.

I've been looking for something like this, thanks!
Then, I thought 'sprint(SOMEVAL)' would do the same, but looking into
misc.e, I see:

global function sprint(object x)
   sequence s

   if atom(x) then
      return sprintf("%.10g", x)
   else
   [...]
   end if
end function

Well, this is also in the docs for sprint(). Anyway, I wonder why
sprint() doesn't return as many digits as possible.

>  cheers,
> Derek Parnell

Best regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  |  while not asleep do
 \ /  against HTML in       |     sheep += 1
  X   e-mail and news,      |  end while
 / \  and unneeded MIME     |

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu