1\chapter{S-Lang 2 Interpreter NEWS}
2
3 This chapter describes features that were added to various 2.0
4 releases.  For a much more complete and detailed list of changes, see
5 the \file{changes.txt} file that is distributed with the library.
6
7\sect{What's new for \slang 2.2}
8#d tagexmp#1 \tag{\exmp{$1}}
9
10\begin{itemize}
11\item
12  The ternary expression was added:
13#v+
14     expression = condition ? val1 : val2
15#v-
16  If \em{condition} is non-zero, then \em{expression = val1},
17  otherwise \em{expression = val2}.
18
19\item
20  The break and continue statements support an optional integer that
21  indicates how many loop levels the statement affects, e.g., the
22  break statement in
23#v+
24   while (1)
25     {
26       loop (10)
27         {
28           break 2;
29         }
30     }
31#v-
32   will cause both loops to be terminated.
33
34\item
35   Multiline strings have been added:
36#v+
37    "This is a \
38    multiline \
39    string"
40
41    `This is
42    another multiline
43    string that
44    does not require
45    a \ for continuation`
46#v-
47\item
48   \dtype{List_Type} objects may be indexed using an array of indices
49   instead of just a single scalar index.
50\end{itemize}
51
52The following intrinsic function were added in version 2.2:
53\begin{descrip}
54\tagexmp{sumsq}
55  Equivalent to \exmp{sum(x*x)}.
56\tagexmp{expm1}
57  More accurate version of \exmp{exp(x)-1} for \exmp{x} near 0.
58\tagexmp{log1p}
59  More accurate version of \exmp{log(1+x)} for \exmp{x} near 0.
60\tagexmp{list_to_array}
61  Creates an array from a list.
62\tagexmp{string_matches}
63  A convenient alternative to the \exmp{string_match} and
64  \exmp{string_match_nth} functions.
65\tagexmp{_close}
66  Close an integer descriptor.
67\tagexmp{_fileno}
68  Returns the descriptor as an integer.
69\tagexmp{dup2_fd}
70  Duplicates a file descriptor via the \exmp{dup2} POSIX function.
71\tagexmp{getsid, killpg, getpriority, setpriority}
72  These functions correspond to the corresponding POSIX functions.
73\tagexmp{ldexp, frexp}
74  If \exmp{x == a*2^b}, where \exmp{0.5<=a<1.0} then
75  \exmp{(a,b)=frexp(x)}, and \exmp{x=ldexp(a,b)}.
76\end{descrip}
77
78The following functions have been enhanced:
79\begin{descrip}
80\tagexmp{hypot}
81  If given a single array argument \exmp{X}, it returns the equivalent
82  of \exmp{sqrt(sum(X*X)}.
83\tagexmp{polynom}
84  The calling interface to this function was changed and support added
85  for arrays.
86\end{descrip}
87
88The following modules were added to version 2.2:
89\begin{descrip}
90\tagexmp{zlib}
91  A module that wraps the popular z compression library.
92\tagexmp{fork}
93  A module that wraps the \exmp{fork}, \exmp{exec*}, and
94  \exmp{waitpid} functions.
95\tagexmp{sysconf}
96  A module that implements interfaces to the POSIX
97  \exmp{sysconf}, \exmp{pathconf}, and \exmp{confstr} functions.
98\end{descrip}
99
100The following library files and functions were add to \slsh:
101\begin{descrip}
102\tagexmp{process.sl}
103  The code in this file utilizes the \exmp{fork} module to implement
104  the \exmp{new_process} function, which allows the caller to easily
105  create and communicate with subprocesses and pipelines.
106\end{descrip}
107
108\sect{What's new for \slang 2.1}
109
110\begin{itemize}
111\item
112 Short circuiting boolean operators \exmp{||} and \exmp{&&}
113 have been added to the languange.  The use of \exmp{orelse} and
114 \exmp{andelse} constructs are nolonger necessary nor encouraged.
115\item
116 \em{Qualifiers} have been added to the language as a convenient
117 and powerful mechanism to pass optional information to functions.
118\item
119 Structure definitions allow embeded assignemnts, e.g,
120#v+
121    s = struct {foo = 3, bar = "hello" };
122#v-
123\item
124  Comparison expressions such as \exmp{a<b<c} are now interpretered as
125  \exmp{(a<b)and(b<c)}.
126\item
127  The \kw{ifnot} keyword was added as an alternative to \kw{!if}.  The
128  use of \kw{!if} has been deprecated.
129\item
130  Looping constructs now support a "then" clause that will get
131  executed if the loop runs to completion, e.g.,
132#v+
133     loop (20)
134       {
135          if (this ())
136            break;  % The then clause will NOT get executed
137       }
138     then do_that ();
139#v-
140  Note: \kw{then} is now a reserved word.
141\item
142  A floating point array of exactly N elements may be created
143  using the form \exmp{[a:b:#N]}, where the elements are uniformly
144  spaced and run from a to b, inclusive.
145\item
146  References to array elements and structure fields are now
147  supported, e.g., \exmp{&A[3]}, \exmp{&s.foo}.
148\item
149  An exception may be rethrown by calling "throw" without any
150  arguments:
151#v+
152    try { something (); }
153    catch AnyError: { do_this (); throw; }
154#v-
155\end{itemize}
156
157The following intrinsic function were added in version 2.1:
158\begin{descrip}
159\tagexmp{wherenot(x)} Equivalent to where (not(x))
160\tagexmp{_$(str)}
161  Evaluates strings with embedded "dollar" variables, e.g.,
162  \exmp{_$("$TERM")}.
163\tagexmp{__push_list/__pop_list}
164  Push list items onto the stack
165\tagexmp{prod(x)}
166  Computes the product of an array \exmp{a[0]*a[1]*...}
167\tagexmp{minabs(x), maxabs(x)}
168  Equivalent to \exmp{min(abs(x))} and \exmp{max(abs(x))}, resp.
169\tagexmp{getpgrp, setgid, getpgid}
170  Get and set the process group ids (Unix).
171\tagexmp{setsid}
172  Create a new session (Unix).
173\end{descrip}
174
175The following modules were added to version 2.1:
176\begin{descrip}
177  \tagexmp{iconv}
178      Performs character-set conversion using the iconv library.
179  \tagexmp{onig}
180     A regular expression module using oniguruma RE library.
181\end{descrip}
182
183The following library files and functions were add to \slsh:
184\begin{descrip}
185\tagexmp{readascii} A flexible and power ascii (as opposed to binary)
186  data file reader.
187\tagexmp{cmdopt}  A set of functions that vastly simplify the parsing
188of command line options.
189\end{descrip}
190
191Also a history and completion mechanism was added to the \slang
192readline interface, and as a result, \slsh now supports history and
193command/file completion.
194
195\sect{What's new for \slang 2.0}
196
197Here is a brief list of some of the new features and improvements in
198\slang 2.0.
199
200\begin{itemize}
201\item \slsh, the generic \slang interpreter, now supports and
202 interactive command-line mode with readline support.
203\item Native support for Unicode via UTF-8 throughout the library.
204\item A \dtype{List_Type} object has been added to the language, e.g.,
205#v+
206     x = {1, 2.7, "foo", [1:10]};
207#v-
208  will create a (heterogeneous) list of 4 elements.
209\item A much improved exception handling model.
210\item Variable expansion within string literals:
211#v+
212    file = "$HOME/src/slang-$VERSION/"$;
213#v-
214\item Operator overloading for user-defined types.
215 For example it is possible to define a meaning to \exmp{X+Y} where
216 \exmp{X} and \exmp{Y} are defined as
217#v+
218    typedef struct { x, y, z } Vector;
219    define vector (x,y,z) { variable v = @Vector; v.x=x; v.y=y; v.z=z;}
220    X = vector (1,2,3);
221    Y = vector (4,5,6);
222#v-
223\item Syntactic sugar for objected-oriented style method calls.
224 \slang 1 code such as
225#v+
226
227     (@s.method)(s, args);
228#v-
229  may be written much more simply as
230#v+
231     s.method(args);
232#v-
233  This should make "object-oriented" code somewhat more readable.
234  See also the next section if your code uses constructs such as
235#v+
236     @s.method(args);
237#v-
238  because it is not supported by \slang 2.
239
240\item More intrinsic functions including math functions such
241 as \ifun{hypot}, \ifun{atan2}, \ifun{floor}, \ifun{ceil},
242 \ifun{round}, \ifun{isnan}, \ifun{isinf}, and many more.
243
244\item Support for \exmp{long long} integers.
245#v+
246    X = 18446744073709551615ULL;
247#v-
248\item Large file support
249\item Performance improvements.  The \slang 2 interpreter is about 20 percent
250 faster for many operations than the previous version.
251\item Better debugging support including an interactive debugger.  See
252 \sectref{Using the sldb debugger} for more information.
253\end{itemize}
254
255See the relevent chapters in in the manual for more information.
256
257\sect{Upgrading to \slang 2}
258
259 For the most part \slang 2 is backwards-compatible with \slang 1.
260 However there are a few important differences that need to be
261 understood before upgrading to version 2.
262
263\begin{descrip}
264  \tag{++ and -- operators in function calls}
265    Previously the \exmp{++} and {--} operators were permitted in
266    a function argument list, e.g.,
267#v+
268    some_function (x++, x);
269#v-
270  Such uses are flagged as syntax errors and need to be changed to
271#v+
272    x++; some_function (x);
273#v-
274
275  \tag{Array indexing of strings}  Array indexing of strings uses
276  byte-semantics and not character-semantics.  This distinction is
277  important only if UTF-8 mode is in effect.  If you use array
278  indexing with functions that use character semantics, then your code
279  may not work properly in UTF-8 mode.  For example, one might have used
280#v+
281     i = is_substr (a, b);
282     if (i) c = a[[0:i-2]];
283#v-
284  to extract that portion of \exmp{a} that preceeds the occurrence of
285  \exmp{b} in \exmp{a}.  This may nolonger work in UTF-8 mode where
286  bytes and characters are not generally the same.  The correct way to
287  write the above is to use the \exmp{substr} function since it uses
288  character semantics:
289#v+
290     i = is_substr (a, b);
291     if (i) c = substr (a, 1, i-1);
292#v-
293
294  \tag{Array indexing with negative integer ranges} Previously the
295    interpretation of a range array was context sensitive.  In an
296    indexing situation \exmp{[0:-1]} was used to index from the first
297    through the last element of an array, but outside this context,
298    \exmp{[0:-1]} was an empty array.  For \slang2, the meaning of
299    such arrays is always the same regardless of the context.  Since
300    by itself \exmp{[0:-1]} represents an empty array, indexing with
301    such an array will also produce an empty array.  The behavior of
302    scalar indices has not changed: \exmp{A[-1]} still refers to the
303    last element of the array.
304
305    Range arrays with an implied endpoint make sense only in indexing
306    situations.  Hence the value of the endpoint can be inferred from
307    the context.  Such arrays include \exmp{[*]}, \exmp{[:-1]}, etc.
308
309    Code that use index-ranges with negative valued indices such as
310#v+
311       B = A[[0:-2]];    % Get all but the last element of A
312#v-
313    will have to be changed to use an array with an implied endpoint:
314#v+
315       B = A[[:-2]];     % Get all but the last element of A
316#v-
317    Similarly, code such as
318#v+
319       B = A[[-3:-1]];   % Get the last 3 elements of A
320#v-
321    must be changed to
322#v+
323       B = A[[-3:]];
324#v-
325\tag{Dereferencing function members of a structure}  Support for the
326 non-parenthesized form of function member dereferencing has been
327 dropped.  Code such as
328#v+
329     @s.foo(args);
330#v-
331 will need to be changed to use the parenthesized form:
332#v+
333     (@s.foo)(args);
334#v-
335 The latter form will work in both \slang 1 and \slang 2.
336
337 If your code passes the structure as the first argument of the
338 method call, e.g.,
339#v+
340     (@s.foo)(s, moreargs);
341#v-
342 then it may be changed to
343#v+
344     s.foo (moreargs);
345#v-
346 However, this \em{objected-oriented} form of method calling is not
347 supported by \slang 1.
348
349\tag{ERROR_BLOCKS}
350    Exception handling via \exmp{ERROR_BLOCKS} is still supported but
351    deprecated.  If your code uses \exmp{ERROR_BLOCKS} it should be
352    changed to use the new exception handling model.  For example,
353    code that looks like:
354#v+
355       ERROR_BLOCK { cleanup_after_error (); }
356       do_something ();
357          .
358          .
359#v-
360   should be changed to:
361#v+
362       variable e;
363       try (e)
364         {
365            do_something ();
366              .
367              .
368         }
369       catch RunTimeError:
370         {
371            cleanup_after_error ();
372            throw e.error, e.message;
373         }
374#v-
375
376 Code that makes use of \exmp{EXECUTE_ERROR_BLOCK}
377#v+
378       ERROR_BLOCK { cleanup_after_error (); }
379       do_something ();
380          .
381          .
382       EXECUTE_ERROR_BLOCK;
383#v-
384   should be changed to make use of a \kw{finally} clause:
385#v+
386       variable e;
387       try (e)
388         {
389            do_something ();
390              .
391              .
392         }
393       finally
394         {
395            cleanup_after_error ();
396         }
397#v-
398
399 It is not possible to emulate the complete semantics of the
400 \ifun{_clear_error} function.  However, those semantics are flawed
401 and fixing the problems associated with the use of
402 \ifun{_clear_error} was one of the primary reasons for the new
403 exception handling model.  The main problem with the
404 \ifun{_clear_error} method is that it causes execution to resume at the
405 byte-code following the code that triggered the error.  As such,
406 \ifun{_clear_error} defines no absolute resumption point.  In
407 contrast, the try-catch exception model has well-defined points of
408 execution.  With the above caveats, code such as
409#v+
410       ERROR_BLOCK { cleanup_after_error (); _clear_error ();}
411       do_something ();
412          .
413          .
414#v-
415  should be changed to:
416#v+
417       variable e;
418       try (e)
419         {
420            do_something ();
421              .
422              .
423         }
424       catch RunTimeError:
425         {
426            cleanup_after_error ();
427         }
428#v-
429 And code using \ifun{_clear_error} in conjunction with
430 \kw{EXECUTE_ERROR_BLOCK}:
431#v+
432       ERROR_BLOCK { cleanup_after_error (); _clear_error ();}
433       do_something ();
434          .
435          .
436       EXECUTE_ERROR_BLOCK;
437#v-
438  should be changed to:
439#v+
440       variable e;
441       try (e)
442         {
443            do_something ();
444              .
445              .
446         }
447       catch RunTimeError:
448         {
449            cleanup_after_error ();
450         }
451       finally:
452         {
453            cleanup_after_error ();
454         }
455#v-
456
457  \tag{fread} When reading \dtype{Char_Type} and
458  \dtype{UChar_Type} objects the \slang 1 version of \ifun{fread}
459  returned a binary string (\dtype{BString_Type} if the number of
460  characters read was greater than one, or a \exmp{U/Char_Type} if the
461  number read was one.  In other words, the resulting type depended
462  upon how many bytes were read with no way to predict the resulting
463  type in advance. In contrast, when reading, e.g, \exmp{Int_Type}
464  objects, \ifun{fread} returned an \exmp{Int_Type} when it read one
465  integer, or an array of \exmp{Int_Type} if more than one was read.
466  For \slang 2, the behavior of \ifun{fread} with respect to
467  \dtype{UChar_Type} and \dtype{Char_Type} types was changed to
468  have the same semantics as the other data types.
469
470  The upshot is that code that used
471#v+
472        nread = fread (&str, Char_Type, num_wanted, fp)
473#v-
474  will no longer result in \exmp{str} being a \dtype{BString_Type} if
475  \exmp{nread > 1}.  Instead, \exmp{str} will now become a
476  \exmp{Char_Type[nread]} object.  In order to read a specified number
477  of bytes from a file in the form of a string, use the
478  \ifun{fread_bytes} function:
479#v+
480       #if (_slang_version >= 20000)
481       nread = fread_bytes (&str, num_wanted, fp);
482       #else
483       nread = fread (&str, Char_Type, num_wanted, fp)
484       #endif
485#v-
486  The above will work with both versions of the interpreter.
487
488  \tag{strtrans} The \ifun{strtrans} function has been changed to
489   support Unicode.  One ramification of this is that when mapping
490   from one range of characters to another, the length of the ranges
491   must now be equal.
492
493  \tag{str_delete_chars}  This function was changed to support unicode
494  character classes.  Code such as
495#v+
496     y = str_delete_chars (x, "\\a");
497#v-
498  is now implies the deletion of all alphabetic characters from
499  \exmp{x}.  Previously it meant to delete the backslashes and
500  \exmp{a}s from from \exmp{x}.  Use
501#v+
502     y = str_delete_chars (x, "\\\\a");
503#v-
504  to achieve the latter.
505
506  \tag{substr, is_substr, strsub}
507  These functions use character-semantics and not byte-semantics.  The
508  distinction is important in UTF-8 mode.  If you use array indexing
509  in conjunction with these functions, then read on.
510
511\end{descrip}
512
513