<div dir="ltr">And you can use <div><br><div>> (number->string (exact->inexact 0.75)) </div><div><br></div><div>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. <div><br><div class="gmail_extra">--- nadeem<br clear="all"><div><div><br></div></div>
<br><div class="gmail_quote">On Wed, Feb 18, 2015 at 7:35 AM, Robby Findler <span dir="ltr"><<a href="mailto:robby@eecs.northwestern.edu" target="_blank">robby@eecs.northwestern.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In the teaching languages, decimal syntax for numbers does not imply<br>
inexactness. The only way to get inexact numbers is to call something<br>
like sqrt or sin. So, there, the number 0.75 and the number 3/4 are<br>
the same exact number (exact same exact number?).<br>
<br>
The printing code is the same (well, it is the same for exact numbers.<br>
Inexact numbers print with a #i prefix).<br>
<span><font color="#888888"><br>
Robby<br>
</font></span><div><div><br>
<br>
On Wed, Feb 18, 2015 at 2:32 AM, Alexis King <<a href="mailto:lexi.lambda@gmail.com" target="_blank">lexi.lambda@gmail.com</a>> wrote:<br>
> This is interesting behavior. To explain why it happens, this has something<br>
> to do with how the HtDP languages handle exact/inexact numbers. For example,<br>
> in plain Racket, (exact? 0.75) is #f, but in BSL, it is #true. In BSL,<br>
> numbers are exact unless otherwise specified. Note that explicitly using an<br>
> exactness prefix in plain Racket, #e0.75, produces 3/4.<br>
><br>
> What’s odd is that the convention for printing numbers in BSL is different<br>
> from the convention used by number->string. BSL, unlike Racket, prints exact<br>
> numbers as decimals. I’d expect that this is to avoid confusion when<br>
> students type in decimals only to have them printed in large fractions.<br>
> Unfortunately, it would seem that number->string simply uses the plain<br>
> Racket implementation, which lets the odd implementations details “leak<br>
> through” the abstraction.<br>
><br>
> It does feel like poor behavior to me. I’d expect number->string to follow<br>
> the same printing conventions BSL uses.<br>
><br>
> On Feb 18, 2015, at 00:17, Breanndán Ó Nualláin <<a href="mailto:bon@science.uva.nl" target="_blank">bon@science.uva.nl</a>> wrote:<br>
><br>
> In BSL, I just got caught out by this behaviour:<br>
><br>
> (number->string 0.75)<br>
><br>
> "3/4"<br>
><br>
> I expected the same behaviour as in the full Racket language:<br>
><br>
> (number->string 0.75)<br>
><br>
> "0.75"<br>
><br>
> What's the thinking behind this? Wouldn't the decimal notation be more<br>
> intuitive, particularly in cases like this?<br>
><br>
> (number->string 0.7555555)<br>
><br>
> "1511111/2000000"<br>
><br>
> And especially in cases like this?<br>
><br>
> (number->string (string->number (number->string pi)))<br>
><br>
> "3141592653589793/1000000000000000"<br>
> ____________________<br></div></div></blockquote></div></div></div></div></div></div>