1 | <BASE HREF="http://www.unixreview.com/documents/s=2425/uni1016550801055/"> |
---|
2 | <html> |
---|
3 | <head> |
---|
4 | <TITLE>Regular Expressions: Erlang Is Worth a Look</TITLE> |
---|
5 | <!-- hide from older browsers, should show em anyway so they will upgrade--> |
---|
6 | <LINK REL=stylesheet HREF="/unxrev.css" TYPE="text/css"> |
---|
7 | <META http-equiv="expires" content="-1"> |
---|
8 | <META http-equiv= "pragma" CONTENT="no-cache"> |
---|
9 | <META name="author" content="Randy Reames"> |
---|
10 | <META name="ROBOTS" content="ALL"> |
---|
11 | <META name="description" content="News, reviews, features, and commentary for Unix and Linux professionals."> |
---|
12 | <META name="KEYWORDS" content="UNIX, open source, security, unix, storage, BSD, Linux, Red Hat, Debian, Suse, solaris, AIX, HP-UX, database, linux training, unix training, certification, backup, system administration, intrusion detection, reviews, XML, network, Perl, Shell, TCP/IP, secure shell"> |
---|
13 | </HEAD> |
---|
14 | <BODY bgColor=#FFFFFF leftMargin=0 rightMargin=0 topMargin=4 marginheight="4"> |
---|
15 | <A name="top"></A> |
---|
16 | <TABLE border=0 cellpadding=3 cellspacing=0 width="98%"> |
---|
17 | <TR> |
---|
18 | <TD width="125" align="center" valign="middle"><A href="/"> </A><IMG src="/cmp_logo.gif" width="69" height="59"> |
---|
19 | </TD> |
---|
20 | <TD align=left valign="top" width="160"> |
---|
21 | <P> <A href="/"><IMG alt="Welcome to UnixReview.com" border=0 |
---|
22 | src="/logosm.gif" width="151" height="89"></A> |
---|
23 | </TD> |
---|
24 | <TD align="right" valign="middle"> |
---|
25 | <A target="_top" href="http://newads.cmpnet.com/event.ng/Type=click&ProfileID=6941&RunID=41981&AdID=31293&GroupID=1&FamilyID=2784&TagValues=178.2994&Redirect=https://www.sdmediagroup.com/circ/subscribe.cgi%3Fuser_keycode%3D2cck"><IMG src="http://img.cmpnet.com/ads/graphics/cs/ar/cuj_sub_468.gif" border=1 height=60 width=468 alt=""></A> </TD> |
---|
26 | </TABLE> |
---|
27 | |
---|
28 | <TABLE border=0 cellPadding=0 cellSpacing=0 width="98%"> |
---|
29 | <TR> |
---|
30 | <TD vAlign=top width=125 align="center"> |
---|
31 | <TABLE bgcolor=#000000 border=0 cellpadding=0 cellspacing=0 |
---|
32 | width="100%"> |
---|
33 | <TR> |
---|
34 | <TD> |
---|
35 | <TABLE border=0 cellpadding=3 cellspacing=1 width="100%"> |
---|
36 | <TR bgcolor="#CCCCCC" align="center" valign="top"> |
---|
37 | <TD class="bluetop">Main Menu</TD> |
---|
38 | </TR> |
---|
39 | <TR align="left" valign="top" bgcolor="#FFFFFF"> |
---|
40 | <TD class="bluebottom" nowrap> <A href="/" class="sidenav">Home</A><BR> |
---|
41 | <A href="/articles/" class="sidenav">Archives</A><BR> |
---|
42 | <A href="/reviews/" class="sidenav">Reviews<BR> |
---|
43 | </A> <A href="/articles/books/" class="sidenav">Books</A><BR> |
---|
44 | <A href="/glink/" class="sidenav">Geek Links</A><BR> |
---|
45 | <A href="/people/" class="sidenav">Contact Us</A> |
---|
46 | </TD> |
---|
47 | </TR> |
---|
48 | </TABLE> |
---|
49 | </TD> |
---|
50 | </TR> |
---|
51 | </TABLE> |
---|
52 | <BR> |
---|
53 | <TABLE bgcolor=#000000 border=0 cellpadding=0 cellspacing=0 |
---|
54 | width="100%"> |
---|
55 | <TR> |
---|
56 | <TD align="left" valign="top"> |
---|
57 | <TABLE border=0 cellpadding=3 cellspacing=1 width="100%"> |
---|
58 | <TR bgcolor="#CCCCCC" align="center" valign="top"> |
---|
59 | <TD class="bluetop">Sections</TD> |
---|
60 | </TR> |
---|
61 | <TR bgcolor="#FFFFFF"> |
---|
62 | <TD class="bluebottom" nowrap align="left" valign="top"> |
---|
63 | <A href="/columns/laird/" class="sidenav">Regular <BR> |
---|
64 | Expressions</A><BR> |
---|
65 | <A href="/tool/" class="sidenav">Tool of the Month</A><BR> |
---|
66 | <A href="/opensource/" class="sidenav">Open |
---|
67 | Source</A><BR> |
---|
68 | <A href="/certify/" class="sidenav">Certification</A><BR> |
---|
69 | <A href="/columns/schaefer/" class="sidenav">Shell |
---|
70 | Corner</A><BR> |
---|
71 | |
---|
72 | <A href="/columns/preston/index.htm" class="sidenav">lost+found</A> |
---|
73 | |
---|
74 | </TD> |
---|
75 | </TR> |
---|
76 | </TABLE> |
---|
77 | </TD> |
---|
78 | </TR> |
---|
79 | </TABLE> |
---|
80 | <P> <A target="_top" href="http://newads.cmpnet.com/event.ng/Type=click&ProfileID=6948&RunID=41296&AdID=30834&GroupID=1&FamilyID=1&TagValues=2994.3003&Redirect=http://www.usenix.org/events/usenix02/"><IMG src="http://img.cmpnet.com/ads/graphics/cs/ar/usenix_2002_125.gif" border=1 height=125 width=125 alt="Click Here!"></A> |
---|
81 | <P> |
---|
82 | <FORM ACTION="/search.htm" METHOD="GET"> |
---|
83 | <INPUT type="text" name="search" size=12> |
---|
84 | <BR> |
---|
85 | <INPUT type="image" src="/search2.gif" alt="Search" border="0" value="Search" name="submit"> |
---|
86 | </FORM> |
---|
87 | <P> |
---|
88 | <TABLE bgcolor=#000000 border=0 cellpadding=0 cellspacing=0 |
---|
89 | width="100%"> |
---|
90 | <tbody> |
---|
91 | <TR> |
---|
92 | <TD> |
---|
93 | <TABLE border=0 cellpadding=3 cellspacing=1 width="100%"> |
---|
94 | <tbody> |
---|
95 | <TR align="center" valign="top"> |
---|
96 | <TD bgcolor=#cccccc class="bluetop">Newsletter</TD> |
---|
97 | </TR> |
---|
98 | <TR align="center"> |
---|
99 | <TD bgcolor=#ffffff class="bluebottom"><A href="/subscribe/index.htm"><IMG src="/newsletter.gif" width="120" height="69" border="0" alt="Get the Newsletter"><BR> |
---|
100 | Get the Newsletter</A> </TD> |
---|
101 | </TR> |
---|
102 | </tbody> |
---|
103 | </TABLE> |
---|
104 | </TD> |
---|
105 | </TR> |
---|
106 | </tbody> |
---|
107 | </TABLE> |
---|
108 | <BR> |
---|
109 | </TD> |
---|
110 | <TD> </TD> |
---|
111 | <TD vAlign=top align="left"> |
---|
112 | |
---|
113 | |
---|
114 | <A href="/print/documentID=24422">Print-Friendly Version</A><BR><BR> |
---|
115 | |
---|
116 | <TABLE cellSpacing=0 cellPadding=3 width="100%" border=0> |
---|
117 | <TBODY> |
---|
118 | <TR vAlign=center bgColor=#dedbce> |
---|
119 | <TD class=headline align=left>Regular Expressions: Erlang Is Worth a Look</TD> |
---|
120 | <TD class=headdate align=right>March 2002</TD> |
---|
121 | </TR> |
---|
122 | <TR vAlign=top align=left> |
---|
123 | <TD colSpan=2> |
---|
124 | <P> by Cameron Laird and Kathryn Soraiz |
---|
125 | <P> |
---|
126 | Let's write highly-reliable, high-performance distributed applications. |
---|
127 | While we're at it, let's choose a development language with a "track |
---|
128 | record" of high productivity. |
---|
129 | <P> |
---|
130 | We'll use the Erlang programming language. |
---|
131 | <P> |
---|
132 | <H2>Erlang for Real</H2> |
---|
133 | <P> The name "Erlang" honors a Danish mathematician by that name, |
---|
134 | whose work in stochastic theories flourished at the beginning of the twentieth |
---|
135 | century. Although Erlang's name-recognition is low among U.S. programmers |
---|
136 | ("Erlang? Isn't that one of the new Winter Olypmics events?"), its accomplishments |
---|
137 | are plenty serious. First implemented in 1986 by an engineer at Ericsson |
---|
138 | Enterprise, Erlang is the language in which many production telecommunications |
---|
139 | and other mission-critical applications are written. Its use on general-purpose |
---|
140 | "personal computers" and servers is also growing. |
---|
141 | <P> One of the reasons for the interest in Erlang is that the software world |
---|
142 | is finally acknowledging the importance of distributed computation. This |
---|
143 | has been a good season for distributed computing -- <I>Scientific American</I> |
---|
144 | has popularized the topic; the new Usenet newsgroup comp.distributed has |
---|
145 | hosted a handful of worthwhile discussions since its launch in mid-February; |
---|
146 | and the Global Grid Forum (<A href="http://www.gridforum.org/" target="_blank">http://www.gridforum.org/</A>) |
---|
147 | has become one of the hottest events in computing. Ideas about large-scale |
---|
148 | operating systems (OSes) are moving out of research laboratories; the |
---|
149 | .NET and Web Services marketing machines are starting to propagate technical |
---|
150 | content; and peer-to-peer and CORBA partisans are fighting back with significant |
---|
151 | engineering advances. This is territory that Erlang experts have been |
---|
152 | exploring for more than a decade. |
---|
153 | <P>Erlang was originally designed as a "language for programming <I>distributed |
---|
154 | fault-tolerant soft real-time non-stop applications</I>." That formulation |
---|
155 | correctly suggests there's more to Erlang than just its capacity for distributed |
---|
156 | calculations. Erlang is a functional programming language, with deep roots |
---|
157 | in logic and functional semantics that contribute to program correctness. |
---|
158 | Like such wildly different languages as Ada and Eiffel, Erlang's correctness |
---|
159 | characteristics make it easier for programmers to compose applications |
---|
160 | that behave predictably. Erlang generalizes correctness to "fault-tolerance" |
---|
161 | with its powerful "exception" mechanisms. Ericsson telephone switches |
---|
162 | need very high uptimes -- 99.999% and up. Erlang's fault-tolerance, related |
---|
163 | to the exceptions in Java and Python, helps achieve this level of reliability. |
---|
164 | <P> |
---|
165 | <H2>See for Yourself</H2> |
---|
166 | <P> |
---|
167 | What's it like to work in a language shaped for fault-tolerance, |
---|
168 | high productivity, and distribution? As with most of the subjects |
---|
169 | we choose for "Regular Expressions," the best answer is likely to |
---|
170 | be, "See for yourself." An open-source version of Erlang has been |
---|
171 | available since 1998, and extensive resources are available on the |
---|
172 | Web. |
---|
173 | <P> Source or binary downloads for the recent versions of the standard Erlang |
---|
174 | distribution are just over 10 megabytes in size. Although this is toward |
---|
175 | the top of the range for the languages "Regular Expressions" most often |
---|
176 | covers, it's significantly smaller than typical Java installations. In |
---|
177 | our experience, Unix generations of Erlang from source always go smoothly; |
---|
178 | whatever errors the latest releases have, they don't show up during installation |
---|
179 | or simple tests. |
---|
180 | <P> Once that's done, Erlang's "Hello, World" preliminaries go quickly enough. |
---|
181 | Erlang's home site even has a "Getting Started" page at <A href="http://www.erlang.org/starting.html" target="_blank">http://www.erlang.org/starting.html</A>. |
---|
182 | Like other typical modern interpreters, the Erlang language processor, |
---|
183 | <CODE>erl</CODE>, supports both interactive and "batch" operation. You |
---|
184 | can bring it up interactively as a convenient calculator: |
---|
185 | <PRE> #> erl |
---|
186 | Erlang (BEAM) emulator version 5.1 [source] |
---|
187 | |
---|
188 | Eshell V5.1 (abort with ^G) |
---|
189 | 1> pwd(). |
---|
190 | /usr/local/src/otp_src_R8B-0 |
---|
191 | ok |
---|
192 | 2> ls(). |
---|
193 | AUTHORS EPLICENCE Makefile Makefile.in |
---|
194 | README bin bootstrap config.cache |
---|
195 | config.log config.status configure configure.in |
---|
196 | erts lib make |
---|
197 | ok |
---|
198 | 3> 123 * 456 - 999. |
---|
199 | 55089 </PRE> |
---|
200 | |
---|
201 | Notice that a period terminates every complete line. |
---|
202 | |
---|
203 | <P> |
---|
204 | <H2>Safe Power</H2> |
---|
205 | <P> |
---|
206 | The Erlang downloads are so large because the |
---|
207 | standard distribution is intended to "include batteries." |
---|
208 | Every Erlang installation builds in functions |
---|
209 | that mediate ASN encoding, manage CORBA transactions, |
---|
210 | perform cryptographic transformations, implement such |
---|
211 | standard networking protocols as FTP, HTTP, SNMP, and SSL, |
---|
212 | and even connect to Java classes. |
---|
213 | <P> This powerful library combines with Erlang's succinct expressivity to |
---|
214 | make remarkable results possible in just a few lines. It's hard to show |
---|
215 | Erlang at its best by simply looking at common programming tasks; it doesn't |
---|
216 | do the things that Perl or C do any better than those languages. Erlang |
---|
217 | comes into its own on applications that must run continuously (think of |
---|
218 | air-traffic control), cooperatively (across many machines), and without |
---|
219 | surprises. Erlang is largely immune to the buffer overflows, memory leaks, |
---|
220 | off-by-one, and other mundane errors that affect many applications. |
---|
221 | <P> |
---|
222 | A favorite example of Erlang's brevity is this generic |
---|
223 | client-server: |
---|
224 | <PRE> -module(cs). |
---|
225 | -export([start/3, rpc/2, loop/2]). |
---|
226 | |
---|
227 | start(Name, Data, Fun) -> |
---|
228 | register(Name, |
---|
229 | spawn(fun() -> |
---|
230 | loop(Data, Fun) |
---|
231 | end)). |
---|
232 | |
---|
233 | rpc(Name, Q) -> |
---|
234 | Tag = ref(), |
---|
235 | Name ! -query, self(), Tag, Q), |
---|
236 | receive |
---|
237 | (Tag, Reply) -> Reply |
---|
238 | end. |
---|
239 | |
---|
240 | loop(Data, Fun) -> |
---|
241 | receive |
---|
242 | (query, Pid, Tag, Q) -> |
---|
243 | (Reply, Data1) = Fun(Q, Data), |
---|
244 | Pid ! (Tag, Reply), |
---|
245 | loop(Data1, Fun) |
---|
246 | end. |
---|
247 | </PRE> |
---|
248 | <P> |
---|
249 | Invocation of <CODE>start()</CODE> launches a complete |
---|
250 | network endpoint. The code above handles communications |
---|
251 | and concurrency, while all that's left for an application |
---|
252 | developer is to bind <CODE>Fun</CODE> to a definition |
---|
253 | that executes the application-specific operation. |
---|
254 | <P> |
---|
255 | If your programs really, REALLY have to work right every |
---|
256 | time, consider using Erlang. |
---|
257 | <P> |
---|
258 | <H2>Administrative Wrap-Up</H2> |
---|
259 | <P> We're collecting notes and hyperlinks on Erlang at <A href="http://starbase.neosoft.com/~claird/comp.lang.functional/Erlang.html" target="_blank">http://starbase.neosoft.com/~claird/comp.lang.functional/Erlang.html</A>. |
---|
260 | One ambition for this page is to introduce a functional language for the |
---|
261 | "working programmer" in a way that makes the academic abstractions found |
---|
262 | in this specialty more appealing. As always, e-mail to us @regularexpressions.com |
---|
263 | is welcome. Incidentally, if you want to try out parallel programming |
---|
264 | in a more mainstream language than Erlang, consider PyPAR (<A href="http://datamining.anu.edu.au/pypar" target="_blank">http://datamining.anu.edu.au/pypar</A>). |
---|
265 | This well-behaved Python extension was just released in its 1.0 version |
---|
266 | last month. |
---|
267 | <P> |
---|
268 | Next time, we'll look at a completely |
---|
269 | different approach to construction of correct programs: |
---|
270 | use of static syntax analyzers. Until then, good luck |
---|
271 | in solving your problems at a high level. |
---|
272 | </TD> |
---|
273 | </TR> |
---|
274 | </TBODY> |
---|
275 | </TABLE> |
---|
276 | |
---|
277 | </TD> |
---|
278 | <TD vAlign=top align="left"> |
---|
279 | <TABLE cellSpacing=1 cellPadding=3 width="130" |
---|
280 | border=0> |
---|
281 | <TBODY> |
---|
282 | <TR vAlign=bottom align=right bgColor=#ffffff><TD> <A target="_top" href="http://newads.cmpnet.com/event.ng/Type=click&ProfileID=9939&RunID=37627&AdID=25450&GroupID=1&FamilyID=2749&TagValues=1910.2994&Redirect=http://www.sdmagazine.com"><IMG src="http://img.cmpnet.com/ads/graphics/cs/ar/clear_1x1.gif" border="0" height=1 width=1 alt=""></A></TD> |
---|
283 | |
---|
284 | </TR> |
---|
285 | </TBODY> |
---|
286 | </TABLE> |
---|
287 | </TD> |
---|
288 | <TR> |
---|
289 | <TD vAlign=top width=150 align="center"> </TD> |
---|
290 | <TD> </TD> |
---|
291 | <TD vAlign=top width="100%" colspan="2"> |
---|
292 | <HR width="170" align="left" noshade size="1"> |
---|
293 | <A href="/" class="headline">Home</A> | <A href="#top" class="headline">Top</A> |
---|
294 | <BR> |
---|
295 | <P> |
---|
296 | <A target="_top" href="http://newads.cmpnet.com/event.ng/Type=click&ProfileID=6936&RunID=41295&AdID=30835&GroupID=1&FamilyID=1&TagValues=179.2994&Redirect=http://www.usenix.org/events/usenix02/"><IMG src="http://img.cmpnet.com/ads/graphics/cs/ar/usenix_2002_468.gif" border=1 height=60 width=468 alt="Click Here!"></A> |
---|
297 | <BR> |
---|
298 | <SPAN class="privacy">Copyright © 2002 <I>UnixReview.com</I>, UnixReview.com's |
---|
299 | <A href="http://www.cmp.com/delivery/privacy.html">Privacy Policy<BR> |
---|
300 | </A></SPAN><SPAN class="privacy">Comments about the Web site: <A href="mailto:scoady@cmp.com?subject=UnixReview">scoady@cmp.com |
---|
301 | </A><BR> |
---|
302 | SDMG Web Sites: <A href="http://www.cuj.com/" target="_new">C/C++ Users |
---|
303 | Journal</A>, <A href="http://www.ddj.com/" target="_new">Dr. Dobb's Journal</A>, |
---|
304 | <A href="http://msdn.microsoft.com/msdnmag/" target="_new">MSDN Magazine</A>, |
---|
305 | <A href="http://www.sysadminmag.com/" target="_new">Sys Admin</A>, <A href="http://www.sdexpo.com/" target="_new">SD |
---|
306 | Expo</A>, <A href="http://www.sdmagazine.com/" target="_new">SD Magazine</A>, |
---|
307 | <A href="http://www.unixreview.com/">UnixReview.com</A>, <A href="http://www.wd-mag.com/" target="_new">Windows |
---|
308 | Developer</A>, <A href="http://www.tpj.com" target="_blank">TPJ</A>, |
---|
309 | <A href="http://www.byte.com/" target="_blank"> BYTE.com</A></SPAN></P> |
---|
310 | </TD> |
---|
311 | </TABLE><DIV align="right"><FONT size=-2>www3</FONT></DIV> |
---|
312 | </BODY></HTML> |
---|