[q-lang-cvs] q/doc qdoc.texi,1.72,1.73
Brought to you by:
agraef
From: Albert G. <ag...@us...> - 2006-06-09 01:55:37
|
Update of /cvsroot/q-lang/q/doc In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv8340 Modified Files: qdoc.texi Log Message: updated documentation Index: qdoc.texi =================================================================== RCS file: /cvsroot/q-lang/q/doc/qdoc.texi,v retrieving revision 1.72 retrieving revision 1.73 diff -C2 -d -r1.72 -r1.73 *** qdoc.texi 8 Jun 2006 17:53:55 -0000 1.72 --- qdoc.texi 9 Jun 2006 01:55:31 -0000 1.73 *************** *** 203,216 **** As a practical programming language, Q comes with ``batteries included''. The standard library, which is mostly written in Q itself, ! provides a complex number type, a lot of useful list and stream ! processing functions (including list/stream comprehensions), some common ! container data structures (dictionaries, sets, etc.), the lambda ! calculus, and operations for creating PostScript graphics. It also ! includes an extensive system interface which offers services such as ! binary and C-style formatted I/O, BSD socket I/O, process management, ! POSIX threads, regular expression matching and internationalization ! features. Additional extension modules provide interfaces to a number of ! other third party libraries, which turns Q into a practical tool for a ! variety of application areas. In difference to other functional languages, Q is entirely based on the --- 203,215 ---- As a practical programming language, Q comes with ``batteries included''. The standard library, which is mostly written in Q itself, ! provides complex numbers, a lot of useful list and stream processing ! functions (including list/stream comprehensions), some common container ! data structures (dictionaries, sets, etc.), and operations for creating ! PostScript graphics. It also includes an extensive system interface ! which offers services such as binary and C-style formatted I/O, BSD ! socket I/O, process management, POSIX threads, regular expression ! matching and internationalization features. Additional extension modules ! provide interfaces to a number of other third party libraries, which ! turns Q into a practical tool for a variety of application areas. In difference to other functional languages, Q is entirely based on the *************** *** 225,232 **** ``free'' variables. Basically, both sides of an equation may involve arbitrary expressions. Therefore Q can also be used as a tool for ! symbolic expression evaluation. Q's symbolic processing capabilities are ! best illustrated by the fact that advanced features such as the lambda ! calculus and list comprehensions are @emph{not} built into the language, ! but are provided by scripts written in Q itself. On the surface, Q looks very much like contemporary functional languages --- 224,228 ---- ``free'' variables. Basically, both sides of an equation may involve arbitrary expressions. Therefore Q can also be used as a tool for ! symbolic expression evaluation. On the surface, Q looks very much like contemporary functional languages *************** *** 245,254 **** provides such imperative features for those who need them). Q also provides two novel and (IMHO) interesting features: a notion of ! @dfn{special forms} which allows to handle lazy evaluation in an ! (almost) transparent manner without having to give up the basic eager ! evaluation strategy; and a notion of @dfn{type guards} which provides a ! means to cope with hierarchies of abstract data types (similar to the ! notion of classes with single inheritance in object-oriented languages) ! in the context of a term rewriting language. Using Q is supposed to be fairly simple: you throw together some --- 241,250 ---- provides such imperative features for those who need them). Q also provides two novel and (IMHO) interesting features: a notion of ! @dfn{special forms} which allows to handle both macro-like functions and ! lazy evaluation in a uniform setting without having to give up the basic ! eager evaluation strategy; and a notion of @dfn{type guards} which ! provides a means to cope with hierarchies of abstract data types ! (similar to the notion of classes with single inheritance in ! object-oriented languages) in the context of a term rewriting language. Using Q is supposed to be fairly simple: you throw together some *************** *** 2341,2345 **** @ref{Built-In and Enumeration Types}, for details. Syntactic sugar is also provided for @dfn{list comprehensions}, which are discussed in ! @ref{Conditional Expressions and Comprehensions}. @cindex stream --- 2337,2341 ---- @ref{Built-In and Enumeration Types}, for details. Syntactic sugar is also provided for @dfn{list comprehensions}, which are discussed in ! @ref{Conditionals and Comprehensions}. @cindex stream *************** *** 2948,2952 **** @subsection Conditional Expressions and Lambdas ! TODO: if-then-else, lambda @node User-Defined Operators, , Built-In Operators, Expressions --- 2944,3014 ---- @subsection Conditional Expressions and Lambdas ! As of version 7.1, Q also provides special syntax for two other kinds of ! constructs which are commonly encountered in functional programs: ! conditional expressions and lambda abstractions. A @dfn{conditional ! expression} takes the form @code{if X then Y else Z} where @code{X}, ! @code{Y} and @code{Z} are arbitrary expressions. It returns the value of ! @code{Y} if the value of @code{X} is @code{true}, and the value of ! @code{Z} if the value of @code{X} is @code{false}. The @samp{else} part ! can also be omitted, in which case @code{()} is returned if the value of ! @code{X} is @code{false}. Like the built-in logical connectives ! @code{and then} and @code{or else}, conditional expressions are special ! forms which are evaluated in short-circuit mode; thus, if @code{X} ! evaluates to @code{false}, then @code{Y} will never be evaluated. ! ! @dfn{Lambda abstractions} can be denoted using the customary notation ! @code{\X.Y} where @code{X} is either an atomic expression (usually a ! variable) or a parenthesized compound expression denoting a pattern to ! be matched against the argument of the lambda function, and @code{Y} is ! another expression, the lambda body which is to be evaluated when the ! lambda function is applied to an argument. Multi-argument lambdas can be ! written using the notation @code{\X1 X2 @dots{} . Y}, which is just a ! shorthand for @code{\X1 . \X2 . @dots{} . Y}. Lambdas are special forms; ! neither the parameter patterns nor the body are evaluated, rather they ! are ``compiled'' (at runtime) to a special kind of function object which ! can be applied to the actual arguments in an efficient manner, see ! @ref{Lambda Abstractions}, for details. ! ! Like the other operators, both @code{if-then-else} and the @code{\X.Y} ! construct are merely syntactic sugar for function applications. The ! @code{if-then-else} operator is actually implemented by the standard ! library function @code{ifelse} (or the @code{when} function if the ! @samp{else} part is omitted), see @ref{Conditionals and ! Comprehensions}. The @code{\X.Y} construct translates to an application ! of the built-in @code{lambda} function, see @ref{Lambda Abstractions}. ! ! Note that the @code{\X.Y} construct has the lowest possible precedence, ! even lower than the sequencing operator @samp{||}, so it always has to ! be parenthesized unless it forms a toplevel expression or the body of ! another lambda construct. The @code{if-then-else} operator binds ! stronger than @samp{||}, but weaker than @samp{$}, and ``dangling ! @code{else}'' parts are assumed to belong to the most recent ! @code{if-then}. This makes imperative-style code like the following ! behave as expected: ! ! @smallexample ! test = \X. ! writes "The value is " || ! if X > 0 then ! writes "positive.\n" ! else if X < 0 then ! writes "negative.\n" ! else ! writes "zero.\n"; ! @end smallexample ! ! Also note that @code{if-then-else} needs to be parenthesized unless it ! occurs as a toplevel or inside a lambda, sequence or another conditional ! expression: ! ! @smallexample ! test = \X. writes $ "The value is " ++ ! (if X > 0 then ! "positive" ! else if X < 0 then ! "negative" ! else ! "zero") ++ ".\n"; ! @end smallexample @node User-Defined Operators, , Built-In Operators, Expressions *************** *** 2954,2959 **** As of version 6.2, the Q language also lets you you define your own ! operator symbols, using a declaration like the following (see also ! @ref{Declarations}): @smallexample --- 3016,3021 ---- As of version 6.2, the Q language also lets you you define your own ! prefix and infix operator symbols, using a declaration like the ! following (see also @ref{Declarations}): @smallexample *************** *** 2996,3004 **** In general, a quick glance at the operator table in the preceding ! subsection reveals that valid precedence level numbers go from 0 (lowest ! precedence, binary sequence operator) to 9 (highest precedence, unary ! quotation operators), with 8 denoting the precedence of function ! application. The complete list of built-in operators, cast as a sequence ! of valid Q declarations, is shown below: @smallexample --- 3058,3069 ---- In general, a quick glance at the operator table in the preceding ! subsection reveals that valid precedence level numbers for the prefix ! and infix operators go from 0 (lowest precedence, binary sequence ! operator) to 9 (highest precedence, unary quotation operators), with 8 ! denoting the precedence of function application. (Note that there are no ! numbered precedence levels for the @code{if-then-else} and @code{\X.Y} ! constructs because there is no way to declare such mixfix operators in ! Q.) The complete list of built-in prefix and infix operators, cast as a ! sequence of valid Q declarations, is shown below. @smallexample *************** *** 3016,3020 **** public (.) X Y @@7; public special const (') X @@9; ! public (`) X @@9, (~) X @@9; @end smallexample --- 3081,3085 ---- public (.) X Y @@7; public special const (') X @@9; ! public (`) X @@9, (~) X @@9, (&) X @@9; @end smallexample *************** *** 3039,3044 **** example here, as this document is confined to 7 bit ASCII.) But note that the ability to declare Unicode operator symbols will be useful only ! if your editor can properly display those symbols (nowadays most editors ! should have this capability, though). @node Equations and Expression Evaluation, Types, Expressions, Top --- 3104,3109 ---- example here, as this document is confined to 7 bit ASCII.) But note that the ability to declare Unicode operator symbols will be useful only ! if your text editor can properly display those symbols (nowadays most ! editors should have this capability, though). @node Equations and Expression Evaluation, Types, Expressions, Top *************** *** 4941,4949 **** @end smallexample ! TODO: stream enums no longer defined in streams.q, discuss here ! Enumerations also work with streams. The corresponding operations are ! not provided as builtins, but are implemented by the @code{stream.q} ! standard library module. We will discuss these in @ref{Streams}. @node Sub- and Supertypes, , Built-In and Enumeration Types, Types --- 5006,5028 ---- @end smallexample ! @cindex stream enumerations ! @findex streamenum ! @findex enumstream ! The standard prelude also provides enumerations for streams, ! cf. @ref{Streams}. The @code{streamenum} function implements stream ! enumerations in the same way as the @code{enum} function does for ! lists. There is also a second function @code{enumstream} which only ! takes one argument (the initial members) and generates a possibly ! infinite stream. The Q language provides syntactic sugar for both. For ! instance, @code{@{1..9@}} denotes a stream consisting of a finite ! arithmetic sequence, while @code{@{0..@}} is the infinite stream of all ! nonnegative integers. Note that if @code{X} belongs to an ``ordinary'', ! i.e., finite enumeration type, then of course @code{@{X..@}} will be ! finite, too. For instance: ! @smallexample ! ==> list @{sun..@} ! [sun,mon,tue,wed,thu,fri,sat] ! @end smallexample @node Sub- and Supertypes, , Built-In and Enumeration Types, Types *************** *** 5120,5124 **** Consider the following definition from the standard library which implements a simple kind of conditional expression (see also ! @ref{Conditional Expressions and Comprehensions}): @smallexample --- 5199,5203 ---- Consider the following definition from the standard library which implements a simple kind of conditional expression (see also ! @ref{Conditionals and Comprehensions}): @smallexample *************** *** 5626,5633 **** the Q language also provides a collection of predefined functions which cover a variety of elementary operations. The built-in functions can be ! divided into seven major groups, arithmetic and numeric functions, string, list and tuple functions, conversion functions, I/O functions, ! exception handling functions, and miscellaneous functions. We will ! describe each of these in turn. @menu --- 5705,5712 ---- the Q language also provides a collection of predefined functions which cover a variety of elementary operations. The built-in functions can be ! divided into eight major groups, arithmetic and numeric functions, string, list and tuple functions, conversion functions, I/O functions, ! lambda abstractions, exception handling functions, and miscellaneous ! functions. We will describe each of these in turn. @menu *************** *** 5637,5640 **** --- 5716,5720 ---- * Conversion Functions:: * I/O Functions:: + * Lambda Abstractions:: * Exception Handling:: * Miscellaneous Functions:: *************** *** 5977,5981 **** these functions in an ``orderly'' manner. ! @node I/O Functions, Exception Handling, Conversion Functions, Built-In Functions @section I/O Functions @cindex I/O functions --- 6057,6061 ---- these functions in an ``orderly'' manner. ! @node I/O Functions, Lambda Abstractions, Conversion Functions, Built-In Functions @section I/O Functions @cindex I/O functions *************** *** 6378,6382 **** @end smallexample ! @node Exception Handling, Miscellaneous Functions, I/O Functions, Built-In Functions @section Exception Handling --- 6458,6467 ---- @end smallexample ! @node Lambda Abstractions, Exception Handling, I/O Functions, Built-In Functions ! @section Lambda Abstractions ! ! TODO: discuss the new built-in lambda function here ! ! @node Exception Handling, Miscellaneous Functions, Lambda Abstractions, Built-In Functions @section Exception Handling *************** *** 6909,6913 **** * Standard Types:: * Streams:: ! * Conditional Expressions and Comprehensions:: * Mathematical Functions:: * Complex Numbers:: --- 6994,6998 ---- * Standard Types:: * Streams:: ! * Conditionals and Comprehensions:: * Mathematical Functions:: * Complex Numbers:: *************** *** 7677,7681 **** @code{ishdict} predicate checks for @code{HDict} values. ! @node Streams, Conditional Expressions and Comprehensions, Standard Types, The Standard Library @section Streams @cindex streams --- 7762,7766 ---- @code{ishdict} predicate checks for @code{HDict} values. ! @node Streams, Conditionals and Comprehensions, Standard Types, The Standard Library @section Streams @cindex streams *************** *** 7762,7767 **** result is always a stream. ! @node Conditional Expressions and Comprehensions, Mathematical Functions, Streams, The Standard Library ! @section Conditional Expressions @pindex cond.q --- 7847,7852 ---- result is always a stream. ! @node Conditionals and Comprehensions, Mathematical Functions, Streams, The Standard Library ! @section Conditionals and Comprehensions @pindex cond.q *************** *** 7904,7908 **** @end smallexample ! @node Mathematical Functions, Complex Numbers, Conditional Expressions and Comprehensions, The Standard Library @section Mathematical Functions @cindex mathematical functions (@code{math.q}) --- 7989,7993 ---- @end smallexample ! @node Mathematical Functions, Complex Numbers, Conditionals and Comprehensions, The Standard Library @section Mathematical Functions @cindex mathematical functions (@code{math.q}) |