Clojure in Belarusian GU
This semester (fall 2012) conducted a course on Clojure in the Belarusian GU. Fasting will be described elective: causes, program, jobs, results, impressions.
the
Beginning
I'm a 5th year student of the faculty of applied mathematics and Informatics in Belarusian state University. Fond of functional programming, but in the course of our training at the University of FP is not considered at all, and programming paradigms were only OOP (java, c++). I believe that students majoring in Informatics must have at least some idea about the OP (and preferably other paradigms). So I decided to try a little bit to rectify the situation and to hold an elective. And because of the experience and knowledge to conduct a course on FP in General, I have a little, we decided to focus on more applied and simple in Clojure. Clojure functional language, a modern dialect of Lisp running on JVM basically.
As the pictures will be used screenshots of the tasks that had to be solved during the course.
Snake. Task — to write a bot.
the
syllabus
-
the
- Introduction to Clojure. Description of the syntax. Function. Anonymous function. Simple arithmetic and logical operations. Recursion. the
- Working with collections. Different types of collections: vector, set, associative array (map). Functions for working with them: map, reduce, filter, etc. the Immutability of the collections. the
- Working with collections. Lazy calculations. Destructuring. the
- Tools for working with mutable state. Atoms, agents, REFs (ref). Transactional memory. the
- Macros. the
- the Principle of operation of immutable data structures. Reviewed the implementation of the PersistentVector PersistentHashMap the
- Multimethods. the
- Protocols, types and records (protocols, types, records). the
- a Little λ-calculus. Arithmetic and Booleans in λ-calculus.
on the λ-calculus. Recursion. The implementation of lists in λ-calculus. An example of a typed λ-calculus.
The Game "Fool". Bot player below.
the
Tasks
After each class was given homework. Homework was 2 types: the solution of problems on 4clojure, and the solution of interactive tasks. 4сlojure website with a small set of tasks from the very simple to the very complex and online test. On 4clojure is a convenient feature — the ability to see solutions of other participants after you have solved a problem. I think it helped, to learn how can be "more functional" to solve the problem.
Interactive experiences — problems that must be solved in Clojure, the solution of most of them pre-rendered, ie you can see the result of the decision. For the visualization library was used Quil (a wrapper over Processing'om for Clojure code) and Incanter (used for plotting).
Task list:
the
-
the
- defense. Need to knock down the goal of setting the angle of the shot. There were 2 options. First, without gravity, the missile flies in a straight line, a goal is also flying in a straight line. The second option took into account the gravity (you can shoot canopy), the purpose of hanging in the air without moving. the
- Snake. To implement a bot for the snake. The bot needs to take into account the presence of walls. the
- a Fool. To implement a bot for a card game "Durak". Mostly implemented bot without memorizing previous States. But one person wrote the bot with memory. the
- k-means. Implement the k-means algorithm with a fixed k. And also try to write an algorithm that will pick the best k. the
- Symbolic differentiation. Write a function that takes Clojure expression, e.g.
(* 2 x)
, the output of the derivative gives:(+ (* 0 x) (* 2 1))
. To simplify the obtained result is not required. Visualization — graphing a function and its first and second derivatives.
on the λ-calculus. To implement arithmetic functions (+, -, *, ^). Write a recursive function to calculate the sum of an arithmetic progression of integers from 1 to n. Implement functions for working with lists (head, tail, cons, empty?). Extra task — write map and reduce for such lists.
Wireworld cellular automaton. The machine implements a logical XOR.
the
Process
Classes are held on Saturdays, 1 time per week. For out-of-class communication was used the Google-group. Tasks at 4clojure naturally checked on the site itself. For the solution of interactive tasks the students forcall github repository and decided to fork. A check was very convenient, especially given the fact that github allows you to comment on commits. So I could point to ineffective or not-so-beautiful places in decisions. All of course in the beginning was the imperative solution using explicit cycles, often use mutable state and the atoms where they really were unnecessary. Unfortunately I can not accurately assess the extent to which decisions by the end of the elective, as they become more functional, but I hope that steel.
the
Projects
Was the idea to split into groups of 2-3 people and each group during the semester doing my project. Was offered the following options: multiplayer snake, simple physics engine, a utility for processing text documents (statistics, other), make an analog this application. And of course you can propose. But the idea somehow didn't find a response. Possible homework assignments, and so enough, given that my elective was voluntary and the University does not apply.
Symbolic differentiation. f = sin(2x). Depicts f, f', f"
the
Motivation and gifts
At the beginning of the course homework was not controlled. And she somehow little was done, though according to an anonymous survey "was interesting"... Then came the idea to reward some buns for the decision domashek. After discussion with friends the idea was proposed that I really liked: the one who will perform more than 50% of the homework, will receive a personalized mug with your result. So that was the incentive to perform at 100%, then 90% of eye blisters. For this purpose was created the rating plate in googledata, which kept record of students ' progress.
By the way, in the end I asked whether it had helped in performing tasks. All said, Yes. Most motivated, they could see your progress. Some explained the mug itself :)
the
Results
On the final survey, we can conclude that the elective is much. I think he was useful, even if they will not use clojure or FP in everyday life. As for me, I loved it. By the way, the idea of elective originated on pairs of pedagogy, where we all complained that our higher education is bad and we are taught to not need anyone stuff. Then our teacher asked why do we do anything about not trying to do.
Thank you my friends for the ideas with the tasks, mugs and helping to pay for the mugs :)
And finally, a few facts:
the
-
the
- On the elective were 10 people, mostly 2nd year students. the
- Was set to 65 problems with 4clojure. On average, each decided 59.
- 3 student completed the tasks 100%. Average score: 88% the
- Everyone who did homework and stayed until the end received a mug. These 8 people. 2 people visited, but did not perform the tasks.
One of the students found 1 serious bug in Quil. the
Personalized mugs.
Update
If anyone will be interested in the generation of images for mugs, the script is available at github: http://nbeloglazov.github.com/clojure-mug-template/