OpenLLM-France/wikimedia huggingface dataset:
# Clojure Programming/TJP Examples

However -> works on everything
or expanded
So one can also use macros and normal functions in ->, i.e. non-methods.

## doto

NB: doto returns the object after modification, which is very convenient. Consider in the above example no variable binding is required to access the resultant object.
Here you can see it is much more readable using doto than the alternative which would be to create a temporary binding with let.

## "lambda"

Use fn, or even better there is a custom syntax to create an anonymous function:
Arguments in the body are determined by the presence of argument literals taking the form %, %n or %&. % is a synonym for %1, %n designates the nth arg (1-based), and %& designates a rest arg.

## recur

See loop

## remove

The opposite of filter
# Clojure Programming/Examples/Lazy Fibonacci

A function which lazily produces Fibonacci numbers:

## Recursive Version

A version with recursion on data, not functions. see http://en.wikipedia.org/wiki/Corecursion :
A different recursive version, making use of the reductions function. ... Does this work? NO. Seems a fake. See discussion.

## Properly Scoped Version

There might be a problem in the precedent versions : they create fibonacci lazy-sequences that are bound to top level vars. And as such they are not garbage collected, and if used to compute a very long sequence, will consume a lot of heap. It could be smarter to define fib-seq as a no-arg function that will return a lazy-seq on demand. Then the lazy seq could be put by the caller in the appropriate scope (hopefully not the top level scope) :

## Using iterate

We can use iterate to generate pairs of [a b] and then take the first of each one.
This example also uses destructuring.

## Self-Referential Version

Computes the Fibonacci sequence by mapping the sequence with itself, offset by one element.
# Clojure Programming/Examples/Norvig Spelling Corrector

Peter Norvig wrote an excellent example of a spelling corrector in Python. You can see How to Write a Spelling Corrector for a more detailed explanation.
This code, translated into Clojure by language creator Rich Hickey, demonstrates the Python-like brevity of Clojure:
To use:
Note: training with big.txt may require the jvm to be started with a heap bigger than its default. You can increase the heap size either by starting java with the "-server" option or setting the maximum heap size explicitly: "java -Xmx128m ..."
# Clojure Programming/Examples/Temperature Converter GUI

Simple example GUI application (from discussion group, updated for 20080329 release):
# Introduction to Programming Languages/Parsing
### Parsing

Parsing is the problem of transforming a linear sequence of characters into a syntax tree. Nowadays we are very good at parsing. In other words, we have many tools, such as lex and yacc, for instance, that helps us in this task. However, in the early days of computer science parsing was a very difficult problem. This was one of the first, and most fundamental challenges that the first compiler writers had to face. All of that must be dealt as an example.
If the program text describes a syntactically valid program, then it is possible to convert this text into a syntax tree. As an example, the figure below contains different parsing trees for three different programs written in our grammar of arithmetic expressions:
There are many algorithms to build a parsing tree from a sequence of characters. Some are more powerful, others are more practical. Basically, these algorithms try to find a sequence of applications of the production rules that end up generating the target string. For instance, let's consider the grammar below, which specifies a very small subset of the English grammar:
Below we have a sequence of derivations showing that the sentence "the student learned the programming language with the professor" is a valid program in this language:
← Grammars · Ambiguity →
# Introduction to Programming Languages/Polymorphis
### What is Polymorphism?

Software reuse is one of the main driving forces behind the design of many programming languages. These languages use different strategies to make it easier for developers to reuse software modules. One of the most important strategies is polymorphism. Polymorphism is the capacity that a language has to use the same name to denote different entities. This capacity surfaces in several distinct ways in programming languages. Following Adam Weber, we will classify the different kinds of polymorphism into two categories: ad-hoc and universal. Ad-hoc polymorphism happens if the same name designates a finite number of programming constructs. This type of polymorphism is further divided into coercion and overloading. Universal polymorphism happens whenever a name can denote a virtually infinite number of entities. This category is also divided into two other groups: parametric polymorphism and subtyping polymorphism. In the rest of this chapter we will describe each kind of polymorphism in more details.
Ad Hoc Polymorphism →
# Introduction to Programming Languages/Parametric Polymorphism
### Parametric polymorphism

