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 2600
{center Copied from prime_pattern 3|http://lambdaway.free.fr/lambdawalks/?view=prime_pattern3} {uncover http://lambdaway.free.fr/lambdawalks/data/gandhi_adami.jpg 100 500 Gandhi is fan of lambdatalk!} _h1 prime pattern {sup 3} -> lambdas _p Writing a function swap interchanging hello and world in such a sentence "I just say hello world!" is simple. Just think {pre replace: x & y in: I just say y x! by: hello world } _p and translate into the '{lambda talk} syntax: {pre '{{lambda {x y} I just say y x! } hello world} -> {{lambda {x y} I just say y x! } hello world} } _p Ooops! Where "{i I just saworld world hello!}" is coming from? _p Well, it's time to remind what exactly means {i replacement}. It means that every occurrence of {b x} and {b y} found in the sentence will be replaced by {b hello} and {b world} ... and that's exactly what happens. Even the character {b y} in the word {b say} is replaced and we don't want that. A good rule is to systematically prefix words to be replaced by a colon, {b :}, like this {b :x} and {b :y}, which has the added advantage of highlighting them as variables, (called function arguments) . {pre '{{lambda {:x :y} I just say :y :x! } hello world} -> {{lambda {:x :y} I just say :y :x! } hello world} } _p Then we can call {b swap} the inner expression {pre '{def swap {lambda {:x :y} I just say :y :x!}} -> {def swap {lambda {:x :y} I just say :y :x!}} } _p and call it safely and several times {pre '{swap hello world} -> {swap hello world} } {pre '{swap james bond} -> {swap james bond} } _p Note: prefixing arguments with a colon is generally a good rule, the {b y} in {b say} is not matched by {b :y} and won't be replaced. But it is not the safest rule. For instance if {b :x1} and {b :x2} are good names, {b :x} and {b :x1} are not because {b {u :x}} matches {b :x} in {b {u :x}1}. The safest rule would be to {b prefix and append} names with a colon, like {b :x:} and {b :x1:}. The key rule is to avoid any name which can be found in another one. So instead of {b {u :h}} and {b {u :h}ello}, use {b :h:} and {b :hello:}. _p In the following example {pre '{def smart_add {lambda {:x :y} I say that the sum of x=:x and y=:y is equal to {+ :x :y}. }} -> {def smart_add {lambda {:x :y} I say that the sum of x=:x and y=:y is equal to {+ :x :y}. }} } {pre '{smart_add 3 4} -> {smart_add 3 4} } _p we can see clearly how characters {b x} and {b y} are prevented from any unwanted replacement. We can see also a great advantage of '{lambda talk} over other programming languages (I'm aware of), the ease with which arguments are mixed with other words in a sentence, without any need to put them in quotation marks. No need to write {pre "I say that the sum of x=" + x + " and y=" + y + " is equal to " + (x+y) } _p like we should do in Javscript for instance. Good news when working in a wiki context where you have to work on long texts incorporating code. _p Before going further let's come back to the basis and give a general definition. A '{lambda talk} expression follows these syntax: {pre {b . '{lambda talk} syntax λ calculus syntax expression := words e := w | '{lambda {words} expression} | λw.e | '{expression expression} | ee | '{def name expression} }} _p where "|" means "or" and word is any group of characters except curly braces '{} and spaces. It's a recursive definition leading to any convoluted expressions we can imagine, for instance: {pre '{{lambda {:l} {{lambda {:f :n} {:f :f :n}} {lambda {:f :l} {{{lambda {:c :a :b} {:c :a :b}} {{lambda {:p} {:p {lambda {:a :b} {lambda {:a :b} :b}}}} :l} {lambda {:f :l} } {lambda {:f :l} {{lambda {:p} {:p {lambda {:a :b} :a}}} :l} {:f :f {{lambda {:p} {:p {lambda {:a :b} :b}}} :l}}}} :f :l}} :l}} {{lambda {:a :b :c} {:c :a :b}} hello {{lambda {:a :b :c} {:c :a :b}} brave {{lambda {:a :b :c} {:c :a :b}} new {{lambda {:a :b :c} {:c :a :b}} world {lambda {:a} {lambda {:a :b} :a}}}}}}} -> hello brave new world } _p {b No, don't run away}, no matter what the detail, let yourself be carried away by the music. Solfege is another story. If you like solfege you could have a look at kernel. _p The next step will be to forget abstractions and maths and see how '{lambda talk} can extend the capabilities of HTML/CSS, thanks to functions, to create funny wiki pages. Meanwhile you could analyze this page seven days|http://lambdaway.free.fr/workshop/?view=seven_days or this one pub. _p {i Alain Marty 2019/11/11 update 2021/11/26} {style ;; pre { box-shadow:0 0 8px #000; padding:5px; } }