lambdaway
::
sandbox
2
|
list
|
login
|
load
|
|
{uncover ../lambdaspeech/data/ali.jpg 100 600 Alain is watching you} ;; {iframe {@ width="580" height="315" src="https://www.youtube.com/embed/1IFVPrJ13Sg?si=Isvk42y5d5jjqbk0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen}}
_img data/IMG_20231220_215511.jpg https://youtu.be/yhd9SrKaIg4?feature=shared ;;
_h1 sandbox | [[agora]] aDpuk 2MseL32 pkEycW data/IMG_20231206_104521.jpg _img data/patrick_rumi.jpg _p Comment présenter un code : {pre '{+ 1 2} ;; an s-expression protected from evaluation -> {+ 1 2} ;; here evaluated } _p Comment copier-coller un simple texte : {prewrap Une même terre gavée de sang depuis que Dieu est Dieu et que le monde est monde, sur laquelle vivent (et s’opposent souvent) deux peuples différents culturellement, économiquement, religieusement, et qui plus est s’en sont remis, volontairement ou pas, aux plus extrêmes d’entre-eux pour les représenter et les défendre. Le Hamas, d’un côté, pour les palestiniens, manipulé par l’Iran, qui revendique clairement la mort d’Israël et de l’autre, Netanyahou et ses ultra orthodoxes, revendiquant par la colonisation l’annexion de la Cisjordanie et, désormais par les bombes, celle de la bande de Gaza... La solution ? Bien malin qui pourra la proposer tant que les deux peuples, premières et seules victimes de cette guerre atroce, ne prendront enfin profondément conscience qui sont ces tristes sires qui les ont amenés à baigner ensemble dans un même sang. } _h2 introduction _p A lambdatalk code is made of {b words} and {b expressions}, where {pre - a {b word} is any group of {b characters} except spaces and curly braces, '{} - an {b expression} is made of {b abstractions}, {b definitions} and {b applications}, - an {b abstraction} is defined as '{lambda {words} expression} - a {b definition} is defined as '{def word expression} - an {b application} is defined as '{abstraction expression} } _p and evaluated according to these rules {pre - a word is not evaluated, - an abstraction is evaluated to a word, bound to a JS anonymous function, - an application is evaluated to words, from inside out, - a definition is evaluated to a word, from inside out, - abstractions and definitions are evaluated before applications. } _h2 first steps {pre - words : james, bond, 123, #f00, :a, :b, ... - abstraction : '{lambda {:a :b} :b :a} -> {lambda {:a :b} :b :a} - definition : '{def SWAP {lambda {:a :b} :b :a}} -> {def SWAP {lambda {:a :b} :b :a}} - application : '{SWAP James Bond} -> {SWAP James Bond} } _p This is a more complex expression {pre '{{lambda {:a :b} My name is :b, :a :b.} James Bond} -> {{lambda {:a :b} My name is :b, :a :b.} James Bond} } _p This exprepssion, so called an {b IIFE}, is preferabily splitted into two parts {pre 1: '{def HI {lambda {:a :b} My name is :b, :a :b.}} -> {def HI {lambda {:a :b} My name is :b, :a :b.}} 2: '{HI James Bond} -> {HI James Bond} } _p {b HI} is a function waiting for two values, let's analyze its behaviour with different numbers of values {pre '{HI} // no values -> {HI} // it's the reference of the functionn '{lambda {:a :b} My name is :b, :a :b.} '{HI James} // only one values -> {HI James} // it's the reference of the function '{lambda {:b} My name is :b, James :b.} '{HI James Bond} // two values -> {HI James Bond} // it's the awaited behaviour '{HI Ludwig Mies van der Rohe} // more than two values -> {HI Ludwig Mies van der Rohe} // note that :a got "Ludwig" and :b got the last words, "Mies van der Rohe" } _p Thus lambdas accept any numbers of values. As a useful application let's introduce {b PAIRS} aggregating two words with {b LEFT} and {b RIGHT} accessing each of them. {prewrap '{def PAIR {lambda {:a :b :c} {:c :a :b}}} -> {def PAIR {lambda {:a :b :c} {:c :a :b}}} '{def LEFT {lambda {:c} {:c {lambda {:a :b} :a}}}} -> {def LEFT {lambda {:c} {:c {lambda {:a :b} :a}}}} '{def RIGHT {lambda {:c} {:c {lambda {:a :b} :b}}}} -> {def RIGHT {lambda {:c} {:c {lambda {:a :b} :b}}}} '{def JB {PAIR James Bond}} -> {def JB {PAIR James Bond}} '{LEFT {JB}} -> {LEFT {JB}} '{RIGHT {JB}} -> {RIGHT {JB}} } _p Note that {b '{PAIR James Bond}} is an example of partial application, {b PAIR} is waiting for 3 words and is given 2 only. The result is a function which will be given to {b LEFT} or {b RIGHT} to return {b James} or {b Bond}. _p Let's trace the evaluation of {b '{LEFT {JB}}} replacing names by their lambda expressions: {pre 0: '{{lambda {z} {z {lambda {x y} x}}} {{lambda {x y z} {z x y}} James Bond}} '{{lambda {x y z} {z x y}} Hello World} is a partial application evaluated to '{lambda {z} {z James Bond}} 1: '{{lambda {z} {z {lambda {x y} x}}} {lambda {z} {z James Bond}}} '{lambda {z} {z James Bond}} replaces z in '{z {lambda {x y}}} 2: '{{lambda {z} {z James Bond}} {lambda {x y} x}} '{lambda {x y} x} replaces z in '{z James Bond} 3: '{{lambda {x y} x} James Bond} James replaces x in the body of '{lambda {x y} x} 4: Bond } _p Et voilà ! _h2 a few steps in arithmetic _p The set of natural numbers is made of {b ZERO} and all its {b SUCC}essors. {pre '{def ZERO {lambda {:f :x} :x}} -> {def ZERO {lambda {:f :x} :x}} '{def SUCC {lambda {:n :f :x} {:f {:n :f :x}}}} -> {def SUCC {lambda {:n :f :x} {:f {:n :f :x}}}} '{def ONE {SUCC ZERO}} -> {def ONE {SUCC ZERO}} '{def TWO {SUCC {ONE}}} -> {def TWO {SUCC {ONE}}} '{def THREE {SUCC {TWO}}} -> {def THREE {SUCC {TWO}}} } _p Because numbers are defined as functions, we need a function to display them, say as groups of dots {b •} {pre '{def CHURCH {lambda {:n} {:n {lambda {:x} :x•} C}}} -> {def CHURCH {lambda {:n} {:n {lambda {:x} :x•} C}}} '{CHURCH {ZERO}} -> {CHURCH {ZERO}} '{CHURCH {ONE}} -> {CHURCH {ONE}} '{CHURCH {TWO}} -> {CHURCH {TWO}} '{CHURCH {THREE}} -> {CHURCH {THREE}} } _p Let's define the addition and the multiplication as compositions of {b SUCC}s {pre '{def ADD {lambda {:n :m :f :x} {{:n :f} {:m :f :x}}}} -> {def ADD {lambda {:n :m :f :x} {{:n :f} {:m :f :x}}}} '{def MUL {lambda {:n :m :f :x} {:n {:m :f} :x}}} -> {def MUL {lambda {:n :m :f :x} {:n {:m :f} :x}}} '{def FIVE {ADD {TWO} {THREE}}} -> {def FIVE {ADD {TWO} {THREE}}} '{def SIX {MUL {TWO} {THREE}}} -> {def SIX {MUL {TWO} {THREE}}} '{CHURCH {FIVE}} -> {CHURCH {FIVE}} '{CHURCH {SIX}} -> {CHURCH {SIX}} } _p We can go further and translate a process leading to a factorial, say {b 6!} {pre [1 , 1] = [1,1] [2 , 1*2] = [1,2] [3 , 1*2*3] = [1,6] [4 , 1*2*3*4] = [1,24] [5 , 1*2*3*4*5] = [1,120] [6 , 1*2*3*4*5*6] = [1,720] -> 6! = 720 } _p into this code {pre '{def FAC {lambda {:n} {RIGHT {{:n {lambda {:p} {PAIR {SUCC {LEFT :p}} {MUL {LEFT :p} {RIGHT :p}}}}} {PAIR {ONE} {ONE}}}}}} -> {def FAC {lambda {:n} {RIGHT {{:n {lambda {:p} {PAIR {SUCC {LEFT :p}} {MUL {LEFT :p} {RIGHT :p}}}}} {PAIR {ONE} {ONE}}}}}} } _p and compute the factorial of 6 {prewrap '{CHURCH {FAC {SIX}}} -> {CHURCH {FAC {SIX}}} // 720 dots } _p Finally, replacing names by their lambda expressions we come back to a pure lambda expression {pre '{{lambda {:n} {:n {lambda {:x} :x•} C}} {{lambda {:n} {{lambda {:c} {:c {lambda {:a :b} :b}}} {{:n {lambda {:p} {{lambda {:a :b :c} {:c :a :b}} {{lambda {:n :f :x} {:f {:n :f :x}}} {{lambda {:c} {:c {lambda {:a :b} :a}}} :p}} {{lambda {:n :m :f :x} {:n {:m :f} :x}} {{lambda {:c} {:c {lambda {:a :b} :a}}} :p} {{lambda {:c} {:c {lambda {:a :b} :b}}} :p}}}}} {{lambda {:a :b :c} {:c :a :b}} {lambda {:f :x} {:f :x}} {lambda {:f :x} {:f :x}}}}}} {lambda {:f :x} {:f {:f {:f {:f {:f {:f :x}}}}}}}}} } _h2 conclusion _p Nothing but words, abstractions, applications and an empty dictionary. And {i a minima:} we could build this set of functions : {pre {def I {lambda {:a :b} :a}} {def O {lambda {:a :b} :b}} {def ? {lambda {:a :b :c} {:a :b :c}}} {def () {lambda {:a :b :c} {:c :a :b}}} {def ( {lambda {:c} {:c I}}} {def ) {lambda {:c} {:c O}}} {def ø {lambda {} I}} {def ø? {lambda {:c} {:c {lambda {} O}}}} } _p and for instance play with the Towers of Hanoï : {pre '{def HANOI {lambda {:n :a :b :c} {{? {ø? :n} {lambda {:n :a :b :c} } {lambda {:n :a :b :c} {HANOI {) :n} :a :c :b} {div} move {( :n} from tower :a to tower :b {HANOI {) :n} :c :b :a} }} :n :a :b :c}}} -> {def HANOI {lambda {:n :a :b :c} {{? {ø? :n} {lambda {:n :a :b :c} } {lambda {:n :a :b :c} {HANOI {) :n} :a :c :b} {div} move {( :n} from tower :a to tower :b {HANOI {) :n} :c :b :a} }} :n :a :b :c}}} '{HANOI {() a {() b {() c {() d ø}}}} A B C} -> {HANOI {() a {() b {() c {() d ø}}}} A B C} } _img https://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/AnimeHanoiNB.gif/440px-AnimeHanoiNB.gif ;; _img data/jeune_fille_lune.jpg ;; _img data/IMG_20230813_084119.jpg ;; _img data/IMG_20230813_084619.jpg ;; _img data/1690900452553.jpg ;; _img data/IMG_20230801_184022.jpg _ul [[https://apprendre-le-deep-learning.com/coder-reseau-de-neurones-from-scratch/| https://apprendre-le-deep-learning.com/coder-reseau-de-neurones-from-scratch/]] _ul [[Africa|https://m.facebook.com/story.php?story_fbid=pfbid02FN9U73FwjGKUpM3t8LspqDFSwwwHC1robP4BwAV1TCsnRyW5pja8WpEkwuhLZpQcl&id=766184657]] ;; {uncover https://i.pinimg.com/originals/7e/6b/04/7e6b044ba007dafdc157180d79731510.jpg 100 550 Profil grec} ;; {uncover https://i.pinimg.com/originals/24/3c/f4/243cf48f5664743d179c67418d1ba389.jpg 100 900 profil grec} ;; _img data/IMG_0077.png
lambdaway v.20211111