lambdaway
::
whynot
7
|
list
|
login
|
load
|
|
{uncover data/amelie_poulain.jpg 100 500 Amélie Poulain is watching you} _h1 the '{lambda way} project {center See the extended [[french|?view=whynot_fr]] version improved in many ways.} _p The '{lambda way} project is a text editor, '{lambda tank}, a wiki operating as a thin overlay on any web browser, equipped with a programming language, '{lambda talk}, for writing, styling and coding on the web. {{title} _h2 What the hell is that? ... } {{content} _p « {i Oh please nooooo! There are hundred of wiki engines and hundred of languages! Why yet another wiki and another language nobody will ever want to use?} » _p Please, let's talk about that! } {{title} _h2 1) just a notepad } {{content} _p '{lambda tank} is a notepad where pages can be added on demand. You write in a page through an editor frame. If you write {pre Hello world } _p the page displays {div Hello world } _p {i Why make it simple when you can make it complicated, right?} I agree, but when you write {pre '{b Hello world} } _p you get {div {b Hello world}} _p {i Hey man, with my old MSWord things are easier, I select the text and click [B], why do you want coming back to the Middle Age?} _p Please wait. If you write {pre '{b 1 2 3 4 5 6} } _p you say "Please boldify the sequence of numbers 1 2 3 4 5 6" and get {div {b 1 2 3 4 5 6} } _p Now if you write {pre '{* 1 2 3 4 5 6} } _p you say "Please multiply the sequence of numbers 1 2 3 4 5 6" and get {div {* 1 2 3 4 5 6} } _p It's a command that MSWord can't understand! _p '{lambda tank} understands this command written in the '{lambda talk}'s syntax. And this syntax is a {b true programming language}. _p Let's explore some of its functionalities. } {{title} _h2 2) Let's write our first functions ... } {{content} {prewrap '{def smart_swap // define smart_swap as the name of {lambda {:x :y} // the function of :x and :y Swapping :x and :y displays :y :x // the body } // end of lambda } // end of def -> {def smart_swap {lambda {:x :y} Swapping :x and :y displays :y :x}} '{smart_swap hello world} // apply smart_app to 2 words -> {smart_swap hello world} '{def smart_add {lambda {:x :y} adding :x and :y displays {+ :x :y}}} -> {def smart_add {lambda {:x :y} adding :x and :y displays {+ :x :y}}} '{smart_add 3 4} -> {smart_add 3 4} } _p Functions are nothing but text replacement processes. } {{title} _h2 3) Let's write some HTML/CSS ... } {{content} {prewrap '{def color {lambda {:col :text} {span {@ style="color::col"}:text}}} -> {def color {lambda {:col :text} {span {@ style="color::col"}:text}}} '{color #f00 hello world} -> {color #f00 hello world} '{color #0ff hello brave new world} -> {color #0ff hello brave new world} '{def randcol {lambda {:w} {span {@ style="color:rgb({round {* {random} 255}}, {round {* {random} 255}}, {round {* {random} 255}})"}:w}}} -> {def randcol {lambda {:w} {span {@ style="color:rgb({round {* {random} 255}}, {round {* {random} 255}}, {round {* {random} 255}})"}:w}}} '{S.map randcol {S.serie 1 100}} -> {S.map randcol {S.serie 1 100}} } _p This is how is coded the progressive display effect used in this page: {pre '{{title} ... the title ... } '{{content} ... the content ... } } _p As simple as that. } {{title} _h2 4) Let's compute ... } {{content} _p Let's compute the sum and the product of the first hundred natural numbers {pre '{+ {S.serie 1 100}} -> {+ {S.serie 1 100}} '{* {S.serie 1 100}} -> {* {S.serie 1 100}} } _p Now using a recursive function using different operators, for instance {code [+,*,long_mult,...]}: {prewrap '{def rec // call rec {lambda {:op :n} // the function of op & n {if {= :n 1} // returning if n = 1 then 1 // then 1 else {:op // else op applied to :n // n {rec // and rec applied to :op // op {- :n 1} // and n-1 } // close rec } // close op } // close if } // close lambda } // close def -> {def rec {lambda {:op :n} {if {= :n 1} then 1 else {:op :n {rec :op {- :n 1}}}}}} '{rec * 100} // calling rec on 100 with * -> {rec * 100} '{rec long_mult 100} // calling rec on 100 with long_mult -> {rec long_mult 100} } } {{title} _h2 And so what? ... } {{content} _p If you're curious you'll find out more [[here|?view=start]]. _p {i Alain Marty (2019/12/25)} } {center See also [[studio.liber|https://www.studio.liber3.net/]], inspired by this page.} ;; coder's corner {style div { border:0px solid #888; padding:0px; } pre { background:#eee; margin: 5px; padding:5px; } } {{hide} {def title div {@ onclick="this.nextSibling.nextSibling.style.transform= (this.nextSibling.nextSibling.style.transform==='scale(0)')? 'scale(1)' : 'scale(0)'; this.nextSibling.nextSibling.style.height= (this.nextSibling.nextSibling.style.height==='0px')? 'auto' : '0px';"}} {def content div {@ style="transform:scale(0); height:0px; transition:all 1s;"}} }
lambdaway v.20211111