diff --git a/_config.yml b/_config.yml index 0d38da8289..aa9af3f50e 100644 --- a/_config.yml +++ b/_config.yml @@ -17,4 +17,7 @@ pygments: true permalink: /:categories/:title.html baseurl: -# markdown: rdiscount \ No newline at end of file +exclude: +- renumber.rb + +# markdown: rdiscount diff --git a/renumber.rb b/renumber.rb new file mode 100644 index 0000000000..3f6ce13614 --- /dev/null +++ b/renumber.rb @@ -0,0 +1,107 @@ +#!/usr/bin/env ruby + +# The workflow is pretty straightforward for using this script to +# reorganize a multi-file document. +# +# 1. Have a clean tree. +# 2. Use -x *.md to print an index; write that to a file. +# 3. Reorder the lines in the file to match your desired order. +# 4. Feed the index back in with -i. + +require 'optparse' + +def opts(args) + options = {:encoding => 'UTF-8'} + OptionParser.new do |opts| + opts.banner = "Usage: ./renumber.rb [OPTIONS] [-i INDEX | FILES]" + + opts.on("-i", "--index FILE", "Use newline-separated list of files") do |i| + options[:index] = i + end + opts.on("-e", "--encoding ENC", "Set character encoding") do |e| + options[:encoding] = e + end + opts.on("-x", "--print-index", "Show index, don't change any files") do |x| + options[:print_index] = true + end + opts.on("-s", "--start-from NUM", Integer, "Use fresh numbers instead of reorganizing the existing numbers") do |s| + options[:start_from] = s + end + end.parse!(args) + options +end + +# `f`'s number and the num index location from its lines, or nil if +# none found. +def filenum(lines) + marker = /^---\s*/ + s = lines.index {|l| marker =~ l} + if s + e = lines.drop(s+1).index {|l| marker =~ l} + if e + nl = lines[s+1, e].map {|l| /^num: (\d+)\s*/.match(l)} + nli = nl.index {|l| l} + if nli + [nl[nli][1].to_i, s + 1 + nli] + end + end + end +end + +def setnum(n, nli, lines, fname) + File.open(fname, "w") do |f| + lines[0, nli].each {|l| f.write(l)} + f.write("num: #{n}\n") + lines[nli+1..-1].each {|l| f.write(l)} + end +end + +# List of (filename, number, number line index, lines) for each of +# files, or nil for entries with no number. +def filenums(files) + files.map do |fname| + lines = File.open(fname) {|f| f.readlines} + fn = filenum(lines) + if fn + [fname] + fn + [lines] + else + warn("#{fname} has no num: index entry; skipping") + end + end +end + +# Given filenums result and an optional number from which to create +# start new indices, write new indices. +def rewrite_indices(ns, start_from) + nums = if start_from + start_from..(start_from + ns.size - 1) + else + ns.map{|e| e[1]}.sort + end + nums.zip(ns) do |e| + nn, oe = e + fn, n, nli, lines = oe + setnum(nn, nli, lines, fn) + end +end + +def print_index(ns) + ns.sort{|x,y| x[1] <=> y[1]}.each{|n| puts(n[0])} +end + +def main(args) + o = opts(args) + fileset = if o[:index] + File.open(o[:index]) {|f| f.readlines}.map{|fn| fn.chomp} + else + args + end + ns = filenums(fileset).select{|e| e} + if o[:print_index] + print_index(ns) + else + rewrite_indices(ns, o[:start_from]) + end +end + +main(ARGV) diff --git a/tutorials/tour/abstract-types.md b/tutorials/tour/abstract-types.md index f1e2034613..9e9d38ae18 100644 --- a/tutorials/tour/abstract-types.md +++ b/tutorials/tour/abstract-types.md @@ -5,7 +5,7 @@ title: Abstract Types disqus: true tutorial: scala-tour -num: 2 +num: 21 outof: 35 languages: [es] --- diff --git a/tutorials/tour/annotations.md b/tutorials/tour/annotations.md index 3094d4d924..00c72ae64e 100644 --- a/tutorials/tour/annotations.md +++ b/tutorials/tour/annotations.md @@ -5,7 +5,7 @@ title: Annotations disqus: true tutorial: scala-tour -num: 3 +num: 30 --- Annotations associate meta-information with definitions. diff --git a/tutorials/tour/anonymous-function-syntax.md b/tutorials/tour/anonymous-function-syntax.md index 0e0bc903ca..b8361e3112 100644 --- a/tutorials/tour/anonymous-function-syntax.md +++ b/tutorials/tour/anonymous-function-syntax.md @@ -5,7 +5,7 @@ title: Anonymous Function Syntax disqus: true tutorial: scala-tour -num: 14 +num: 6 --- Scala provides a relatively lightweight syntax for defining anonymous functions. The following expression creates a successor function for integers: diff --git a/tutorials/tour/automatic-closures.md b/tutorials/tour/automatic-closures.md index 78b254ea84..d3f0217ba7 100644 --- a/tutorials/tour/automatic-closures.md +++ b/tutorials/tour/automatic-closures.md @@ -5,7 +5,7 @@ title: Automatic Type-Dependent Closure Construction disqus: true tutorial: scala-tour -num: 16 +num: 29 --- Scala allows parameterless function names as parameters of methods. When such a method is called, the actual parameters for parameterless function names are not evaluated and a nullary function is passed instead which encapsulates the computation of the corresponding parameter (so-called *call-by-name* evalutation). diff --git a/tutorials/tour/case-classes.md b/tutorials/tour/case-classes.md index 28f4ba3297..3d0c6f7c83 100644 --- a/tutorials/tour/case-classes.md +++ b/tutorials/tour/case-classes.md @@ -5,7 +5,7 @@ title: Case Classes disqus: true tutorial: scala-tour -num: 5 +num: 10 --- Scala supports the notion of _case classes_. Case classes are regular classes which export their constructor parameters and which provide a recursive decomposition mechanism via [pattern matching](pattern-matching.html). diff --git a/tutorials/tour/classes.md b/tutorials/tour/classes.md index bffb37fb64..29542cc647 100644 --- a/tutorials/tour/classes.md +++ b/tutorials/tour/classes.md @@ -5,7 +5,7 @@ title: Classes disqus: true tutorial: scala-tour -num: 4 +num: 3 --- Classes in Scala are static templates that can be instantiated into many objects at runtime. diff --git a/tutorials/tour/compound-types.md b/tutorials/tour/compound-types.md index d82bc865f0..1222614d18 100644 --- a/tutorials/tour/compound-types.md +++ b/tutorials/tour/compound-types.md @@ -5,7 +5,7 @@ title: Compound Types disqus: true tutorial: scala-tour -num: 6 +num: 22 --- Sometimes it is necessary to express that the type of an object is a subtype of several other types. In Scala this can be expressed with the help of *compound types*, which are intersections of object types. diff --git a/tutorials/tour/currying.md b/tutorials/tour/currying.md index 87e01b9fa5..0f1a3e1135 100644 --- a/tutorials/tour/currying.md +++ b/tutorials/tour/currying.md @@ -5,7 +5,7 @@ title: Currying disqus: true tutorial: scala-tour -num: 15 +num: 9 --- Methods may define multiple parameter lists. When a method is called with a fewer number of parameter lists, then this will yield a function taking the missing parameter lists as its arguments. diff --git a/tutorials/tour/default-parameter-values.md b/tutorials/tour/default-parameter-values.md index 7c7a59d041..6f5175eeec 100644 --- a/tutorials/tour/default-parameter-values.md +++ b/tutorials/tour/default-parameter-values.md @@ -5,7 +5,7 @@ title: Default Parameter values disqus: true tutorial: scala-tour -num: 34 +num: 31 --- Scala provides the ability to give parameters default values that can be used to allow a caller to omit those parameters. diff --git a/tutorials/tour/explicitly-typed-self-references.md b/tutorials/tour/explicitly-typed-self-references.md index 7359b80fa6..2fa5c5db26 100644 --- a/tutorials/tour/explicitly-typed-self-references.md +++ b/tutorials/tour/explicitly-typed-self-references.md @@ -5,7 +5,7 @@ title: Explicitly Typed Self References disqus: true tutorial: scala-tour -num: 27 +num: 23 --- When developing extensible software it is sometimes handy to declare the type of the value `this` explicitly. To motivate this, we will derive a small extensible representation of a graph data structure in Scala. diff --git a/tutorials/tour/extractor-objects.md b/tutorials/tour/extractor-objects.md index c5d63d96dd..c0e8699732 100644 --- a/tutorials/tour/extractor-objects.md +++ b/tutorials/tour/extractor-objects.md @@ -5,7 +5,7 @@ title: Extractor Objects disqus: true tutorial: scala-tour -num: 8 +num: 14 --- In Scala, patterns can be defined independently of case classes. To this end, a method named unapply is defined to yield a so-called extractor. For instance, the following code defines an extractor object Twice. diff --git a/tutorials/tour/generic-classes.md b/tutorials/tour/generic-classes.md index 751166ec54..7a4d5ae193 100644 --- a/tutorials/tour/generic-classes.md +++ b/tutorials/tour/generic-classes.md @@ -5,7 +5,7 @@ title: Generic Classes disqus: true tutorial: scala-tour -num: 9 +num: 16 --- Like in Java 5 (aka. [JDK 1.5](http://java.sun.com/j2se/1.5/)), Scala has built-in support for classes parameterized with types. Such generic classes are particularly useful for the development of collection classes. diff --git a/tutorials/tour/higher-order-functions.md b/tutorials/tour/higher-order-functions.md index f5e58dba13..991de213f7 100644 --- a/tutorials/tour/higher-order-functions.md +++ b/tutorials/tour/higher-order-functions.md @@ -5,7 +5,7 @@ title: Higher-order Functions disqus: true tutorial: scala-tour -num: 18 +num: 7 --- Scala allows the definition of higher-order functions. These are functions that _take other functions as parameters_, or whose _result is a function_. Here is a function `apply` which takes another function `f` and a value `v` and applies function `f` to `v`: diff --git a/tutorials/tour/implicit-parameters.md b/tutorials/tour/implicit-parameters.md index 19e775821f..17265a3471 100644 --- a/tutorials/tour/implicit-parameters.md +++ b/tutorials/tour/implicit-parameters.md @@ -5,7 +5,7 @@ title: Implicit Parameters disqus: true tutorial: scala-tour -num: 10 +num: 24 --- A method with _implicit parameters_ can be applied to arguments just like a normal method. In this case the implicit label has no effect. However, if such a method misses arguments for its implicit parameters, such arguments will be automatically provided. diff --git a/tutorials/tour/inner-classes.md b/tutorials/tour/inner-classes.md index 9b23d86df2..8101c1c977 100644 --- a/tutorials/tour/inner-classes.md +++ b/tutorials/tour/inner-classes.md @@ -5,7 +5,7 @@ title: Inner Classes disqus: true tutorial: scala-tour -num: 11 +num: 20 --- In Scala it is possible to let classes have other classes as members. Opposed to Java-like languages where such inner classes are members of the enclosing class, in Scala such inner classes are bound to the outer object. To illustrate the difference, we quickly sketch the implementation of a graph datatype: diff --git a/tutorials/tour/local-type-inference.md b/tutorials/tour/local-type-inference.md index ed413fbf69..b7e4181a24 100644 --- a/tutorials/tour/local-type-inference.md +++ b/tutorials/tour/local-type-inference.md @@ -5,7 +5,7 @@ title: Local Type Inference disqus: true tutorial: scala-tour -num: 29 +num: 27 --- Scala has a built-in type inference mechanism which allows the programmer to omit certain type annotations. It is, for instance, often not necessary in Scala to specify the type of a variable, since the compiler can deduce the type from the initialization expression of the variable. Also return types of methods can often be omitted since they corresponds to the type of the body, which gets inferred by the compiler. diff --git a/tutorials/tour/lower-type-bounds.md b/tutorials/tour/lower-type-bounds.md index 3a3632c83a..f897279ab1 100644 --- a/tutorials/tour/lower-type-bounds.md +++ b/tutorials/tour/lower-type-bounds.md @@ -5,7 +5,7 @@ title: Lower Type Bounds disqus: true tutorial: scala-tour -num: 26 +num: 19 --- While [upper type bounds](upper-type-bounds.html) limit a type to a subtype of another type, *lower type bounds* declare a type to be a supertype of another type. The term `T >: A` expresses that the type parameter `T` or the abstract type `T` refer to a supertype of type `A`. diff --git a/tutorials/tour/mixin-class-composition.md b/tutorials/tour/mixin-class-composition.md index 5a07b7cb18..57d977db3d 100644 --- a/tutorials/tour/mixin-class-composition.md +++ b/tutorials/tour/mixin-class-composition.md @@ -5,7 +5,7 @@ title: Mixin Class Composition disqus: true tutorial: scala-tour -num: 12 +num: 5 --- As opposed to languages that only support _single inheritance_, Scala has a more general notion of class reuse. Scala makes it possible to reuse the _new member definitions of a class_ (i.e. the delta in relationship to the superclass) in the definition of a new class. This is expressed as a _mixin-class composition_. Consider the following abstraction for iterators. diff --git a/tutorials/tour/named-parameters.md b/tutorials/tour/named-parameters.md index ebe134d493..3bb56eb3fa 100644 --- a/tutorials/tour/named-parameters.md +++ b/tutorials/tour/named-parameters.md @@ -5,7 +5,7 @@ title: Named Parameters disqus: true tutorial: scala-tour -num: 35 +num: 32 --- When calling methods and functions, you can use the name of the variables expliclty in the call, like so: diff --git a/tutorials/tour/nested-functions.md b/tutorials/tour/nested-functions.md index a6235b54fc..a85a3e84f6 100644 --- a/tutorials/tour/nested-functions.md +++ b/tutorials/tour/nested-functions.md @@ -5,7 +5,7 @@ title: Nested Functions disqus: true tutorial: scala-tour -num: 13 +num: 8 --- In Scala it is possible to nest function definitions. The following object provides a `filter` function for extracting values from a list of integers that are below a threshold value: diff --git a/tutorials/tour/operators.md b/tutorials/tour/operators.md index 68d49c7888..602a3dd065 100644 --- a/tutorials/tour/operators.md +++ b/tutorials/tour/operators.md @@ -5,7 +5,7 @@ title: Operators disqus: true tutorial: scala-tour -num: 17 +num: 28 --- Any method which takes a single parameter can be used as an *infix operator* in Scala. Here is the definition of class `MyBool` which defines three methods `and`, `or`, and `negate`. diff --git a/tutorials/tour/pattern-matching.md b/tutorials/tour/pattern-matching.md index 5f8a527bd5..37c1f75e7a 100644 --- a/tutorials/tour/pattern-matching.md +++ b/tutorials/tour/pattern-matching.md @@ -5,7 +5,7 @@ title: Pattern Matching disqus: true tutorial: scala-tour -num: 20 +num: 11 --- Scala has a built-in general pattern matching mechanism. It allows to match on any sort of data with a first-match policy. diff --git a/tutorials/tour/polymorphic-methods.md b/tutorials/tour/polymorphic-methods.md index db149bbcf4..ed68400996 100644 --- a/tutorials/tour/polymorphic-methods.md +++ b/tutorials/tour/polymorphic-methods.md @@ -5,7 +5,7 @@ title: Polymorphic Methods disqus: true tutorial: scala-tour -num: 21 +num: 26 --- Methods in Scala can be parameterized with both values and types. Like on the class level, value parameters are enclosed in a pair of parentheses, while type parameters are declared within a pair of brackets. diff --git a/tutorials/tour/regular-expression-patterns.md b/tutorials/tour/regular-expression-patterns.md index 7b8b5cea1b..56ae787c08 100644 --- a/tutorials/tour/regular-expression-patterns.md +++ b/tutorials/tour/regular-expression-patterns.md @@ -5,7 +5,7 @@ title: Regular Expression Patterns disqus: true tutorial: scala-tour -num: 22 +num: 13 --- ## Right-ignoring sequence patterns ## diff --git a/tutorials/tour/sequence-comprehensions.md b/tutorials/tour/sequence-comprehensions.md index 1e193d8d48..dc3b541dfa 100644 --- a/tutorials/tour/sequence-comprehensions.md +++ b/tutorials/tour/sequence-comprehensions.md @@ -5,7 +5,7 @@ title: Sequence Comprehensions disqus: true tutorial: scala-tour -num: 7 +num: 15 --- Scala offers a lightweight notation for expressing *sequence comprehensions*. Comprehensions have the form `for (enumerators) yield e`, where `enumerators` refers to a semicolon-separated list of enumerators. An *enumerator* is either a generator which introduces new variables, or it is a filter. A comprehension evaluates the body `e` for each binding generated by the enumerators and returns a sequence of these values. diff --git a/tutorials/tour/tour-of-scala.md b/tutorials/tour/tour-of-scala.md index 19c53c017d..3ffe8ef766 100644 --- a/tutorials/tour/tour-of-scala.md +++ b/tutorials/tour/tour-of-scala.md @@ -16,7 +16,7 @@ Scala is a pure object-oriented language in the sense that [every value is an ob ## Scala is functional ## Scala is also a functional language in the sense that [every function is a value](unified-types.html). Scala provides a [lightweight syntax](anonymous-function-syntax.html) for defining anonymous functions, it supports [higher-order functions](higher-order-functions.html), it allows functions to be [nested](nested-functions.html), and supports [currying](currying.html). Scala's [case classes](case-classes.html) and its built-in support for [pattern matching](pattern-matching.html) model algebraic types used in many functional programming languages. -Furthermore, Scala's notion of pattern matching naturally extends to the [processing of XML data](xml-processing.html) with the help of [right-ignoring sequence patterns](regular-expression-patterns.html). In this context, [sequence comprehensions](sequence-comprehensions.html) are useful for formulating queries. These features make Scala ideal for developing applications like web services. +Furthermore, Scala's notion of pattern matching naturally extends to the [processing of XML data](xml-processing.html) with the help of [right-ignoring sequence patterns](regular-expression-patterns.html), by way of general extension via [extractor objects](extractor-objects.html). In this context, [sequence comprehensions](sequence-comprehensions.html) are useful for formulating queries. These features make Scala ideal for developing applications like web services. ## Scala is statically typed ## Scala is equipped with an expressive type system that enforces statically that abstractions are used in a safe and coherent manner. In particular, the type system supports: @@ -26,7 +26,7 @@ Scala is equipped with an expressive type system that enforces statically that a * [inner classes](inner-classes.html) and [abstract types](abstract-types.html) as object members * [compound types](compound-types.html) * [explicitly typed self references](explicitly-typed-self-references.html) -* [views](views.html) +* [implicit parameters](implicit-parameters.html) and [views](views.html) * [polymorphic methods](polymorphic-methods.html) A [local type inference mechanism](local-type-inference.html) takes care that the user is not required to annotate the program with redundant type information. In combination, these features provide a powerful basis for the safe reuse of programming abstractions and for the type-safe extension of software. @@ -40,6 +40,6 @@ In practice, the development of domain-specific applications often requires doma A joint use of both features facilitates the definition of new statements without extending the syntax and without using macro-like meta-programming facilities. Scala interoperates with Java and .NET. -Scala is designed to interoperate well with the popular Java 2 Runtime Environment (JRE). In particular, the interaction with the mainstream object-oriented Java programming language is as smooth as possible. Scala has the same compilation model (separate compilation, dynamic class loading) like Java and allows access to thousands of existing high-quality libraries. Support for the .NET Framework (CLR) is also available. +Scala is designed to interoperate well with the popular Java 2 Runtime Environment (JRE). In particular, the interaction with the mainstream object-oriented Java programming language is as smooth as possible. Newer Java features like [annotations](annotations.html) and Java generics have direct analogues in Scala. Those Scala features without Java analogues, such as [default](default-parameter-values.html) and [named parameters](named-parameters.html), compile as close to Java as they can reasonably come. Scala has the same compilation model (separate compilation, dynamic class loading) like Java and allows access to thousands of existing high-quality libraries. Support for the .NET Framework (CLR) is also available. Please continue to the next page to read more. diff --git a/tutorials/tour/traits.md b/tutorials/tour/traits.md index e8ccef0560..0cc405dd57 100644 --- a/tutorials/tour/traits.md +++ b/tutorials/tour/traits.md @@ -5,7 +5,7 @@ title: Traits disqus: true tutorial: scala-tour -num: 24 +num: 4 --- Similar to interfaces in Java, traits are used to define object types by specifying the signature of the supported methods. Unlike Java, Scala allows traits to be partially implemented; i.e. it is possible to define default implementations for some methods. In contrast to classes, traits may not have constructor parameters. diff --git a/tutorials/tour/unified-types.md b/tutorials/tour/unified-types.md index 37073a79ad..6d128a3bd4 100644 --- a/tutorials/tour/unified-types.md +++ b/tutorials/tour/unified-types.md @@ -5,7 +5,7 @@ title: Unified Types disqus: true tutorial: scala-tour -num: 30 +num: 2 --- In contrast to Java, all values in Scala are objects (including numerical values and functions). Since Scala is class-based, all values are instances of a class. The diagram below illustrates the class hierarchy. diff --git a/tutorials/tour/upper-type-bounds.md b/tutorials/tour/upper-type-bounds.md index 94b6bc011c..bbf893f0de 100644 --- a/tutorials/tour/upper-type-bounds.md +++ b/tutorials/tour/upper-type-bounds.md @@ -5,7 +5,7 @@ title: Upper Type Bounds disqus: true tutorial: scala-tour -num: 25 +num: 18 --- In Scala, [type parameters](generic-classes.html) and [abstract types](abstract-types.html) may be constrained by a type bound. Such type bounds limit the concrete values of the type variables and possibly reveal more information about the members of such types. An _upper type bound_ `T <: A` declares that type variable `T` refers to a subtype of type `A`. diff --git a/tutorials/tour/variances.md b/tutorials/tour/variances.md index 622dafe21e..aa6995ed50 100644 --- a/tutorials/tour/variances.md +++ b/tutorials/tour/variances.md @@ -5,7 +5,7 @@ title: Variances disqus: true tutorial: scala-tour -num: 31 +num: 17 --- Scala supports variance annotations of type parameters of [generic classes](generic-classes.html). In contrast to Java 5 (aka. [JDK 1.5](http://java.sun.com/j2se/1.5/)), variance annotations may be added when a class abstraction is defined, whereas in Java 5, variance annotations are given by clients when a class abstraction is used. diff --git a/tutorials/tour/views.md b/tutorials/tour/views.md index 3376dd4d8c..2adcfb3bf4 100644 --- a/tutorials/tour/views.md +++ b/tutorials/tour/views.md @@ -5,7 +5,7 @@ title: Views disqus: true tutorial: scala-tour -num: 32 +num: 25 --- [Implicit parameters](implicit-parameters.html) and methods can also define implicit conversions called _views_. A view from type `S` to type `T` is defined by an implicit value which has function type `S => T`, or by an implicit method convertible to a value of that type. diff --git a/tutorials/tour/xml-processing.md b/tutorials/tour/xml-processing.md index bb9c4cc534..b9e9ccf058 100644 --- a/tutorials/tour/xml-processing.md +++ b/tutorials/tour/xml-processing.md @@ -5,7 +5,7 @@ title: XML Processing disqus: true tutorial: scala-tour -num: 33 +num: 12 --- Scala can be used to easily create, parse, and process XML documents. XML data can be represented in Scala either by using a generic data representation, or with a data-specific data representation. The latter approach is supported by the *data-binding* tool `schema2src`.