Hello list,
I still read some Java news every now and then, and last week, I came across
these:
http://java.sun.com/developer/JDCTechTips/2004/tt1201.html
http://weblogs.java.net/blog/pat/archive/2004/10/stupid_scanner_1.html
Here's a synopsis:
As some of you must know, reading a URL with Java is a time consuming
enterprise:
InputStream source = new URL("http://some.url/path/file.html").openStream();
BufferedReader br = new BufferedReader( new InputStreamReader( source ) );
String text = "";
for ( String line; (line = br.readLine()) ! = null )
text.concat( line );
Now, finally, Java introduces a new class that can turn this into a one-liner
(according to Pat Niemeyer):
String text = new Scanner(new
URL("http://some.url/path/file.html").openStream()).useDelimiter("\\A").next();
(Pat only put in the variable "source" to construct the Scanner, so I had to
replace it with the URL constructor. Nice one-liner, eh?)
I send this not only to make fun of the Java programming language, but also to
remind us all of the really neat simplicity we have in rebol:
text: read http://some.url/path/file.html
I also advice you to read the JDCTechTip about the scanner class. It seems to
behave a bit like 'parse does when not using a rule but a set of delimiters.
Only Java (using Java.util.Scanner) needs 41 lines of code to do this:
Assume you have these lines in a file named Employee.data:
Joe, 38, true
Kay, 27, true
Lou, 33, false
To produce this output:
It is true that Joe, age 38, is certified.
It is true that Kay, age 27, is certified.
It is false that Lou, age 33, is certified.
You need 10 lines of code in Rebol:
REBOL []
either system/script/args [
text: read to-file system/script/args
foreach [name age certified?] parse text "^/" [
print ["It is" certified? "that" name "age" age "is certified"]
]
][
print "usage: short.r filename"
]
HY
Pr�tera censeo Carthaginem esse delendam
--
To unsubscribe from the list, just send an email to rebol-request
at rebol.com with unsubscribe as the subject.