Paradigms

<aside> πŸ“– A programming paradigm is an approach to programming based on a coherent set of principles or a mathematical theory.

</aside>

Each language implements one or two paradigms. We can understand every language that exists if we understand the few paradigms that exist.

When we resolve a complex problem we have to use multiple paradigms. This combination of paradigms is done using kernel language.

Kernel language

<aside> πŸ“– The kernel language is the first part of the formal semantics of a paradigm or programming language. It is its simple core language that contains its essential concepts. Kernel languages are very similar between different paradigms and most of the concepts are in common.

</aside>

Functional programming kernel program

β†’ All intermediate results of calculations are visible.

Length of a list

fun {Length Xs N}
	case Xs
	of nil then N
	[] X|Xr then {Length Xr N+1}
	end
end

A function is translated as a procedure with one extra argument, which gives the function’s result.

N={Length L Z} is equivalent to: {Length L Z N}

# Kernel language 
proc {Length Xs N R}
	case Xs
	of nil then R=N
	else
		case Xs
		of X|Xr then
			local N1 in
				N1=N+1
				{Length Xr N1 R}
			end
		else
			raise typeError end 
		end
	end
end

All practical programs can be translated into kernel language β†’ all hidden variables become visible :

  1. Functions become procedures with one extra argument
  2. Nested expressions become sequences, with extra local identifiers
  3. Each pattern has its own case statement

β‡’ Kernel programs are longer

β‡’ It is easy to see when programs are tail-recursive

β‡’ It is easy to see exactly how programs execute

The OZ language

Variables

<aside> πŸ“– A variable is a value stored in memory.

</aside>

<aside> πŸ“– An identifier is the name of a variable.

</aside>