Standard IO syntax and the Robustness Principle
By Didier Verna on Friday, October 27 2017, 11:24 - Lisp - Permalink
Here is a flagrant illustration of the robustness principle, or rather, of a failure to honor it.
I was investigating a bug in Declt where some floating point numbers were printed with exponent markers (e.g. 0.5f0
instead of just 0.5
) in the Texinfo file, which broke the parsing of the file by Perl.
Eventually, I found out a double infringement of the robustness principle. First of all, Declt failed to comply with part 1 of the robustness principle: be lenient with the others. The Texinfo file generation routine should have been wrapped into a call to WITH-STANDARD-IO-SYNTAX
and it wasn't. Always do that to be on the safe side. Lesson learnt.
This failure on my part, however, had the interesting consequence of exhibiting what I consider a serious infringement of part 2 of the robustness principle: be strict with yourself. It would have remained unnocited otherwise. The culprit here is not Declt. This time, it's the common-lisp-stat library. Problem: the simple fact of loading this library globally changes the value of *READ-DEFAULT-FLOAT-FORMAT*
from SINGLE-FLOAT
(the default) to DOUBLE-FLOAT
. This is bad, and it can break your code in all sorts of nasty ways.
Explanation
*READ-DEFAULT-FLOAT-FORMAT*
tells the reader how to read floats when no exponent marker is provided. By default, 0.5
will be read as a SINGLE-FLOAT
. But this variable also influences the printer (out of a concern for printing readably I guess): when printing a float of a different format than the current default, then the appropriate exponent marker is also printed. So here is precisely what happened. Declt had been compiled with some floats (e.g. 0.5
) read as SINGLE-FLOAT
s. Later on, those floats were supposed to be printed aesthetically as such. But right after loading common-lisp-stat, the default format changed to DOUBLE-FLOAT
and all of a sudden 0.5
started to be printed as 0.5f0
.
Consequences
This is bad enough already, but consider that messing with the standard IO syntax globally like this can break your code in all other sorts of even nastier ways. Imagine for instance that common-lisp-stat had been loaded before Declt, and Declt needed to be recompiled. All of a sudden, Declt would be using double floats and the bug would be gone. That is, until the next start of the REPL, after which all floats would be printed like 0.5d0
!
So granted, my code wasn't robust enough. But please, don't mess with standard IO syntax globally!
Comments
Hi Dear, are you actually visiting this site regularly, if so afterward you will absolutely
get pleasant knowledge.
What's up, every time i used to check blog posts here in the early hours in the break of day, as i love to
learn more and more.
continuously i used to read smaller posts which as well clear their
motive, and that is also happening with this article which
I am reading here.
Fantastic items from you, man. I have remember your stuff previous
to and you're simply too wonderful. I actually like what you have
received right here, really like what you are saying and the best way through which you say it.
You make it enjoyable and you still take care of to keep it
wise. I cant wait to learn far more from you. That is really a tremendous site.
This is a very good tip particularly to those new to the blogosphere.
Simple but very precise info… Thanks for sharing this one.
A must read post!
My developer is trying to convince me to move to .net from PHP.
I have always disliked the idea because of the expenses. But he's tryiong none the
less. I've been using WordPress on various websites for about a year and am nervous
about switching to another platform. I have heard excellent things
about blogengine.net. Is there a way I can transfer all my wordpress
posts into it? Any kind of help would be really appreciated!
I got this site from my friend who told me regarding this website and at the moment this time I am browsing this web page and reading very informative articles at this time.
Hi there, I would like to subscribe for this website to get most recent updates, so where can i do it please help.
Appreciate this post. Will try it out.
What's up, after reading this awesome paragraph i am too glad to share
my familiarity here with mates.
I think this is among the so much vital info for me.
And i am glad reading your article. However want to statement on some normal issues, The website taste
is wonderful, the articles is in point of fact nice : D.
Good activity, cheers
Excellent beat ! I would like to apprentice while you
amend your website, how could i subscribe for a weblog web site?
The account helped me a acceptable deal. I have been a little bit familiar of this your broadcast provided brilliant transparent idea
Greetings! Very helpful advice in this particular post!
It's the little changes that will make the biggest changes.
Many thanks for sharing!
Thanks on your marvelous posting! I truly enjoyed reading it, you may be a great author.
I will remember to bookmark your blog and definitely will come back down the
road. I want to encourage you continue your great writing, have a nice day!
Greetings from Florida! I'm bored to death at work so I decided to check out your website on my iphone during lunch break.
I really like the information you provide here and can't wait to
take a look when I get home. I'm amazed at how quick your blog loaded on my mobile ..
I'm not even using WIFI, just 3G .. Anyhow, superb blog!
Pretty component to content. I just stumbled upon your weblog and in accession capital to
say that I get actually loved account your blog posts. Anyway I will be subscribing in your augment or even I achievement you get admission to persistently rapidly.
Hi there just wanted to give you a quick heads up. The text in your post seem
to be running off the screen in Chrome. I'm not sure if this is a format issue or
something to do with web browser compatibility but I thought
I'd post to let you know. The design and style look great though!
Hope you get the problem fixed soon. Thanks
magnificent issues altogether, you just gained a new reader.
What could you recommend in regards to your post that you simply made a few days ago?
Any positive?
Hello, i think that i saw you visited my website thus i came to
“return the favor”.I am trying to find things to improve my site!I
suppose its ok to use a few of your ideas!!
Heya are using Wordpress for your blog platform?
I'm new to the blog world but I'm trying to get started and
set up my own. Do you require any html coding knowledge to make
your own blog? Any help would be really appreciated!
We're a group of volunteers and starting a new scheme in our community.
Your site provided us with valuable information to work on. You've done a formidable job
and our entire community will be thankful to you.
I like what you guys are usually up too. This sort of clever work and exposure!
Keep up the fantastic works guys I've added you guys to my personal blogroll.
Inspiring story there. What happened after? Thanks!
I'm gone to say to my little brother, that he should also pay a quick visit this blog on regular basis to take updated from
latest information.
I am really enjoying the theme/design of your blog.
Do you ever run into any web browser compatibility issues?
A small number of my blog visitors have complained about my website not operating correctly in Explorer
but looks great in Safari. Do you have any recommendations
to help fix this problem?
all the time i used to read smaller posts which also clear their motive, and
that is also happening with this article which I am reading
at this place.
Very energetic post, I loved that bit. Will there be a part 2?
asocialnemu buy stromectol for humans online ucebniciach where to get
stromectol buy stromectol 3mg - stromectol/purchase [url=http://stromectoles.com/#]order stromectol 3mg[/url] edudonelson how to buy stromectol
coitus stromectol "eye worm" verludert ivermectin 3mg tablet can you buy hydroxychloroquine over
the counter - 0.2 mg/kg is how many 3 mg stromectol tablets [url=http://hydroxychloroquine.pro/#]hy... online[/url] sidemetest
stromectol where to buy
thats really help me out