Newsgroups: comp.lang.apl
Path: watmath!watserv1!utgpu!news-server.csri.toronto.edu!rpi!think.com!ames!haven.umd.edu!socrates!socrates!rockwell
From: rockwell@socrates.umd.edu (Raul Deluth Miller-Rockwell)
Subject: Re: Which language can write this but Perl
In-Reply-To: hui@yrloc.ipsa.reuter.COM's message of Mon, 2 Mar 92 05:28:37 GMT
Message-ID: <ROCKWELL.92Mar3004533@socrates.umd.edu>
Sender: rockwell@socrates.umd.edu (Raul Deluth Miller-Rockwell)
Organization: Traveller
References: <9202280836.AA12817@menora.weizmann.ac.il>
	<1992Mar2.052837.15235@yrloc.ipsa.reuter.COM>
Date: Tue, 3 Mar 1992 05:45:33 GMT

[put comp.lang.misc back in distribution if you want to say something
pertaining to the original subject thread.]

Dov Grobgeld writes:
   >   #!/usr/local/bin/perl -p
   >   s|(\d+\.?(\d+)?)\s*inch| sprintf("%0.2f cm", $1 / 2.54); |eg;

Roger Hui:
       ;@(<@(,&(' cm',10{a.))@(%&2.54&.".)@(_4&}.);._2)


Um....  here's a sample paragraph:

If you take a piece of paper 8.5 inches by 11 inches and fold it in
half, you'll get a folded piece of paper.  But if you take a piece of
wood 2 by 4 by 12 inches and fold it in half you'll get a splintered
piece of wood.  If you heat water to 100 degrees centigrade, you'll
get hot water.

Here's what you get when you pass that paragraph through Dov
Grobgeld's perl program:

If you take a piece of paper 3.35 cmes by 4.33 cmes and fold it in
half, you'll get a folded piece of paper.  But if you take a piece of
wood 2 by 4 by 4.72 cmes and fold it in half you'll get a splintered
piece of wood.  If you heat water to 100 degrees centigrade, you'll
get hot water.


The closest I've been able to get to this using a simple J program is
the following:

s=.'cm'&[^:('inch'&-:)
f=.(+._1&|.)@:-. @e.&('0123456789.inch')
x=.'''s y.''".''":2.54%~'',y.':''
dov=.;@:(< @x;.1~f)

Here's the result of passing the above paragraph through that J
program:

If you take a piece of paper 3.34646 cmes by 4.33071 cmes and fold it in
half, you'll get a folded piece of paper.  But if you take a piece of
wood 0.787402 by 1.5748 by 4.72441 cmes and fold it in half you'll get a splintered
piece of wood.  If you heat water to 39.3701 degrees centigrade, you'll
get hot water.

Obviously, I'm ignoring information, like 'inch' is adjacent to '12'
but not adjacent to '100'.  Also, I'm not providing any rounding
(partially because the program would provide much nicer output if one
multiplied by 2.54 instead of divided).

Anyways, the class of problem posed here (partitioning text for
selective function application) is not one for which I've a concise J
solution.

-- 
Raul Deluth Miller-Rockwell                   <rockwell@socrates.umd.edu>
