1: Introduction

1.1: The functional and the imperative paradigms

C functional random
int functional_random( int seed ) {
  return 22 * seed % 37 ;
}
C using functional random
int first  = functional_random( 1 ) ;
int second = functional_random( first ) ;
int third  = functional_random( second ) ;
C imperative random
int seed = 1 ;
int imperative_random( void ) {
  seed = 22 * seed % 37 ;
  return seed ;
}

1.1.1: The advantage of state

C imperative dice
int imperative_dice( void ) {
  return imperative_random() % 6 + 1 ;
}

1.1.2: The advantage of pure functions

C two dice, functional style
int x = functional_random( r ) ;
int y = functional_random( s ) ;
int dice = x%6 + 1 + y%6 + 1 ;

1.1.3: Idiomatic building blocks in C

1.2: Guide to the book