# Teaching Elixir at the Federal University of Technology — Parana

I am teaching Elixir to first year students at UTFPR. Part of these students (approximately half of them) is in their first semester and most of this half had never any experience with computer programming. The other half is in their second semester and they had a course on programming (using C) during the first semester.

I am not teaching Elixir as part of a functional programming course. Nor as part of a programming paradigms course or as an introduction to programming.

I want them to learn Elixir so that they can implement some programs for my Logic in Computing course.

Elixir came from Erlang whose syntax came from Prolog which, some say, is an abbreviation for “Programming in Logic”.

There are several things I want them to do. The first thing is to implement a function that receives as input a formula and a “language” in classical propositional logic and answers if it is a well-formed formula.

But I don’t want them to write a parser. At least no now. So, they will use Elixir’s data structures and values like the following to represent formulas:

Atomic formulas:

:p1

:p2

Formulas with unary connectives (such as “not”):

{:not, :p1}

{:not, {:not, :p1}}

Formulas with binary connectives (“and”, “or”, “implies”):

{:p1, :and, :p2}

{:p1, :or, {:p2, :implies, :p3}}

{:p1, :or, {:not, {:p2, :implies, :p3}}}

The function will receive two arguments:

• the formula, represented as above
• the language, represented as {[:p1, :p2, :p3], %{:not => 1, :and => 2, :or => 2, :implies => 2}}

So, the language is a tuple containing the list of atoms (propositional formulas) allowed and the connectives and their arities. The idea is in a later moment ask them to check if the formula contains only allowed atoms and if the connective instances in formulas are those allowed and respect their arity. But at this moment I just want the to ignore the language and verify if a formula is well-formed using pattern matching, is_atom/1 and recursiveness.

So, the function will be something like this:

Logic.well_formed?(:p1) returns true

Logic.well_formed?(“a”) returns false

Logic.well_formed?({:not, :p, :and, :q}) returns false

Logic.well_formed?({:not, {:p, :and, :q}}) returns true

And so on.

Not so easy but not so difficult.

For the second moment they will need the Enum module.