80 likes | 104 Views
Explore Unlambda, a powerful functional programming language designed for abstraction-elimination. Learn about its syntax, functions, numbers like Church integers, and see an example of computing Fibonacci numbers. Dive into the unconventional world of Unlambda and its quirky reputation. Discover more about this fascinating language and its peculiarities.
E N D
The University of North Carolina at Chapel Hill Lecture 28: More on Functional Programming COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos April 1 COMP 144 Programming Language Concepts Felix Hernandez-Campos
Advanced Functional Programming • Functional programming languages can increase readability • But they can also help developing obfuscated code • Unlambda is a functional programming language specifically designed for this task • It is powerful (Turing-complete) • It is the ideal language for abstraction-elimination COMP 144 Programming Language Concepts Felix Hernandez-Campos
Programming Principles • Seven primitive functions : • k, • s, • i, • v, • d, • C, and • .x COMP 144 Programming Language Concepts Felix Hernandez-Campos
Numbers • Church integers: • <0> is ^f^x$x (i.e. `ki). • <1> is ^f^x`$f$x (i.e. i). • <2> is ^f^x`$f`$f$x (i.e. ``s``s`kski). • <3> is ^f^x`$f`$f`$f$x (i.e. ``s``s`ksk``s``s`kski). • and so on… COMP 144 Programming Language Concepts Felix Hernandez-Campos
Example: Fibonacci • 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`k s``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`k s``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 COMP 144 Programming Language Concepts Felix Hernandez-Campos
Unlambda in Unlambda • http://www.ofb.net/~jlm/unlambda/unlambda.unl.gz COMP 144 Programming Language Concepts Felix Hernandez-Campos
The Shocking Truth • “It's disgusting — it's revolting — we love it.” CyberTabloid • “Unlambda, the language in which every program is an IOUCC.” Encyclopædia Internetica • “The 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 Programming COMP 144 Programming Language Concepts Felix Hernandez-Campos
Source of this evil • Reference • http://www.eleves.ens.fr:8080/home/madore/programs/unlambda/ • Extra credit • A+ guaranteed to the first one that develops a Turtle interpreter in Unlambda COMP 144 Programming Language Concepts Felix Hernandez-Campos