Skip to main content

Posts

Showing posts from September, 2012

Functional Programming in Scala: Getting Started

Functional Programming is becoming increasingly popular because it offers an attractive method for exploiting parallelism for multicore and cloud computing. As the name indicates functional programming focuses on the functions. A functional programming language is one which does not have mutable variables, assignments, loops, and other imperative control structures. Some of the important functional programming languages are   Lisp, Scheme, Racket, Clojure SML, Ocaml, F# Haskell (full language) Scala Smalltalk, Ruby (!) REPL(Read-Eval-Print)   An interactive shell or REPL lets one write expressions and responds with their value. Scala REPL can be started by typing >scala For example; >scala 23+34 57 >scala def length = 10   length: Int >scala def breadth = 20 breadth: Int >scala length*breadth 200 Parameters and Return type in def Definition may consist of parameters. Sometimes return types are also specified in the definition....

Abstraction Using Higher Order Procedures

Procedures are, in effect, abstractions that describe compound operations on numbers independent of the particular numbers. Yet even in numerical processing we will be severely limited in our ability to create abstractions if we are restricted to procedures whose parameters must be numbers. Often the same programming pattern will be used with a number of different procedures. To express such patterns as concepts, we will need to construct procedures that can accept procedures as arguments or return procedures as values. Procedures as arguments Procedures are often used as the arguments of an another procedure. This provides a higher level of abstraction in programming. For example consider a procedure to find out the sum of squares of numbers between a range. The procedures inc and square are used as the arguments of the procedure sum, which is generalised as follows.                 (define (inc...

Elements of Programming in Scheme

A powerful programming language provides a framework to interpret our ideas of processes. It generally combines small procedures to complex ones. Usually there are three steps to accomplish this. primitive expressions , which represent the simplest entities the language is concerned with, means of combination , by which compound elements are built from simpler ones, and means of abstraction , by which compound elements can be named and manipulated as units. Some very basic ideas in manipulating with the data are given below. Expressions   A very simple expression is a number. Simple expressions are combined to form complex ones. For example:                   (+ 2  3  4) is an expression where + is the operation and 2,3,4 are the oparents. The expression can be made more complex by combining simple expressions as given below:              ...