Preparing for my upcoming ILC talk led me to some old Common
Lisp email archives where I came across this proposal from Guy
Steele:
Date: 11 June 1982 2233-EDT (Friday) From: Quux To: bug-lisp at MIT-AI, bug-lispm at MIT-AI, common-lisp at SU-AI Subject: Proposed new FORMAT operator: ~U("units") Here's a krevitch that will really snork your flads. ~U swallows an argument, which should be a floating-point number (an integer or ratio may be floated first). The argument is then scaled by 10^(3*K) for some integer K, so that it lies in [1.0,1000.0). If this K is suitably small, then the scaled number is printed, then a space, then a metric-system prefix. If not, then the number is printed in exponential notation, then a space. With a :, prints the short prefix. Examples: (FORMAT () "~Umeters, ~Uliters, ~:Um, ~:UHz" 50300.0 6.0 .013 1.0e7) => "50.5 kilometers, 6.0 liters, 13.0 mm, 10.0 MHz" And you thought ~R was bad!
Later he made this small addition:
Date: 12 June 1982 1119-EDT (Saturday) From: Quux To: bug-lisp at MIT-AI, bug-lispm at MIT-AI, common-lisp at SU-AI Subject: More on ~U (short) I forgot to mention that the @ flag should cause scaling by powers of 2^10 instead of 10^3: (format () "~Ubits, ~:Ub, ~@Ubits, ~:@Ub" 65536 65536 65536 65536) => "65.536 kilobits, 65.536 Kb, 64.0 kilobits, 64.0 Kb" --Q
October 7, 2010 at 6:43 pm |
my flads are suitably snorked!
October 8, 2010 at 4:57 pm |
The ~U format directive reminds me of Frink ( http://futureboy.us/frinkdocs/ ), which is the only programming language to excite me since Common Lisp. I’ve been meaning to write some sort of Frink-like library or toy for CL when I get some free time, which means never.
I hope my flads recover soon.
October 8, 2010 at 5:05 pm |
Very amusing!
October 12, 2010 at 1:11 pm |
When I first created “format” by adapting Multics’s ioa_, I had no idea that I was releasing a flood of creativity. I was at the OOPSLA last year, and someone giving a talk was criticizing the complexity of Lisp’s “format”, and I piped up and said “mea culpa”, although the real hair is from Steele. I continue to be dubious about the iteration construct.
However, this proposed ~u is completely in line with what format is for: formatting things, especially numbers.
I wonder why we didn’t accept it?
October 12, 2010 at 2:36 pm |
Hi Dan, I didn’t realize you were the father of FORMAT. Anyway, I think the iteration construct is the feature of FORMAT I use most often, possibly edged out by ~:d to get a commafied number.
May 11, 2011 at 7:22 am |
snorking.
It typifies the baroqueness of that section of Common Lisp, I too wonder why it didn’t get blessed by the standard.
Doesn’t work so well for higher-dimensional units:
1,000,000 m² = 1 km² (not 1 Mm² which is what ~U would give me).
May 11, 2011 at 12:42 pm |
drj11, I’m pretty sure that could be handled by allowing a numeric argument to the directive.
(format nil “~2:um^2” (expt 10 6)) ==> “1 km^2”
(format nil “~3:um^3” (expt 10 9)) ==> “1 km^3”
-Peter
May 11, 2011 at 3:13 pm |
Yeah, I thought the same thing. We should be careful though, lest someone actually implement it and starts using it.
August 13, 2012 at 10:00 am |
[…] via Peter Seibel, who has much more context on his blog post. Like this:LikeBe the first to like this. […]