Parametric polymorphism occurs when a routine, type or class definition is parameterized by one or more types. It allows the actual parameter type to be selected by the user. This way, it is possible to define types or functions that are generics, which can be expressed by using type variables for the parameter type. The code below shows the use of a template, which is a way of implementing parametric polymorphism in C++.
The source code above defines a polymorphic function called GetMax (lines 3 to 8). The type variable T defined in the scope of GetMax is a kind of generics, which will be substituted at the function call. The function takes two parameters (a and b) and returns a value of type T. The runtime values of a and b are compared and the bigest is returned by the function. The main function shows two calls for the GetMax function. At line 13 the function call uses the type int whereas at line 14 it uses the type long. The content of the arguments in a GetMax function call is compared using the ">" operator. For using this function, it is necessary that a variable type has this operator implemented. The following code shows an implementation of the overloading operator ">" in the class MyInt, so that it is possible to apply GetMax on it. The main function shows its use.
← Coercion · Subtype Polymorphism →
# Introduction to Programming Languages/Preface
### Preface

There exists an enormous variety of programming languages in use today. Testimony of this fact are the 650 plus different programming languages listed in Wikipedia. A good understanding of this great diversity is important for many reasons. First, it opens new perspectives to the computer scientists. Problems at first hard in one language might have a very easy solution in another. Thus, knowing which language to use in a given domain might decrease considerably the effort to build an application.
Furthermore, programming languages are just by themselves a fascinating topic. Their history blends together with the history of computer science. Many of the recipients of the Turing Award, such as John McCarthy or John Backus were directly involved in the project of some programming languages. And some of the most vibrating discussions in computer science were motivated by the design of programming languages. For instance, many modern programming languages no longer provide the goto command. It has not been like this in early designs. It took many years of discussions, plus a letter signed by Edsger Dijkstra, himself a Turing Award laureate, to ostracize the goto command into oblivion.
This wikibook is an attempt to describe a bit of the programming languages zoo. The material present here has been collected from blogs, language manuals, forums and many other sources; however, many examples have been taken from Dr. Webber's book. Thus, we follow the organization used in the slides that he has prepared for his book Modern Programming Languages. Thus, we start describing the ML programming language. Next, we move on to Python and finally to Prolog. We use each of these particular languages to introduce fundamental notions related to the design and the implementation of general purpose programming languages.
Programming Language Paradigms →
# Introduction to Programming Languages/Primitive Types
### Primitive Types

Every programming language that has types builds these types around a finite set of primitive types. Primitive types are atomic. In other words, they cannot be de-constructed into simpler types. As an example, the SML programming language has five primitive types:
* bool: these are the true or false.
* int: these are the integer numbers, which can be positive or negative.
* real: these are the real numbers. SML might represent them with up to 12 meaningful decimal digits after the point, e.g., 2.7 / 3.33 = 0.810810810811.
* char: these are the characters. They have a rather cumbersome syntax, when compared to other types. E.g.: #"a".
* string: these are the chains of characters. However, contrary to most of the programming languages, strings in SML cannot be de-constructed as lists of characters.
Different languages might provide different primitive types. Java, for instance, has the following primitive types:
* bool (1-bit)
* byte (1-byte signed)
* char (2-byte unsigned)
* short (2-byte signed)
* int (4-byte signed)
* long (8-byte signed)
* float (4-byte floating point)
* double (8-byte floating point)
Some authors will say that strings are primitive types in Java. Others will say that strings are composite: they are chains of characters. Nevertheless, independent on how strings are classified, we all agree that strings are built-in types. A built-in type is a data type that is not user-defined. Because the built-in type is part of the core language, its elements can be treated specially by the compiler. Java's strings, for instance, have the special syntax of literals between quotes. Furthermore, in Java strings are implemented as read-only constants. If we try, say, to insert a character in the middle of a string, then what we can do is to build a new string composing the original value with the character we want to insert.
In some languages the primitive types are part of the language specification. Thus, these types have the same semantics in any system where the language is supported. This is the case of the primitive types in Java and in SML, for instance. For example, the type integer, in Java, contains 2$^{32}$ elements in any setup that runs the Java Virtual Machine. However, there exist systems in which the semantics of a primitive type depends on the implementation of the programming language. C is a typical example. The size of integers in this programming language might vary from one architecture to the others. We can use the following function to find out the largest integer in C:
This function is executed in constant time, because of the operations that manipulate bits. In languages that do not support this type of operations, in general we cannot find the largest integer so quickly. For instance, the function below, in SML, finds the largest integer in $\scriptstyle O(ln{\mbox{ }}n)$, where $n$ is the number of bits in the integer type:
← Type Definition · Constructed Types →
# Introduction to Programming Languages/Overloading
### Overloading

