Scheme Functional Programming Language CSC 337 Concepts of Programming Languages Qassim University College of Computer –IT department Ms.Sadaf Ambreen Abbasi . Reham AL blihed Muna AL rajhi
Outline About Scheme programming language A Simple Idea of Scheme Program Type Primitive Numeric Functions Type Predicates General Example of Scheme Language
About Scheme programming language Scheme is primarily a functional programming language . It shares many characteristics with other members of the Lisp programming language family. Scheme's very simple syntax . The Scheme language, which is a dialect of LISP, was developed in the mid-1970s.
A Simple Idea of Scheme Program Some of the differences between Scheme program and C program. C Scheme (2 + 3 + 4) (+ 2 3 4) Arithmetic operations ((2 * 3) + (4 * 5)) (+ (* 2 3) (* 4 5)) Arithmetic operations int sq ( int x) { return (x * x) } (define ( sq x) (* x x)) Function
Type Primitive Numeric Functions : Scheme includes primitive functions for the basic arithmetic operations. These are +, −, *, and /, for add, subtract, multiply, and divide. Expressions are written in the form ( function_name arguments) Example Expression with Parameter & without Parameter Example of numeric function:
Type Predicates Functions. A R redicate Functions is a boolean functions (some representation of either true or false)
General Example of Scheme Language Example: using special form cond
General Example of Scheme Language Power The Power Function use mathematical induction and then translate that definition using recursion. Exponentiation (assume m ≠0) m^ = 1 m^n = m • m^n-1 for n>0 Example:
General Example of Scheme Language Max of three number Example:
General Example of Scheme Language Categorize Categorize is function to check if number positive or negative or zero.
General Example of Scheme Language Sum of the members of a list Parameter: a list of numbers. Result: the sum of all the numbers in the list . Example:
General Example of Scheme Language Length Example : The recursion used in length is called " cdr -recursion". –At each step, a shorter list is passed to the next function call.
General Example of Scheme Language Filter Filter function built-in scheme, which takes a predicate and a list and returns those elements of the list for which the predicate is true. Example: