Category:Lambdatalk: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 42:
 
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:
 
{def word expression}
 
allowing to create constants added to the dictionary and give names to anonymous functions.
 
What can be done with so little?
 
Hello World
-> Hello World
 
Out of curly braces words are not evaluated.
 
{def HI Hello World}
-> HI
 
HI, I just say {HI}
-> HI, I just say Hello World
 
Sequences of words can be given a name.
 
{{lambda {o a} oh happy day!} oOOOo aaAAaa}
-> oOOOoh haaAAaappy daaAAaay!
 
The abstraction is defined and immediately called. The abstraction is first evaluated, the application gets the awaited values oOOOo and aaAAaa, calls the abstraction which makes the substitution and returns the result, oOOOoh haaAAaappy daaAAaay!. Abstractions can be given a name and then called easily several times:
 
{def GOOD_DAY {lambda {o a} oh happy day!}}
-> GOOD_DAY
 
{GOOD_DAY oOOOo aaAaa}
-> oOOOoh haaAaappy daaAaay!
{GOOD_DAY ♠ ♥}
-> ♠h h♥ppy d♥y!
 
Most of the time expressions are nested. The expression below returns the first word of Hello World:
 
{{lambda {z}
{z {lambda {x y} x}}}
{{lambda {x y z}
{z x y}} Hello World}}
-> Hello
 
Using names helps to recognize a data structure and its accessors:
 
{def CONS {lambda {:x :y :z} {:z :x :y}}} -> CONS
{def CAR {lambda {:z} {:z {lambda {:x :y} :x}}}} -> CAR
{def CDR {lambda {:z} {:z {lambda {:x :y} :y}}}} -> CDR
 
{CAR {CONS Hello World}} -> Hello
{CAR {CONS Hello World}} -> World
 
===Implementation===
 
{lambda talk} is not implemented following the standard process, code -> tokens -> tree -> eval. '''The code is a string from beginning to end'''. At each keyboard input, the code is processed by a single function, do_eval(), which returns words sent to the browser for the final evaluation and display.:
 
var do_eval = function( code ) {
Line 56 ⟶ 107:
};
 
Using a single '''regular expression''' the eval_forms() function loops over the code string, skips the words out of curly braces, matches nested forms {first rest} from inside out, and replaces them by words. The repeated substitutions inside the code string overcomes limitations of regular language. It's a kind of Turing machine.
 
The eval_lambdas() function uses arguments as Regular'''regular Expressionsexpressions''' to successively replace occurencesoccurrences 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 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 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.
 
==B) {lambda talk} full==
 
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.
 
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.
As a dwarf standing on their shoulders, {lambda talk} takes benefit from the extraordinary power of modern web browsers. It does not re-invent the wheel and simply adds a coherent and unique language on existing tools.
 
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 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.
 
A full presentation of {lambda talk} can be seen in:
Line 82 ⟶ 131:
- http://lambdaway.free.fr/workshop/?view=oxford_slides
- and several other pages of the workshop.
 
Your opinion is welcome. Alain Marty