Some programming languages support overloading. There are two kinds of overloading: function name and operator overloading. A function name overloading occurs when multiple member functions exist with the same name on the same scope. Despite having the same name, the functions must have different signatures, which comprises its name and the type and order of its parameters. The following example illustrates the use of function name overloading.
In the context of the main function, it is necessary to select the appropriate sum function to call. This selection is made by matching the type of the actual arguments in the call against the type of the formal parameters in one of the declarations. This process of selecting the appropriated function is called overload resolution. An error message or an exception is thrown if the compiler can not match a function call with a function declaration. As will be discussed in the Coercion section, it is possible to call a function with the same number of actual arguments but with not exactly the same type of its parameter definitions. Some languages provide a kind of convertions in an attempt to find a match.
The function name overloading can be eliminated by changing the name of the functions, so making them unique. After that, it is necessary to find each function call in the program and replace it with the appropriated function name. This strategy is a way in which some language systems implement overloading. It is created separated function definitions and each reference is replaced according to the types involved. The code below represents the modifications done in the function overlading sum.
Many languages have support to operator overloading. This concept is related to the fact that a same operator have different implementations depending on their arguments. Some languages allow the programmer to change the meaning of operators. By doing this, the user can program in the language of the problem domain rather than in the language of the machine. The next example ilustrates the use of the + operator to perform string concatenation and the use of << operator to print a MyString object. The result of the execution of this program is the word "UFMG" written in the screen.
Coercion →
# Introduction to Programming Languages/Partial Application
### Partial Application

In many programming languages, most notably in members of the functional paradigm such as ML and Haskell, every function takes only one argument as an input parameter. For instance, a ML function such as add(x, y) does not receive two parameters, x and y, as one could, at first think. It receives one parameter: the tuple (x, y):
In order to give developers the illusion that a function takes several parameters, these languages resort to a technique called currying. A curried function such as f(x)(y) takes an argument x, and returns a new function that takes another argument y, and might use the value of x inside its body. As an example, the function below is the curried version of the previous implementation of add:
Usually we do not need to pass all the sequence of arguments expected by a curried function. If we pass only the prefix of this sequence of arguments, then we have a Partial Application. The result of a partial application is normally implemented as a closure. For instance, below we are using our add_curry function as a function factory:
← Closures · Noticeable High-Order Functions →
# Dutch Empire/Stadtholders of Holland

