1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 28: More on Functional Programming COMP 144 Programming Language Concepts Spring

Download 1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 28: More on Functional Programming COMP 144 Programming Language Concepts Spring

Post on 17-Dec-2015

212 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

<ul><li> Slide 1 </li> <li> 1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 28: More on Functional Programming COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos April 1 The University of North Carolina at Chapel Hill </li> <li> Slide 2 </li> <li> 2 COMP 144 Programming Language Concepts Felix Hernandez-Campos Advanced Functional Programming Functional programming languages can increase readabilityFunctional programming languages can increase readability But they can also help developing obfuscated code Unlambda is a functional programming language specifically designed for this taskUnlambda is a functional programming language specifically designed for this task It is powerful (Turing-complete) It is the ideal language for abstraction-elimination </li> <li> Slide 3 </li> <li> 3 COMP 144 Programming Language Concepts Felix Hernandez-Campos Programming Principles Seven primitive functions :Seven primitive functions : k,k,k,k, s,s,s,s, i,i,i,i, v,v,v,v, d,d,d,d, C, and .x.x.x.x </li> <li> Slide 4 </li> <li> 4 COMP 144 Programming Language Concepts Felix Hernandez-Campos Numbers Church integers:Church integers: is ^f^x$x (i.e. `ki ). is ^f^x$x (i.e. `ki ). is ^f^x`$f$x (i.e. i ). is ^f^x`$f$x (i.e. i ). is ^f^x`$f`$f$x (i.e. ``s``s`kski ). is ^f^x`$f`$f$x (i.e. ``s``s`kski ). is ^f^x`$f`$f`$f$x (i.e. ``s``s`ksk``s``s`kski ). is ^f^x`$f`$f`$f$x (i.e. ``s``s`ksk``s``s`kski ). and so onand so on </li> <li> Slide 5 </li> <li> 5 COMP 144 Programming Language Concepts Felix Hernandez-Campos Example: Fibonacci The following Unlambda program calculates and prints the Fibonacci numbers (as lines of asterisks)The following Unlambda program calculates and prints the Fibonacci numbers (as lines of asterisks)```s``s``sii``s`kk`ki`ki``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s`kk`kk``s`kk`kr``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s`kk`kk`ki``s``s`ks``s`kk`kk``s`kk`k.*``s``s`ks``s`kk`kk``s`kki``s``s`ks``s`kk`kk``s`kki``s`kk`ki``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s`kk`kk``s`kk`k``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s`kk`kk``s`kk`ks``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s`kk`kk``s`kk`ks``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s`kk`kk``s`kk`kk``s``s`ks``s`kk`kk``s`kki``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s`kk`kk``s`kk`kk``s`kk`ki``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s`kk`kk``s`kk`ks``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s`kk`kk``s`kk`ks``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s`kk`kk``s`kk`kk``s``s`ks``s`kk`kk`ki``s``s`ks``s``s`ks``s`kk`ks``s``s`ks``s`kk`kk``s`kk`kk``s`kk`ki``s``s`ks``s`kk`kk``s`kk`ki``s``s`ks``s`kk`kk`ki``s`kk`ki </li> <li> Slide 6 </li> <li> 6 COMP 144 Programming Language Concepts Felix Hernandez-Campos Unlambda in Unlambda http://www.ofb.net/~jlm/unlambda/unlambda.unl.gzhttp://www.ofb.net/~jlm/unlambda/unlambda.unl.gzhttp://www.ofb.net/~jlm/unlambda/unlambda.unl.gz </li> <li> Slide 7 </li> <li> 7 COMP 144 Programming Language Concepts Felix Hernandez-Campos The Shocking Truth It's disgusting it's revolting we love it. CyberTabloidIt's disgusting it's revolting we love it. CyberTabloid Unlambda, the language in which every program is an IOUCC. Encyclopdia InterneticaUnlambda, the language in which every program is an IOUCC. Encyclopdia Internetica The worst thing to befall us since Intercal. Computer Languages TodayThe worst thing to befall us since Intercal. Computer Languages Today The effect of reading an Unlambda program is like habing your brains smashed out by a Lisp sexp wrapped around an ENIAC. You won't find anything like it west of Alpha Centauri. The Hitch-Hacker's Guide to ProgrammingThe effect of reading an Unlambda program is like habing your brains smashed out by a Lisp sexp wrapped around an ENIAC. You won't find anything like it west of Alpha Centauri. The Hitch-Hacker's Guide to Programming </li> <li> Slide 8 </li> <li> 8 COMP 144 Programming Language Concepts Felix Hernandez-Campos Source of this evil ReferenceReference http://www.eleves.ens.fr:8080/home/madore/programs/unl ambda/ http://www.eleves.ens.fr:8080/home/madore/programs/unl ambda/http://www.eleves.ens.fr:8080/home/madore/programs/unl ambda/ Extra creditExtra credit A+ guaranteed to the first one that develops a Turtle interpreter in Unlambda </li> </ul>