Message: 7
Date: Fri, 2 Dec 2005 10:23:04 +0100
From: Kevin Glynn <[EMAIL PROTECTED]>
Subject: Oz Newbie: Display of unary minus
To: Anthony Borla <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED]
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=us-ascii

Kevin,

> > Anthony Borla writes:
> > Greetings,
> >
> > Ouput from the following code:
> >
> >   {System.showInfo ~1}          %% (1)
> >   {System.showInfo ~1.0}       %% (2)
> >
> >   {System.showInfo {VirtualString.changeSign
> >                         {IntToString ~1} &-}}
> >   {System.showInfo {VirtualString.changeSign
> >                         {IntToString ~1} "-"}}
> >
> > is:
> >
> >   -1
> >   -1.0
> >   ~1
> >   ~1
> >
> > Obviously some sort of implicit conversion is being
> > performed at (1) and (2).
> >
>
> I am a bit confused about your question.  ~1 is the lexical
> string that reprsents -1.  So the lexer/parser turns the
> string ~1 into an internal value of -1.  ShowInfo prints -1
> as the string "-1"
>

This line:

    {System.showInfo ~1}

displays:

    -1

There is code - [I'd assumed] an Oz procedure - being used within
'System.showInfo' that is converting:

    ~1

to:

    -1

I wanted to know what Oz procedure that might be. I'd assumed it to be,
'VirtualString.changeSign', but wanted confirmation of that. My attempts to
use it to perform the 'sign change' did not work.

>
> This behaviour is sort of hinted at in the documentation of
> VirtualString.toString:
>
>" The transformation is straightforward: Atoms (except nil and '#'),
>  integers, floats and byte strings are transformed into strings using
>  Atom.toString, Int.toString, Float.toString, and ByteString.toString
>  respectively, where in numbers - is used instead of ~."
>
> IntToString converts the value -1 into the string "~1" (as per
> documentation it converts to a string in Oz Concrete syntax)
>
> >
> > My question is: what routine(s) need to be called in order to
> > explicitly perform this task ?
> >
>
> What task do you want to perform?
>

Have [1 could be any value]:

    ~1

converted to:

    -1

> >
> > I would have thought it was 'VirtualString.changeSign',
> > but all my attempts to so use it are failing.
> >
>
> See the difference in:
>
> {System.showInfo ~3.14}
> {System.showInfo {VirtualString.changeSign ~3.14 '~'}}
>
> Hope this helps
>

Indeed -*yes* - with a minor edit:

    {System.showInfo {VirtualString.changeSign ~3.14 '-'}}

that *does* help :) !

It would seem I was correct about the Oz procedure, but needed to specify
the minus sign as an atom, and not as either a character, or list, as in
both my non-working examples.

In hindsight my question should simply have been:

    "Why doesn't my invocation of 'VirtualString.changeSign' work ?"

Of course, that is with hindsight !

The question cropped up because I've been using a small library of floating
point formatting procedures [i.e. justify, round, and otherwise format
floating point numbers], but negative values appeared with ~, and when
displayed with 'showInfo', remained as ~, not an acceptable outcome.

I quickly added the following code:

    {Map VS fun {$ C} if C == &~ then &- else C end end}

to effect the appropriate transformation, but wanted to perform this task
the Oz-idiomatic way, which led me to use 'VirtualString.changeSign', but,
as mentioned, this [at least as I used it] didn't work.

All clear now - thanks again, Kevin :) !

Cheers,

Anthony Borla


_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to