URLs as first-class concepts in a language

how-to
Feb 23, 20082 mins

While perusing the E Tutorial, I noticed something that was simple and powerful all at the same time: URLs as first-class concepts in the language. Or, if you will, URLs as a factory for creating objects. Check out this snippet of E:

? pragma.syntax(<span style="color: #006080">"0.8"</span>)
? def poem := <http:<span style="color: #008000">//<a href="https://www.erights.org/elang/intro/jabberwocky.txt">www.erights.org/elang/intro/jabberwocky.txt</a>></span> #
value: <http:<span style="color: #008000">//<a href="https://www.erights.org/elang/intro/jabberwocky.txt">www.erights.org/elang/intro/jabberwocky.txt</a>></span> ?
<file:c:/jabbertest>.mkdirs(<span style="color: #0000ff">null</span>); ? <file:c:/jabbertest/jabberwocky.txt>.setText(poem.getText())

Notice how the initialization of the “poem” variable is set to what looks like an HTTP URL? This essentially downloads the contents of that file and stores it into poem (in a form I don’t precisely understand yet–I think it’s an object that wraps the contents, but I could be wrong). Then the script uses file URLs to create the local directory (jabbertest) and to create a new file (jabberwocky.txt) and set the contents of that file to be the same as the contents of the stored “poem” object.

That, my friends, is just slick. It also neatly avoids the whole “how are files and directories and stuff different from URLs” that tends to make doing this same bit of code in Java or C# that much more difficult.


Enterprise consulting, mentoring or instruction. Java, C++, .NET or XML services. 1-day or multi-day workshops available. Contact me for details.

ted_neward

Ted Neward is an independent consultant specializing in high-scale enterprise systems, working with clients ranging in size from Fortune 500 corporations to small 10-person shops. He is an authority in Java and .NET technologies, particularly in the areas of Java/.NET integration (both in-process and via integration tools like Web services), back-end enterprise software systems, and virtual machine/execution engine plumbing. He lives in the Pacific Northwest with his wife, two sons, and eight PCs.

More from this author