Category:Lambdatalk: Difference between revisions

Content added Content deleted
No edit summary
No edit summary
Line 16: Line 16:
-> 2+3 is equal to 5
-> 2+3 is equal to 5


• 3) Functions are created with lambda and named with def.
• 3) Functions are created with '''lambda''' and named with '''def'''.


{def foo
{def foo
Line 37: Line 37:
1) a word is any character except spaces and curly braces, and is not evaluated out of curly braces,
1) a word is any character except spaces and curly braces, and is not evaluated out of curly braces,


2) an abstraction is a special form (called a function) selecting words (called arguments) in an expression (called the body), and is evaluated to a word referencing an anonymous function added to a single dictionary, initially empty,
2) an abstraction is a '''special form''' (called a function) selecting words (called arguments) in an expression (called the body), and is evaluated to a word referencing an anonymous function added to a single dictionary, initially empty,


3) an application is a simple form calling an abstraction to replace selected words by some other words (called values), and is evaluated to words.
3) an application is a '''simple form''' calling an abstraction to replace selected words by some other words (called values), and is evaluated to words.


The evaluation stops when all expressions have been replaced by words.
The evaluation stops when all expressions have been replaced by words.


In order to make code easier to write and read, we add a second special form:
In order to make code easier to write and read, we define a second special form:


{def word expression}
{def word expression}
Line 58: Line 58:
{def HI Hello World}
{def HI Hello World}
-> HI
-> HI

HI, I just say {HI}
HI, I just say {HI}
-> HI, I just say Hello World
-> HI, I just say Hello World
Line 71: Line 70:
{def GOOD_DAY {lambda {o a} oh happy day!}}
{def GOOD_DAY {lambda {o a} oh happy day!}}
-> GOOD_DAY
-> GOOD_DAY

{GOOD_DAY oOOOo aaAaa}
{GOOD_DAY oOOOo aaAaa}
-> oOOOoh haaAaappy daaAaay!
-> oOOOoh haaAaappy daaAaay!
Line 90: Line 88:
{def CAR {lambda {:z} {:z {lambda {:x :y} :x}}}} -> CAR
{def CAR {lambda {:z} {:z {lambda {:x :y} :x}}}} -> CAR
{def CDR {lambda {:z} {:z {lambda {:x :y} :y}}}} -> CDR
{def CDR {lambda {:z} {:z {lambda {:x :y} :y}}}} -> CDR

{CAR {CONS Hello World}} -> Hello
{CAR {CONS Hello World}} -> Hello
{CAR {CONS Hello World}} -> World
{CAR {CONS Hello World}} -> World
Line 111: Line 108:
The eval_lambdas() function uses arguments as '''regular expressions''' to successively replace occurrences found in the function's body by the given values. Lambdas have the following properties:
The eval_lambdas() function uses arguments as '''regular expressions''' to successively replace occurrences found in the function's body by the given values. Lambdas have the following properties:


- lambdas are first class functions, they can be called as functions' arguments and returned from functions,
- lambdas are '''first class functions''', they can be called as functions' arguments and returned from functions,


- lambdas are pure black boxes, they '''don't create closures''' and are context free, inner lambdas don't see outer functions' arguments, there are no lexical scoping, no free variables,
- lambdas are pure black boxes, they '''don't create closures''' and are context free, inner lambdas don't see outer functions' arguments, there are no lexical scoping, no free variables,
Line 117: Line 114:
- lambdas accept de facto '''partial function application''': called with a number of values lesser than its arity, a lambda memorizes the given values and returns a new lambda waiting for the rest.
- lambdas accept de facto '''partial function application''': called with a number of values lesser than its arity, a lambda memorizes the given values and returns a new lambda waiting for the rest.


Upon these foundations, after '''Alonzo Church''', we could define the set of natural numbers [ZERO, ONE, TWO, ...] and their associate operators, [SUCC, ADD, MUL, POWER, PRED, ...] allowing to build iterations and recursions. But, as a ''dwarf standing on their shoulders'', {lambda talk} can take benefit from the extraordinary power of modern '''web browsers'''. Without ''re-inventing the wheel'' {lambda talk} simply adds a coherent and unique language on existing tools.
Upon these foundations, after '''Alonzo Church''', we could define the set of natural numbers [ZERO, ONE, TWO, ...] and their associate operators, [SUCC, ADD, MUL, POWER, PRED, ...] allowing to build iterations and recursions. For instance, computing factorials:

{CHURCH
{{lambda {:n}
{{lambda {:g :n} {:g :g :n}}
{lambda {:g :n}
{{{ISZERO :n}
{CONS {lambda {:g :n} ONE}
{lambda {:g :n}
{MUL :n {:g :g {PRED :n}}}}
}} :g :n}} :n}} FIVE}}
-> 120


==B) {lambda talk} full==
==B) {lambda talk} full==


But {lambda talk} can take benefit from the extraordinary power of modern '''web browsers''' and, without ''re-inventinging the wheel'', {lambda talk} simply adds a coherent and unique language on existing tools.
In its complete state, {lambda talk} comes with a more complete set of special forms, [lambda, def, if, let, quote, macro, require, script, style], and a dictionary containing about 200 primitives built on Javascript Math object, the DOM, HTML tags and CSS rules and more, pairs, lists, arrays, ... and more specific to the wiki context.

In its complete state, {lambda talk} comes with a more complete set of special forms, ['''lambda''', '''def''', if, let, quote, macro, require, script, style], and a dictionary containing about 200 primitives built on Javascript Math object, HTML tags and CSS rules, the DOM and more, pairs, lists, arrays, ... and some other specific to the wiki context.


The {lambda way} project adds on browsers a thin overlay, {lambda tank}, proposing a small ''Interactive Development Environment'' without any external dependencies and thereby easy to download (50kb) and install on any web account provider running PHP. From any web browser, on any system, complex and dynamic web pages can be created, enriched, structured and tested in real time on the web.
The {lambda way} project adds on browsers a thin overlay, {lambda tank}, proposing a small ''Interactive Development Environment'' without any external dependencies and thereby easy to download (50kb) and install on any web account provider running PHP. From any web browser, on any system, complex and dynamic web pages can be created, enriched, structured and tested in real time on the web.