📜 ⬆️ ⬇️

Clojure in the Belarusian State University

BSU logo
Clojure logo
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.

Task 2. Snake.
Snake. The task is to write a bot.
')

Course program


  1. Introduction to Clojure. Syntax description. Functions. Anonymous functions. Simple arithmetic and logical operations. Recursion
  2. 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.
  3. Work with collections. Lazy computing. Destructuring.
  4. Tools for working with a changeable state. Atoms, agents, refs (ref). Transactional Memory.
  5. Macros.
  6. The principle of operation of immutable data structures. Disassembled implementation of PersistentVector and PersistentHashMap
  7. Multimethods.
  8. Protocols, types and records (protocols, types, records).
  9. A bit of λ-calculus. Arithmetic and logical values ​​in λ-calculus.
  10. λ-calculus. Recursion Implementation of lists in λ-calculus. An example of a typed λ-calculus.


Task 3. Fool.
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:


Task 4. Cellular automaton.
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.

Problem 6. Derivatives.
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:

Mugs
Name cups.

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

Source: https://habr.com/ru/post/164701/


All Articles