prime pattern 1 | prime pattern 2 | prime pattern 3 | prime pattern 4 | prime pattern 5
http://code.fed.wiki/assets/pages/lambda-talk-in-a-frame/repl.html HEIGHT 3600
{center Copied from prime_pattern2|http://lambdaway.free.fr/lambdawalks/?view=prime_pattern2} {uncover http://lambdaway.free.fr/lambdawalks/data/gandhi_adami.jpg 100 500 Gandhi is fan of lambdatalk!} _h1 prime pattern {sup 2} -> Yin & Yang _p You are supposed to have read the previous page, prime_pattern|http://lambdaway.free.fr/lambdawalks/?view=prime_pattern, and understood how a handful of markup commands can be applied to raw text to create titles, paragraphs, links and to insert pictures. Maybe have you soon replaced {pre _{span}h1 TITLE} _p by {pre '{h1 TITLE}} _p to be convinced that the first expression is an alternate form of the second one, easier to write and read. I hope that the general form for a '{lambda talk} expression {pre '{first rest}} _p begins to be familiar to you. That you understand that {b first} is a command and {b rest} is any expression on which the command will be applied. Writing {code '{b hello world}} to boldify some inline part in a sentence should be now evident. There is nothing amazing here, '{lambda talk} is nothing but a light overlay on the standard HTML/CSS syntaxes brought for free by the web browsers ... which do the main work, evaluate HTML/CSS code and display the result. _p '{lambda talk} is just {i a dwarf on the shoulders of giants}. In fact, you don't need '{lambda talk}, you might as well use plain HTML/CSS. You could write {pre <{span}b>hello world<{span}/b>} _p instead of {pre '{b hello world}} _p to display {b hello world}. You could write (in the right order) {pre <{span}b><{span}i><{span}u>hello world<{span}u><{span}i><{span}b>} _p instead of {pre '{b {i {u hello world}}}} _p to display {b {i {u hello world}}}. It's a matter of choice. In any case learning '{lambda talk} is learning HTML/CSS, it's not a waste of time, maybe it's even a good place to learn HTML/CSS and the web gives us all we need about HTML/CSS. You don't remind how to {del delete} some word? Just Google "{i HTML delete a word}" and you have the answer. _p And so what? What might encourage you to use '{lambda talk} is the fact '{lambda talk} is more than a light overlay on HTML/CSS. For instance with '{lambda talk} you can write {pre '{+ 1 2 3 4 5 6 7 8 9 10} -> 55 } _p and get the sum of {b 1 2 3 4 5 6 7 8 9 10}. You can't do that with HTML/CSS. _p Yes, '{lambda talk} knows a few things in mathematics. The following expression computes the hypothenuse of a right angle triangle with sides 3 and 4 {pre '{sqrt {+ {* 3 3} {* 4 4}}} -> 5 } _p This {i nested} expression is evaluated by the successive application of three operators, [{code sqrt, +, *}] to two numbers [{code 3,4}]. First the two inner expressions {code '{* 3 3} & '{* 4 4}} are replaced by {b 9 & 16}, leading to {code '{sqrt {+ 9 16}}}, then to {code '{sqrt 25}} and finally to {b 5}. In this process the key word is {b application}. _p We are going to discover another keyword, {b abstraction}, rising '{lambda talk} from the simple {i pocket calculator} to a true programming language. _p Let's begin with a {i bad} idea. If you write {pre '{sqrt {+ {* x x} {* y y}}} -> {sqrt {+ {* x x} {* y y}}} } _p you get an error, the result is {b NaN}, which means {i Not a Number}. That's understandable, the three numerical operators [{code sqrt, +, *}] are waiting for numbers and [{code x,y}] are not numerical values. As it is, this expression is unevaluable, it's a {i bad} idea. _p Now the good {i idea}: we are going to prevent this expression from an immediate evaluation and we will call it later when it will be possible to replace x and y by numerical values, say 3 and 4, making it evaluable. _p A way to do that would be to write something like this {pre {i replace:} x & y {i in:} '{sqrt {+ {* x x} {* y y}}} {i by:} 3 & 4 } _p For several reasons explained later the syntax chosen is slightly different {pre '{{lambda {x y} {sqrt {+ {* x x} {* y y}}} } 3 4} -> 5 } _p It's a kind of {i shorthand} notation using the curly braces you are soon familiar with (isnt'it?) and the word {b replace} replaced by the funny greek symbol {b lambda} loved by mathematicians and preventing average people to understand what is going on, just replacing a word by another one. _p You are welcome in the wonderful world of {b λ calculus} created 10 years before the era of computers by Alonzo Church, a mathematician working in Princeton, close to Albert Einstein, Kurt Gödel, and Alan Turing (one of Church's students). _p Everything else is {i syntactic sugar}. Lisp, Java, Python and others are (powerful) dialects of this seminal work. _p Let's discover a first syntactic sugar, {b '{def name expression}}, a special form used to replace an unreadable expression by a short name. It's nothing but aliasing but it's very useful. For instance let's call {b hypo} the inner expression {pre '{def hypo {lambda {x y} {sqrt {+ {* x x} {* y y}}}}} -> {def hypo {lambda {x y} {sqrt {+ {* x x} {* y y}}}}} } _p Thanks to this name we can replace the whole unreadable substitution process by the following {pre '{hypo 3 4} -> {hypo 3 4} } _p As simple as that! _p And we understand now that a new operator, {b hypo}, has been added to some dictionary, after [sqrt, +, *] and several others we have used in this page [h1, h2, ... b, i, u, ...]. We understand that operators - called more generally {b functions} - are postponed expressions, {b abstractions}, waiting for {b applications}, waiting to be applied on given values to return other ones. And every expressions we will write will be smart composition of these twinned operators, {b abstraction & application}, applied on words. The {b TAO} of programming languages, Yin & Yang in a universe of words! Probably the brain's primary language. No, I'm kidding, don't mind.... _p More seriously we discover a sequential/recursive process where long and complex expressions can be progressively replaced by simpler ones. This can be very powerful. For instance an unordered collection of words can be ordered, bringing out {b information}. Finding a word in a mess of 4 billion words is a long trip, we have to test an average of two billion words. If words are ordered the number of tests is drastically reduced to ... {b 32}. _p Information brings power! Programming languages bring out information, create negentropy. Replacing {b '{{lambda {x y} {sqrt {+ {* x x} {* y y}}}} 3 4}} by {b 5} is replacing code by data and creating negentropy. _p [...] _p As an exercice, you should write a function {b swap} interchanging {b hello} and {b world} in such a sentence {b "I just say hello world!"}. The answer is in prime_pattern3... _p {i Alain Marty 2019/11/11 update 2021/11/26} {style ;; pre { box-shadow:0 0 8px #000; padding:5px; } }
xxx