This is a list of Stadtholders of Holland since Independence was declared in 1581.
| | Name | In Office | Notes |
| 1 | William I of Orange | (1572) 1581–1584 | William I of Orange, also known as William the Silent, was the main leader of the Dutch revolt against the Spanish that set off the Eighty Years' War and resulted in the independence of the Dutch Republic. He was elected as Stadtholder in 1572, although Phillip II, the King of Spain, had appointed another one. William the Silent was assassinated in 1584. In the Netherlands, he is also known as the Vader des Vaderlands, "Father of the Fatherland", and the Dutch national anthem, Het Wilhelmus, is written in his honor. |
| 2 | Maurits of Nassau | 1585–1625 | Became stadtholder of Holland in 1585. He was appointed captain-general of the army in 1587. He led many campaigns that turned the tide of the revolt against Spain. Died in 1625. |
| 3 | Frederik Hendrik of Orange | 1635–1647 | Brother of Maurits of Nassau. Frederick Henry proved himself almost as good a general as his brother, and a far more capable statesman and politician. For twenty-two years he remained at the head of government in the United Provinces, and in his time the power of the stadtholderate reached its highest point. On Frederick Henry's death, he was buried with great pomp beside his father and brother at Delft. |
| 4 | William II Prince of Orange | 1647–1650 | Opposed acceptance of the Treaty of Münster, although it recognized the independence of the Netherlands. Died from smallpox in 1650. |
| - | First Stadtholderless Period | 1650–1672 | |
| 5 | William III of Orange | 1672–1702 | Became Stadtholder in 1672 after the murder of Johan de Witt. He led the Dutch in the Franco-Dutch War. He invaded England in 1688 and became king. He served as Stadtholder and king until his death in 1702. |
| - | Second Stadtholderless Period | 1702–1747 | |
| 6 | William IV of Orange | 1747–1751 | Was appointed Stadtholder after the French Army entered Flanders. He was very popular among the people, and served until his death in 1751. |
| 7 | William V of Orange | 1751–1795 | The last Stadtholder of the Dutch Republic. His reign was longer than any other Stadtholder of Holland. He became Stadtholder at age 3. He served at Stadtholder until 1795 when France invaded and conquered the country. In 1795 he fled to the safety of his former enemy, England. He died in exile at Brunswick, now in Germany in 1806. |
# Dutch Empire/Origins of an Empire

The coastal provinces of Holland and Zeeland had for a long time prior to Spanish rule been important hubs of the European maritime trade network. Their geographical location provided convenient access to the markets of France, Germany, England and the Baltic. The war with Spain led many financiers and traders to emigrate from Antwerp, capital of Flanders and then one of Europe's most important commercial centres, to Dutch cities, particularly Amsterdam, which became Europe's foremost centre for shipping, banking, and insurance. Efficient access to capital enabled the Dutch in the 1580s to extend their trade networks beyond northern Europe to new markets in the Mediterranean and the Levant. In the 1590s, Dutch ships began to trade with Brazil and the Gold Coast of Africa, and towards the Indian Ocean and the source of the lucrative spice trade. This brought the Dutch into direct competition with Portugal, which had dominated these trade networks for several decades, and had established colonial outposts on the coasts of Brazil, Africa and the Indian Ocean to facilitate them. The rivalry with Portugal, however, was not entirely economic: from 1580 the Portuguese crown had been joined to that of Spain in an "Iberian Union" under Phillip II. By attacking Portuguese overseas possessions, the Dutch forced Spain to divert financial and military resources away from its attempt to quell Dutch independence. Thus this began the Dutch-Portuguese War, which would last until the 1650s.
In 1594, a "Company of Far Lands" was founded in Amsterdam, with the aim of sending two fleets to the spice islands of Maluku. The first fleet sailed in 1596 and returned in 1597 with a cargo of pepper, which more than covered the costs of the voyage. The second fleet, departing in 1598 and returning in 1599, returned its investors a 400% profit. The success of these voyages led to the founding of a number of companies competing for the trade. The competition was counterproductive to the companies' interests as it threatened to drive up the price of spices at their source in Indonesia while driving them down in Europe.
# Dutch Empire/Language

