And you can use > (number->string (exact->inexact 0.75))
to get numbers printed in decimal notation. It's slightly distracting/annoying, but in class I can briefly explain that there is a distinction between exact and inexact numbers in BSL, and that the former print as rationals (fractions), and the latter in decimal notation. --- nadeem On Wed, Feb 18, 2015 at 7:35 AM, Robby Findler <ro...@eecs.northwestern.edu> wrote: > In the teaching languages, decimal syntax for numbers does not imply > inexactness. The only way to get inexact numbers is to call something > like sqrt or sin. So, there, the number 0.75 and the number 3/4 are > the same exact number (exact same exact number?). > > The printing code is the same (well, it is the same for exact numbers. > Inexact numbers print with a #i prefix). > > Robby > > > On Wed, Feb 18, 2015 at 2:32 AM, Alexis King <lexi.lam...@gmail.com> > wrote: > > This is interesting behavior. To explain why it happens, this has > something > > to do with how the HtDP languages handle exact/inexact numbers. For > example, > > in plain Racket, (exact? 0.75) is #f, but in BSL, it is #true. In BSL, > > numbers are exact unless otherwise specified. Note that explicitly using > an > > exactness prefix in plain Racket, #e0.75, produces 3/4. > > > > What’s odd is that the convention for printing numbers in BSL is > different > > from the convention used by number->string. BSL, unlike Racket, prints > exact > > numbers as decimals. I’d expect that this is to avoid confusion when > > students type in decimals only to have them printed in large fractions. > > Unfortunately, it would seem that number->string simply uses the plain > > Racket implementation, which lets the odd implementations details “leak > > through” the abstraction. > > > > It does feel like poor behavior to me. I’d expect number->string to > follow > > the same printing conventions BSL uses. > > > > On Feb 18, 2015, at 00:17, Breanndán Ó Nualláin <b...@science.uva.nl> > wrote: > > > > In BSL, I just got caught out by this behaviour: > > > > (number->string 0.75) > > > > "3/4" > > > > I expected the same behaviour as in the full Racket language: > > > > (number->string 0.75) > > > > "0.75" > > > > What's the thinking behind this? Wouldn't the decimal notation be more > > intuitive, particularly in cases like this? > > > > (number->string 0.7555555) > > > > "1511111/2000000" > > > > And especially in cases like this? > > > > (number->string (string->number (number->string pi))) > > > > "3141592653589793/1000000000000000" > > ____________________ >
____________________ Racket Users list: http://lists.racket-lang.org/users