

In this semester (autumn 2012), an optional course on Clojure was conducted in Belarusian State University. The post will describe the optional: reasons, program, tasks, results, impressions.
Start
I am a 5th year student of the Faculty of Applied Mathematics and Computer Science at BSU. I take a great interest in functional programming, but in the course of our study at the University, the FP is not considered at all, and from the programming paradigms only OOP (java, c ++) passed. I believe that students who study computer science should have at least some idea of the FP (and preferably other paradigms). Therefore, I decided to try to at least a little rectify the situation and conduct an elective. And since I generally have little experience and knowledge for carrying out electives on AF in general, I decided to focus on more practical and simple - in Clojure.
Clojure is a functional language, a modern lispa dialect, executed mainly on the JVM.
Screenshots of tasks that had to be solved during the course will be used as pictures.

Snake. The task is to write a bot.
')
Course program
- Introduction to Clojure. Syntax description. Functions. Anonymous functions. Simple arithmetic and logical operations. Recursion
- Work with collections. Different types of collections: vector, set, associative array (map). Functions for working with them: map, reduce, filter, etc. The immutability of collections.
- Work with collections. Lazy computing. Destructuring.
- Tools for working with a changeable state. Atoms, agents, refs (ref). Transactional Memory.
- Macros.
- The principle of operation of immutable data structures. Disassembled implementation of PersistentVector and PersistentHashMap
- Multimethods.
- Protocols, types and records (protocols, types, records).
- A bit of λ-calculus. Arithmetic and logical values in λ-calculus.
- λ-calculus. Recursion Implementation of lists in λ-calculus. An example of a typed λ-calculus.

The game "Fool". Player's bot - bottom.
Tasks
After each class homework was given. Homework assignments were of 2 types: solving 4clojure tasks and solving interactive tasks.
4lojure - a site with a set of small problems from very simple to very complex and online check. At 4clojure there is a convenient feature - the ability to look at the decisions of other participants after they have solved the problem. I think it helped to find out how to solve the problem “more functionally”.
Interactive tasks are tasks that need to be solved on Clojure, while the solution of most of them are visualized in advance, i.e. it was possible to look at the result of the decision. For the visualization, the
Quil libraries (wrapper over the
Processing for the slope) and
Incanter (used for plotting) were used.
Task list:
- Air defense. It is necessary to knock down the target by setting the angle of the shot. There were 2 options. The first - without gravity, the rocket flies in a straight line, the target also flies in a straight line. The second option took into account gravity (you can shoot a canopy), the target hangs in the air without moving.
- Snake. Implement a snake bot. Bot should take into account the presence of walls.
- Fool. Implement the bot for the card game "Fool". Basically, the bot was implemented without memorizing previous states. But one person still wrote a memorized bot.
- Cellular machine. Release the “framework” for a 2-dimensional cellular automaton: write visualization, make interaction with the program possible (stop, change cell states), and most importantly, make it possible to simply connect arbitrary rules (such as Life, Brian's Brain , Wireworld , etc.).
- k-means. Implement the k-means algorithm with a fixed k. And also try to write an algorithm that will select the best k.
- Character differentiation. Write a function that takes an input to an input expression, for example
(* 2 x)
, gives the output a derivative: (+ (* 0 x) (* 2 1))
. To simplify the result is not required. Visualization - plotting functions and its first and second derivatives. - λ-calculus. Implement arithmetic functions (+, -, *, ^). Write a recursive function to calculate the sum of an arithmetic progression of numbers from 1 to n. Implement functions for working with lists (head, tail, cons, empty?). An additional task is to write map and reduce for such lists.

Cellular Wireworld machine. The automaton implements a logical XOR.
Process
Classes were held on Saturdays, 1 time per week. For extracurricular communication used Google-group. Tasks for 4clojure were naturally checked on the site itself. To solve interactive problems, students forked a repository on a githaba and solved it in a fork. It was very convenient to check, especially considering that the githab allows you to leave comments on commits. So I could point out inefficient or not so beautiful places in the solutions. Of course, everyone at first had imperative solutions that use explicit cycles, often using mutable states and atoms where they actually were redundant. Unfortunately, I cannot accurately assess how much the solutions have changed by the end of the elective, how much they have become more functional, but I hope that they have become.
Projects
There was an idea - that everyone should be divided into groups of 2-3 people and each group would do its own project during the semester. Such options were offered: a multiplayer snake, a simple physics engine, a utility for processing text documents (statistics, something else), to make an analogue of
this application. And of course you could offer your options. But the idea somehow did not find a response. Perhaps there was enough homework, given that my elective was voluntary and did not apply to study at the university.

Character differentiation. f = sin (2x). Depicted f, f ', f' '
Motivation and gifts
At the beginning of the elective, the home was not controlled at all. And it was somehow poorly executed, although judging by the anonymous survey, “it was interesting” ... Then the idea to reward with some kind of buns for solving homework appeared. After discussion with friends, an idea was proposed that I really liked: the one who performs more than 50% of the homework will receive a personalized mug with his result. So there was a stimulus to execute 100% so that then 90% of the eye would not be sore. For this purpose, a rating was created - a sign in the city of Google where the records of student success were recorded.
By the way, at the end I asked if it helped with the assignments. Everyone said that, yes. Most motivated rating, in which they could see their progress. Some were motivated by the mug itself :)
Results
According to the final survey, we can conclude that I liked the elective option. I think it was useful, even if they would not use clojure or AF in everyday life. As for me, I really liked it. By the way, the idea of elective was born on the pairs of pedagogy, where we all complained that our higher education is bad and we are taught no useless nonsense. Then our teacher asked why we ourselves are not trying to do anything about this.
Thanks to my friends for ideas with tasks, circles and assistance in paying for mugs :)
And finally, a few facts:
- Eleven people attended the course, mostly 2-year students.
- 65 tasks with 4clojure were set. On average, each decided 59.
- 8 interactive tasks were set. On average, each decided 6.
- One student found one serious bug in Quil.
- 3 students completed assignments at 100%. Average result: 88%
- All those who did homework and held out until the end got a mug. Such 8 people. 2 people visited, but did not fulfill the task.

Name cups.
UpdateIf anyone is interested in generating images for mugs, the script is available on the githaba:
http://nbeloglazov.github.com/clojure-mug-template/