A small minority of Indonesians can speak a degree of Dutch. Many Indonesian lawyers and historians can speak Dutch due to historical ties, as do those of the older generation who were schooled in Dutch. Many Indonesian words have come from Dutch. One scholar argues that 20% of Indonesian words can be traced back to Dutch words.
The century and half of Dutch rule in Ceylon and southern India left few to no traces of the Dutch language. In Suriname, Dutch has left its mark as it is the official language of the country. About 60% of the population speaks it as their first language, and most of the remaining 40% know Dutch as well. In Aruba, Bonaire, and Curaçao, Dutch is the official language but spoken as a first language by only by seven to eight percent of the population, although most people on the islands can speak the language and the education system on these islands is in Dutch at some or all levels. The lingua franca of Aruba, Bonaire and Curaçao is Papiamento, a creole language that originally developed among the slave population of the islands. The population of the three northern Antilles, Sint Maarten, Saba, and Saint Eustatius, is predominantly English-speaking.
In New Jersey in the United States, a dialect of Dutch, Jersey Dutch, spoken by descendants of seventeenth century Dutch settlers in Bergen and Passaic counties, was noted to still be spoken as late as 1921. Former American President Franklin Roosovelt said he remembered hearing Dutch spoken when he was growing up in the Hudson Valley.
Arguably, greatest linguistic legacy of the Netherlands was in its colony in South Africa, which attracted large numbers of Dutch farmer (in Dutch, Boer) settlers, who spoke a simplified form of Dutch called Afrikaans, which is largely mutually intelligible with Dutch. After the colony passed into British hands, the settlers spread into the hinterland, taking their language with them. Today, there are 10 million people for whom Afrikaans is either a primary and secondary language, compared with 25 million worldwide speakers of Dutch.
# Dutch Empire/Introduction

Hello, and welcome to the History of the Dutch Empire. Here we will cover the history of the Dutch colonies, as well as the Netherlands itself. I encourage anyone to contribute, as many sections currently do not cover enough material. So any help would be appreciated, particularly with my spelling which is not that good.
# Dutch Empire/Place Names

New York City was once called New Amsterdam. Parts of New York City are named after original Dutch colonial settlements: Brooklyn, after Breukelen, Harlem after Haarlem. Staten Island, was originally called Staten Eylandt after the Dutch parliament (Staten) who paid for the expeditions up the Hudson River. The place Old Town on Staten Island was originally called Oude Dorp, which in English means Old Town.
The last Director-General of the colony of New Netherland, Peter Stuyvesant, has given his name to several streets, a neighborhood and a few schools in New York City. In Columbia County, near Albany, there is a town named Stuyvesant.
The following towns in New York have names that were derived from Dutch: Claverack, Cobleskill, Greenbush (East and North), Kinderhook, Plattekill, Nassau, Poestenkill, Rensselaer, Saugerties, Valatie, Voorheesville, Watervliet, and Wynantskill.
Many towns and cities in Suriname share names with cities in the Netherlands, such as Alkmaar, and Groningen.
# Dutch Empire/Kingdom of Holland

Kingdom of Holland was set up by Napoleon Bonaparte as a puppet kingdom for his third brother, Louis Bonaparte, in order to better control the Netherlands in 1806. The name of the leading province, Holland, was now taken for the whole country. In 1807 Prussian East Frisia and Jever were added to the kingdom but in 1809, after an English invasion, Holland had to give over all territories south of the river Rhine to France.
King Louis did not perform to Napoleon's expectations, he tried to serve Dutch interests instead of his brother's . Louis had learned the Dutch language, and proclaimed himself to be a "Hollander" as soon as he stepped into the country. In 1810, under heavy pressure from his brother, Louis abdicated and the Kingdom was annexed into the French Empire.
The kingdom of Holland covered the area of present day Netherlands, with the exception of Limburg, and parts of Zeeland, which were French territory. East Frisia (in present day Germany) was also part of the kingdom.
In 1810 the British invaded the Dutch island of Java, and their other possessions in the East Indies. This started the Anglo-Dutch Java War. By the end of 1811 the entire island was under British control.