SlideShare a Scribd company logo
Introduction Suresh B Velagapudi, Ph.D Chief Technical Officer Mayera Software Solutions, LLC
Scalastic Warning “ Prolog Technology for temporal reasoning in relational databases” In spite of  Ph.D for the above research work,  I love to code in and talk about scala. I warn you up front  that Your present coding style is at risk.
Scala as a Practical Declarative Language
Weltanschauung Based on Peace, Practicality and Productivity Not on Power, Pride, Prejudice or Prosperity etc.
In A Nutshell Declarative Programming Style in Scala makes software product development from Proof-of-Concept to Deployment enjoyable.
Abbreviations MOD –  Martin ODersky DOS – Designer Of Scala SBE – Scala By Example ASS96 – Abelson Sussman Sussman MIL78 – Milner COW – Check Out Wikipedia DOP – A Discipline Of Programming 1976
Ramanujan scala>  for  {hardyTaxi <- List.range(1000,2000) j <- List.range(1,20) k <- List.range(1,20) l <- List.range(1,20) m <- List.range(1,20) if((j*j*j)+(k*k*k) == hardyTaxi && (l*l*l)+(m*m*m) == hardyTaxi) && j!= l && k!= m && j!= m}  yield  (i,j,k,l,m) res2: List[(Int, Int, Int, Int, Int)] = List((1729,1,12,9,10) The smallest number expressible as the sum of two cubes in two different ways.
Dijkstra on non-imperative in 1985 The simplest way to characterize the difference between imperative programming languages and non-imperative ones is that in the reasoning about imperative programming you have to be aware of the 'state' of the machine as is recorded in its memory.
An expression is non-imperative scala> if(12*12*12 + 1*1*1 == 10*10*10 + 9*9*9) 1729 else false res5: AnyVal = 1729 scala> if(12*12*12 + 1*1*1 == 10*10*10 + 9*9*9) 1729 else 0 res6: Int = 1729
Declarative Programs are Executable Specifications //from SBE page 72 def isPrime(n: Int) = List.range(2, n) forall (x => n % x != 0) //from SBE page 80 for { i <- List.range(1,10) j <- List.range(1, i) if isPrime(i+j) } yield (i, j)
Pythagorean tuple that sums to 1000 for  {i <- List.range(1,1000) j <- List.range(1,1000) k <- List.range(1,1000) if (i+j+k==1000 && i*i + j*j == k*k) }  yield  (i, j, k) res6: List[(Int, Int, Int)] = List((200,375,425), (375,200,425))
Declarative Reading is  Math Definition The definition of  isPrime   n ,  an integer ,  is,  given a range of integers 2 thru   n  for all X,  n  modulo  x  is not zero def fact(n: Int): Int =  n*fact(n-1) def isPrime(n: Int) = List.range(2, n) forall (x => n % x != 0) The definition of  factorial   n ,  an integer ,  is,  n   times   factorial  n -1
Separation of Concerns – Dijkstra We should not head for a mathematically correct program that is so badly engineered that is beyond salvation. --Dijkstra (1976) A Discipline of Programming
Recursion vs iteration //recursive procedure (described in ALGOL 60 ): procedure  whiledo (condition, statement);  begin if  condition  then begin  statement;  whiledo (condition, statement);  end end   Although correct, it hurts me. DOP Preface
A Generation Later // SBE page 6 def While (p: => Boolean) (s: => Unit) { if (p) { s ; While(p)(s) } } Later generations will pronounce as their judgment that  in the last fifteen years, recursive solutions have been placed upon too high a pedestal. DOP 178
Thank You Samar Singh My math comp mentor of late seventies and early eighties.
Tail Recursive Functions //SBE page 18 def gcd(a: Int, b: Int): Int = if (b == 0) a else  gcd(b,a % b)   /Answer to Exercise 4.6.1 of SBE page 19 def  mf (x: Int): Int =  myf (x, 1); def  myf (x:Int, Acc: Int): Int  =  if(x==1) Acc else myf(x-1, Acc * x)
Horner's rule def horner(L:List[Int], X : Int): Int = { def horneri(L:List[Int], X : Int,Acc: Int): Int = { if(L.isEmpty) Acc  else  horneri(L.tail,X, Acc*X + L.head)} horneri(L,X,0)}
Internal Rate of Return internal rate of return for an investment is the discount rate that makes the net present value of the investment's cash flow stream equal to zero.
Hilbert's Tenth Problem Determination of the solvability of a  Diophantine equation. Given a Diophantine equation with any number of unknown quantities and with rational integral numerical coefficients: To devise a process according to which it can be determined by a finite number of operations whether the equation is solvable in rational integers. A Diophantine equation  is a  polynomial   equation  where the variables are  integers  only.
An Oxymoron in 1989? Programming is essentially procedural. Real Engineers program by FORTRAN Arrays, or C pointers. Philosophers and Logicians make Declarations. Ha! Ha!
A Syllogism All humans are mortal. Socrates is human. So Socrates is mortal. Ha! Ha!
Modus Ponens  in PROLOG //All humans are mortal. mortal(X) :-  human(X). //Socrates is human. human( socrates ). human( suresh). ?- human(X). X = socrates ?- mortal(X). X = socrates  ; X = suresh.
Second Order Predicate ?- setof(X,mortal(X),List). List = [socrates, suresh]
Concatenation of Lists The concatenation of an empty list with a list L  is L. The Concatenation of a list having  head H and tail T,  with a list L,  is a list with head H and a tail that is the concatenation of T and L. concatenation([], L, L). concatenation([H|T], L, [H|CTL])  :-  concatenation(T,L, CTL). ?- concatenation([socrates,suresh],[addanki],L). L = [socrates,suresh,addanki] CTL H T L
Concatenation in Scala def concatenation[G](xs: List[G], ys: List[G]):  List[G] = xs match { case List() => ys   case H :: T => H :: concatenation(T,L) } CTL H T L
Predicate Logic as a Programming Language – Kowalski (1974) Program is a set of axioms. Computation is a constructive proof of a goal statement from the program
Thanks to Trevor Legall First theory book in 1984 Foundations of Logic Programming By J.W.Lloyd
Floating Point Number Crunching is not the only game in computingville. Combining qualitative reasoning and quantitative Techniques to  improve mechanical and electrical Product design.
Newton's method def sqrt(x: Double) = { def sqrtIter(guess: Double, x: Double): Double = if  (isGoodEnough(guess, x)) guess else  sqrtIter(improve(guess, x), x) def improve(guess: Double, x: Double) = (guess + x / guess) / 2 def isGoodEnough(guess: Double, x: Double) = abs(square(guess) - x) < 0.001 sqrtIter(1.0, x) }
Algorithms + Data Structures = Programs That was my fault. I included it because I liked it, and that for two reasons: 1. (z /: xs) (op) looks like an abbreviation of a left leaning tree with a `z' on the lower left end (at least to me). I.e. something like op /  \  op  x1 /  \  z  x0  That's the tree I always draw when I explain fold left. 2. (z /: xs) has the operands in the ``right'' order.
Algorithm = Logic + Control The logic component determines the meaning of the algorithm. The control component only affects its efficiency.
Algorithm Logic component Abstract Procedure Definitions Definitions of data structures represented by terms Direction e.g. (top-down or bottom-up) Strategy for execution of procedure calls (e.g. sequential or parallel Strategy for investigating alternative procedures Control component Scheme for storing data represented relationally
Which  Factorial Program? def fact(n: Int) = 1 to n reduceLeft (_*_)  def fact(n: Int):Int =  If (n == 0) 1  else n * fact(n-1) def mf(x: Int): Int = myf(x, 1); def myf(x:Int, Acc: Int): Int  =  if(x==1) Acc  Else myf(x-1, Acc * x)
Which Reverse? //SBE page 68 def reverse[A](xs: List[A]): List[A] = xs match  case Nil => Nil  case x :: xs => reverse(xs) ::: List(x)} //SBE page 75 def reverse: List[A] = ((Nil: List[A]) /: this) {(xs, x) => x :: xs} //Is Tail Recursive Reverse Possible?
Tail Recursive Reverse def reverse[T](l: List[T]): List[T] = { def reverseR(result: List[T], curList: List[T]): List[T] = curList match { case Nil  => result case h :: tail => reverseR(h :: result, tail) } reverseR(Nil, l) }
Sample Conversation with ELIZA I am unhappy. >> How long have you been unhappy? Six months. Can you help me. >> What makes you think I  help you? You remind me of my father and brother >>Please tell me more about father. I like teasing father. >>Does anyone else in your family like teasing father? No, only me. >> Please go on
ELIZA in Scala def response(stimulus : List[String]) :  Unit = stimulus match { case List(&quot;i&quot;,&quot;am&quot;, x) => println(&quot;How long have  you been&quot; + x+ &quot;?&quot;) case List(x, &quot;you&quot;, y, &quot;me&quot;) => println(&quot;What  makes you think I &quot; +y+&quot; you?&quot;) case List(&quot;i&quot;,&quot;feel&quot;, x) => println(&quot;Do you often  feel that way?&quot;) case List(&quot;i&quot;, &quot;like&quot;, x)  => println(&quot;Does any one  else in your family like &quot; + x +&quot; ?&quot;) case _ => println(&quot;Please Go On&quot;) }
Machine Learning Suppose ELIZA wants to improve.  Weka switched to java from prolog. SWeka will be in Scala.
Future of Scala Pessimistic Scenario: Functional freaks and java addicts fight to finish to scare away all scala enthusiasts. Optimistic Scenario: Complete Domination of the entire computing scene Most likely scenario:  Solid apps come up. Steady impressive growth for next decade.
Pollak's cpp Principle Each morning that I sit down at the keyboard and start coding Scala, I get a feeling of  calm, peace, and power.  I know that I’m going to have another day of taking the ideas in my head and reducing them to a running computer program that will be fast and low in defects.
Pollak  But most importantly, Scala taught me to program and reason about programming differently. I stopped thinking in terms of allocating buffers, structs, and objects, and of changing those pieces of memory. Instead, I learned to think about most of my programs as transforming input to output. This change in thinking has lead ( sic ) to lower defect rates, more modular code, and more testable code.
Tony Hoare in QCON 2009 One 
day
... • Software 
will 
be 
the 
most
 reliable
 component Of 
every 
product
 which
 contains 
it. • Software 
engineering
 will
 be
 the 
most Dependable 
of
 all 
engineering 
professions. • Because 
of 
the
 successful 
interplay
 of research – 
into
 the
 science 
of
 programming – and
 the
 engineering
 of
 software
I have a dream One day..... My fellow scalastics'  programs will be judged not by the colorful confusion of syntax  but by the content of the character sequences with  declarative semantics.
Remember  SURESH S emantics   independent of execution is the aim.  U niversal quantification is  for  stating facts and rules. R ecursion is natural and  efficient with TRO Call. E xtensive use of pattern matching  is desirable. S tatic typing of generics avoids awful defects.   H igher order functions  help declarative programming.
The End Thank You

More Related Content

What's hot (20)

PDF
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and Scala
Philip Schwarz
 
PDF
Monoids - Part 1 - with examples using Scalaz and Cats
Philip Schwarz
 
PDF
Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Philip Schwarz
 
PDF
Applicative Functor - Part 3
Philip Schwarz
 
PDF
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
PPTX
Software Construction Assignment Help
Programming Homework Help
 
PDF
Monad Transformers - Part 1
Philip Schwarz
 
PDF
Programming with matlab session 1
Infinity Tech Solutions
 
PPTX
Computer Science Assignment Help
Programming Homework Help
 
PDF
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
PDF
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Philip Schwarz
 
PDF
Abstracting over the Monad yielded by a for comprehension and its generators
Philip Schwarz
 
PPTX
Matlab Tutorial
Ahmad Siddiq
 
PPT
Introduction to MATLAB
Damian T. Gordon
 
PDF
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
Philip Schwarz
 
PDF
Scala 3 enum for a terser Option Monad Algebraic Data Type
Philip Schwarz
 
PPT
Scilab for real dummies j.heikell - part3
Scilab
 
PDF
Programming in Scala - Lecture Three
Angelo Corsaro
 
PDF
Functors
Philip Schwarz
 
PPT
Matlab1
guest8ba004
 
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and Scala
Philip Schwarz
 
Monoids - Part 1 - with examples using Scalaz and Cats
Philip Schwarz
 
Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Philip Schwarz
 
Applicative Functor - Part 3
Philip Schwarz
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
Software Construction Assignment Help
Programming Homework Help
 
Monad Transformers - Part 1
Philip Schwarz
 
Programming with matlab session 1
Infinity Tech Solutions
 
Computer Science Assignment Help
Programming Homework Help
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Philip Schwarz
 
Abstracting over the Monad yielded by a for comprehension and its generators
Philip Schwarz
 
Matlab Tutorial
Ahmad Siddiq
 
Introduction to MATLAB
Damian T. Gordon
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
Philip Schwarz
 
Scala 3 enum for a terser Option Monad Algebraic Data Type
Philip Schwarz
 
Scilab for real dummies j.heikell - part3
Scilab
 
Programming in Scala - Lecture Three
Angelo Corsaro
 
Functors
Philip Schwarz
 
Matlab1
guest8ba004
 

Viewers also liked (6)

PDF
Introducing Pattern Matching in Scala
Ayush Mishra
 
PPTX
From Imperative to Functional Programming (for Absolute Beginners)
Alex Bunardzic
 
PPTX
FUNCTIONS OF ENGLISH AS A LANGUAGE
Karthika Shibu
 
PPS
Personality Development ppt by Taher Salim INDORE
Taher Salim
 
PPTX
Language functions and notions
Ian Lao
 
PPTX
Language functions
Syeda Baneen
 
Introducing Pattern Matching in Scala
Ayush Mishra
 
From Imperative to Functional Programming (for Absolute Beginners)
Alex Bunardzic
 
FUNCTIONS OF ENGLISH AS A LANGUAGE
Karthika Shibu
 
Personality Development ppt by Taher Salim INDORE
Taher Salim
 
Language functions and notions
Ian Lao
 
Language functions
Syeda Baneen
 
Ad

Similar to Scala as a Declarative Language (20)

PDF
Logic Programming and ILP
Pierre de Lacaze
 
PPTX
Prolog 7-Languages
Pierre de Lacaze
 
PPS
Presentation of GetTogether on Functional Programming
Filip De Sutter
 
PDF
Unified Programming Theory
Crazy Mathematician
 
PDF
Introduction à Scala - Michel Schinz - January 2010
JUG Lausanne
 
PDF
Introductiontoprogramminginscala
Amuhinda Hungai
 
PPT
Functional Programming - Past, Present and Future
Pushkar Kulkarni
 
PPT
Functional Programming Past Present Future
IndicThreads
 
PDF
Genetic programming
Yun-Yan Chi
 
PDF
Introduction to Scala for JCConf Taiwan
Jimin Hsieh
 
PDF
Programming in Scala - Lecture Two
Angelo Corsaro
 
KEY
An Introduction to Functional Programming using Haskell
Michel Rijnders
 
ODP
Knolx Session : Built-In Control Structures in Scala
Ayush Mishra
 
PPTX
programming part 1 introduction to python.pptx
hashini42
 
PDF
programacion funcional.pdf
FranciscoJavierAcost31
 
PDF
Data Structures Chapter-2
priyavanimurugarajan
 
PPTX
Scala
Marcelo Cure
 
PPTX
Scala Introduction
Constantine Nosovsky
 
PDF
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...
Codemotion
 
PDF
Introduction to Functional Languages
suthi
 
Logic Programming and ILP
Pierre de Lacaze
 
Prolog 7-Languages
Pierre de Lacaze
 
Presentation of GetTogether on Functional Programming
Filip De Sutter
 
Unified Programming Theory
Crazy Mathematician
 
Introduction à Scala - Michel Schinz - January 2010
JUG Lausanne
 
Introductiontoprogramminginscala
Amuhinda Hungai
 
Functional Programming - Past, Present and Future
Pushkar Kulkarni
 
Functional Programming Past Present Future
IndicThreads
 
Genetic programming
Yun-Yan Chi
 
Introduction to Scala for JCConf Taiwan
Jimin Hsieh
 
Programming in Scala - Lecture Two
Angelo Corsaro
 
An Introduction to Functional Programming using Haskell
Michel Rijnders
 
Knolx Session : Built-In Control Structures in Scala
Ayush Mishra
 
programming part 1 introduction to python.pptx
hashini42
 
programacion funcional.pdf
FranciscoJavierAcost31
 
Data Structures Chapter-2
priyavanimurugarajan
 
Scala Introduction
Constantine Nosovsky
 
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...
Codemotion
 
Introduction to Functional Languages
suthi
 
Ad

Recently uploaded (20)

PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 

Scala as a Declarative Language

  • 1. Introduction Suresh B Velagapudi, Ph.D Chief Technical Officer Mayera Software Solutions, LLC
  • 2. Scalastic Warning “ Prolog Technology for temporal reasoning in relational databases” In spite of Ph.D for the above research work, I love to code in and talk about scala. I warn you up front that Your present coding style is at risk.
  • 3. Scala as a Practical Declarative Language
  • 4. Weltanschauung Based on Peace, Practicality and Productivity Not on Power, Pride, Prejudice or Prosperity etc.
  • 5. In A Nutshell Declarative Programming Style in Scala makes software product development from Proof-of-Concept to Deployment enjoyable.
  • 6. Abbreviations MOD – Martin ODersky DOS – Designer Of Scala SBE – Scala By Example ASS96 – Abelson Sussman Sussman MIL78 – Milner COW – Check Out Wikipedia DOP – A Discipline Of Programming 1976
  • 7. Ramanujan scala> for {hardyTaxi <- List.range(1000,2000) j <- List.range(1,20) k <- List.range(1,20) l <- List.range(1,20) m <- List.range(1,20) if((j*j*j)+(k*k*k) == hardyTaxi && (l*l*l)+(m*m*m) == hardyTaxi) && j!= l && k!= m && j!= m} yield (i,j,k,l,m) res2: List[(Int, Int, Int, Int, Int)] = List((1729,1,12,9,10) The smallest number expressible as the sum of two cubes in two different ways.
  • 8. Dijkstra on non-imperative in 1985 The simplest way to characterize the difference between imperative programming languages and non-imperative ones is that in the reasoning about imperative programming you have to be aware of the 'state' of the machine as is recorded in its memory.
  • 9. An expression is non-imperative scala> if(12*12*12 + 1*1*1 == 10*10*10 + 9*9*9) 1729 else false res5: AnyVal = 1729 scala> if(12*12*12 + 1*1*1 == 10*10*10 + 9*9*9) 1729 else 0 res6: Int = 1729
  • 10. Declarative Programs are Executable Specifications //from SBE page 72 def isPrime(n: Int) = List.range(2, n) forall (x => n % x != 0) //from SBE page 80 for { i <- List.range(1,10) j <- List.range(1, i) if isPrime(i+j) } yield (i, j)
  • 11. Pythagorean tuple that sums to 1000 for {i <- List.range(1,1000) j <- List.range(1,1000) k <- List.range(1,1000) if (i+j+k==1000 && i*i + j*j == k*k) } yield (i, j, k) res6: List[(Int, Int, Int)] = List((200,375,425), (375,200,425))
  • 12. Declarative Reading is Math Definition The definition of isPrime n , an integer , is, given a range of integers 2 thru n for all X, n modulo x is not zero def fact(n: Int): Int = n*fact(n-1) def isPrime(n: Int) = List.range(2, n) forall (x => n % x != 0) The definition of factorial n , an integer , is, n times factorial n -1
  • 13. Separation of Concerns – Dijkstra We should not head for a mathematically correct program that is so badly engineered that is beyond salvation. --Dijkstra (1976) A Discipline of Programming
  • 14. Recursion vs iteration //recursive procedure (described in ALGOL 60 ): procedure whiledo (condition, statement); begin if condition then begin statement; whiledo (condition, statement); end end Although correct, it hurts me. DOP Preface
  • 15. A Generation Later // SBE page 6 def While (p: => Boolean) (s: => Unit) { if (p) { s ; While(p)(s) } } Later generations will pronounce as their judgment that in the last fifteen years, recursive solutions have been placed upon too high a pedestal. DOP 178
  • 16. Thank You Samar Singh My math comp mentor of late seventies and early eighties.
  • 17. Tail Recursive Functions //SBE page 18 def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b,a % b) /Answer to Exercise 4.6.1 of SBE page 19 def mf (x: Int): Int = myf (x, 1); def myf (x:Int, Acc: Int): Int = if(x==1) Acc else myf(x-1, Acc * x)
  • 18. Horner's rule def horner(L:List[Int], X : Int): Int = { def horneri(L:List[Int], X : Int,Acc: Int): Int = { if(L.isEmpty) Acc else horneri(L.tail,X, Acc*X + L.head)} horneri(L,X,0)}
  • 19. Internal Rate of Return internal rate of return for an investment is the discount rate that makes the net present value of the investment's cash flow stream equal to zero.
  • 20. Hilbert's Tenth Problem Determination of the solvability of a Diophantine equation. Given a Diophantine equation with any number of unknown quantities and with rational integral numerical coefficients: To devise a process according to which it can be determined by a finite number of operations whether the equation is solvable in rational integers. A Diophantine equation is a polynomial equation where the variables are integers only.
  • 21. An Oxymoron in 1989? Programming is essentially procedural. Real Engineers program by FORTRAN Arrays, or C pointers. Philosophers and Logicians make Declarations. Ha! Ha!
  • 22. A Syllogism All humans are mortal. Socrates is human. So Socrates is mortal. Ha! Ha!
  • 23. Modus Ponens in PROLOG //All humans are mortal. mortal(X) :- human(X). //Socrates is human. human( socrates ). human( suresh). ?- human(X). X = socrates ?- mortal(X). X = socrates ; X = suresh.
  • 24. Second Order Predicate ?- setof(X,mortal(X),List). List = [socrates, suresh]
  • 25. Concatenation of Lists The concatenation of an empty list with a list L is L. The Concatenation of a list having head H and tail T, with a list L, is a list with head H and a tail that is the concatenation of T and L. concatenation([], L, L). concatenation([H|T], L, [H|CTL]) :- concatenation(T,L, CTL). ?- concatenation([socrates,suresh],[addanki],L). L = [socrates,suresh,addanki] CTL H T L
  • 26. Concatenation in Scala def concatenation[G](xs: List[G], ys: List[G]): List[G] = xs match { case List() => ys case H :: T => H :: concatenation(T,L) } CTL H T L
  • 27. Predicate Logic as a Programming Language – Kowalski (1974) Program is a set of axioms. Computation is a constructive proof of a goal statement from the program
  • 28. Thanks to Trevor Legall First theory book in 1984 Foundations of Logic Programming By J.W.Lloyd
  • 29. Floating Point Number Crunching is not the only game in computingville. Combining qualitative reasoning and quantitative Techniques to improve mechanical and electrical Product design.
  • 30. Newton's method def sqrt(x: Double) = { def sqrtIter(guess: Double, x: Double): Double = if (isGoodEnough(guess, x)) guess else sqrtIter(improve(guess, x), x) def improve(guess: Double, x: Double) = (guess + x / guess) / 2 def isGoodEnough(guess: Double, x: Double) = abs(square(guess) - x) < 0.001 sqrtIter(1.0, x) }
  • 31. Algorithms + Data Structures = Programs That was my fault. I included it because I liked it, and that for two reasons: 1. (z /: xs) (op) looks like an abbreviation of a left leaning tree with a `z' on the lower left end (at least to me). I.e. something like op / \ op x1 / \ z x0 That's the tree I always draw when I explain fold left. 2. (z /: xs) has the operands in the ``right'' order.
  • 32. Algorithm = Logic + Control The logic component determines the meaning of the algorithm. The control component only affects its efficiency.
  • 33. Algorithm Logic component Abstract Procedure Definitions Definitions of data structures represented by terms Direction e.g. (top-down or bottom-up) Strategy for execution of procedure calls (e.g. sequential or parallel Strategy for investigating alternative procedures Control component Scheme for storing data represented relationally
  • 34. Which Factorial Program? def fact(n: Int) = 1 to n reduceLeft (_*_) def fact(n: Int):Int = If (n == 0) 1 else n * fact(n-1) def mf(x: Int): Int = myf(x, 1); def myf(x:Int, Acc: Int): Int = if(x==1) Acc Else myf(x-1, Acc * x)
  • 35. Which Reverse? //SBE page 68 def reverse[A](xs: List[A]): List[A] = xs match case Nil => Nil case x :: xs => reverse(xs) ::: List(x)} //SBE page 75 def reverse: List[A] = ((Nil: List[A]) /: this) {(xs, x) => x :: xs} //Is Tail Recursive Reverse Possible?
  • 36. Tail Recursive Reverse def reverse[T](l: List[T]): List[T] = { def reverseR(result: List[T], curList: List[T]): List[T] = curList match { case Nil => result case h :: tail => reverseR(h :: result, tail) } reverseR(Nil, l) }
  • 37. Sample Conversation with ELIZA I am unhappy. >> How long have you been unhappy? Six months. Can you help me. >> What makes you think I help you? You remind me of my father and brother >>Please tell me more about father. I like teasing father. >>Does anyone else in your family like teasing father? No, only me. >> Please go on
  • 38. ELIZA in Scala def response(stimulus : List[String]) : Unit = stimulus match { case List(&quot;i&quot;,&quot;am&quot;, x) => println(&quot;How long have you been&quot; + x+ &quot;?&quot;) case List(x, &quot;you&quot;, y, &quot;me&quot;) => println(&quot;What makes you think I &quot; +y+&quot; you?&quot;) case List(&quot;i&quot;,&quot;feel&quot;, x) => println(&quot;Do you often feel that way?&quot;) case List(&quot;i&quot;, &quot;like&quot;, x) => println(&quot;Does any one else in your family like &quot; + x +&quot; ?&quot;) case _ => println(&quot;Please Go On&quot;) }
  • 39. Machine Learning Suppose ELIZA wants to improve. Weka switched to java from prolog. SWeka will be in Scala.
  • 40. Future of Scala Pessimistic Scenario: Functional freaks and java addicts fight to finish to scare away all scala enthusiasts. Optimistic Scenario: Complete Domination of the entire computing scene Most likely scenario: Solid apps come up. Steady impressive growth for next decade.
  • 41. Pollak's cpp Principle Each morning that I sit down at the keyboard and start coding Scala, I get a feeling of calm, peace, and power. I know that I’m going to have another day of taking the ideas in my head and reducing them to a running computer program that will be fast and low in defects.
  • 42. Pollak But most importantly, Scala taught me to program and reason about programming differently. I stopped thinking in terms of allocating buffers, structs, and objects, and of changing those pieces of memory. Instead, I learned to think about most of my programs as transforming input to output. This change in thinking has lead ( sic ) to lower defect rates, more modular code, and more testable code.
  • 43. Tony Hoare in QCON 2009 One 
day
... • Software 
will 
be 
the 
most
 reliable
 component Of 
every 
product
 which
 contains 
it. • Software 
engineering
 will
 be
 the 
most Dependable 
of
 all 
engineering 
professions. • Because 
of 
the
 successful 
interplay
 of research – 
into
 the
 science 
of
 programming – and
 the
 engineering
 of
 software
  • 44. I have a dream One day..... My fellow scalastics' programs will be judged not by the colorful confusion of syntax but by the content of the character sequences with declarative semantics.
  • 45. Remember SURESH S emantics independent of execution is the aim. U niversal quantification is for stating facts and rules. R ecursion is natural and efficient with TRO Call. E xtensive use of pattern matching is desirable. S tatic typing of generics avoids awful defects. H igher order functions help declarative programming.

Editor's Notes

  • #2: FORTRAN is the first language. 1969 Btech IITM Did Eco and finance too. Ms and Ph.D in computer science. Intend going from 50% to 100%
  • #3: That is my thesis title.
  • #6: Enjoy
  • #28: Read it after 15 years. In stone age of computing, from one stone inscription to the other takes a long time. I do not blame myself. Dijkstra is ignorant of it too,