Aperçu de « ELS_2014 - epsilonwiki

Apr 19, 2014 - interactions with these data leading to web apps like blogs, wikis and CMS. Hundreds of ... 3: {sin {/ {PI} 2}}. 4: {map {lambda {:x} {* :x :x}} {serie ...
339KB taille 6 téléchargements 43 vues
+

ELS_2014 :: A4_2

Yet Another Wiki! Alain Marty Engineer Architect 66180, Villeneuve de la Raho, France [email protected] Abstract The present contribution introduces a small environment working on top of any modern browser, allowing to write, style and script dynamic WEB pages using a simple and unique LISP-like syntax.

Keywords Wiki, CMS, interpreter, language, Lisp

1......INTRODUCTION Web browsers can parse data (HTML code, CSS rules, JS code, ...) stored on the server side and display rich multimedia dynamic pages on the client side. Some HTML functions, (texarea, input, form, ...) associated with script languages (PHP,...) allow interactions with these data leading to web apps like blogs, wikis and CMS. Hundreds of engines have been built, managing files on the server side and interfaces on the client side, such as Wordpress, Wikipedia, Joomla,.... Syntaxes are proposed to simplify text enrichment, pages composing, multimedia handling. The Markdown syntax is the de facto standard to help writing styled and structured texts, but stays far from the wish of the father of LISP, John McCarthy: « An environment where the markup, styling and scripting is all s-expression based would be nice. » Works have been done in this direction, for instance: Skribe [1] a text-processor based on the SCHEME programming language dedicated to writing web pages, HOP [2] a Lisp-like progamming language for the Web 2.0, based on SCHEME, BRL [3] based on SCHEME and designed for server-side WWW-based applications. All of these projects are great and powerful. With the plain benefit of existing SCHEME implementations they make a strong junction between the mark-up (HTML/CSS) and programming (JS, PHP,...) syntaxes. But these tools are devoted to developers, not to users or web-designers. The α-wiki project [4] is intended to link the user, the web-designer and the developer in a single collaborative work: 1) α-wiki is a small wiki intended to be easy to install, its archive is about 100kb (about 1000 JS lines), with nothing but PHP on the server side and no external library. 2) α-wiki is a small and easy to use environment on top of the browser allowing to write, style and script WEB pages with the same LISP-like syntax: λ-talk. In this paper I will present a few elements of this syntax and its evaluator.

2......λ-talk SYNTAX The code is keyed into the frame editor as a mix of plain text and s-expressions. Valid s-expressions are evaluated by λ-talk and displayed by α-wiki in the wiki page; others are ignored. At least, the code is displayed without any enrichment and without any structure, as a sequence of words.

2.1.....Words First of all, α-wiki is a text editor. As in any text editor, enriching a sequence of words proceeds into two steps: select & apply. In α-wiki, selection uses curly braces { } and application uses a dictionary of HTML tags, to build s-expressions : {tag any text}. λ-talk translates them into HTML expressions to be evaluated and displayed by the browser. For instance, writing in the editor frame: {div {@ id="myId"} I am {b fat}, I am {b {i fat italicized}}, I am {b {i {u fat italicized underlined}}}. } displays in the wiki page : I am fat, I am fat italicized, I am fat italicized underlined. Note that the function @ contains HTML attributes and CSS rules expressed in the standard HTML/CSS syntax, not in an s-expression syntax. This is a matter of choice : not to use a pure s-expression such as {@ {id myId} {style {text-align center} {border 1px solid}}} avoids dictionary pollution, support HTML/CSS future evolution and is well known by a web-designer.

2.2......Numbers α-wiki offers the usual numeric computation capabilities that a pocket calculator would have. Following the same syntax {first rest} where first is a math function (+, -, *, /, %, sqrt, ...) and rest a sequence of numbers and/or valid s-expressions, any complex math expressions can be evaluated by λ-talk and inserted anywhere in the page, for instance writing in the editor frame: 1: 2: 3: 4: 5:

{* 1 2 3 4 5 6} {sqrt {+ {* 3 3} {* 4 4}}} {sin {/ {PI} 2}} {map {lambda {:x} {* :x :x}} {serie 1 10}} {reduce + {serie 1 100}}

displays in the wiki page : 1: 720 2: 5 3: 1 4: 1 4 9 16 25 36 49 64 81 100 5: 5050

2.3......Code λ-talk is a programmable programming language. It keeps from LISP nothing but three special forms (lambda, def, if) opening the door to recursion (and thus iteration), local variables (via lambdas), partial application (currying). The if, lambda, def forms can be nested and the λ-talk's dictionary can be extended via the def form. For instance, writing in the editor frame :

every keyUp and the page's display follows the edition in real-time: {b 1) a basic function:} {def hypo {lambda {:a :b} {sqrt {+ {* :a :a} {* :b :b}}}}} hypo(3,4) = {hypo 3 4} {b 2) a recursive function:} {def fac {lambda {:n} {if {< :n 1} then 1 else {* :n {fac {- :n 1}}}}}} fac(6) = {fac 6} {b 3) the first derivees of y=x{sup 3} using partial function calls:} {def D {lambda {:f :x} {/ {- {:f {+ :x 0.01}} {:f {- :x 0.01}}} 0.02}}} {def cubic {lambda {:x} {* :x :x :x}}} cubic(1)={cubic 1} cubic'(1)={{D cubic} 1} cubic''(1)={{D {D cubic}} 1} cubic'''(1)={{D {D {D cubic}}} 1} cubic''''(1)={{D {D {D {D cubic}}}} 1} displays in the wiki page: 1) a basic function: hypo hypo(3,4) = 5 2) a recursive function: fac(6) = 720 3) the first derivees of y=x3 using partial function calls: cubic cubic(1) =1 cubic'(1) = 3.0000999999999998 ≠3 cubic''(1) = 5.999999999999628 ≠6 cubic'''(1) = 6.000000000007111 ≠6 cubic''''(1) = 4.107825191113079e-9 ≠0 And the underground JS language can always be called via the input function and external plugins to give access to user interaction (buttons) and more complex tools like graphics, raytracing, fractals, and spreadsheets. Spreadsheets are known to be a good illustration of the functional approach, for instance:

function evaluate(str) { str = preprocessing( str ); str = eval_ifs( str ); str = eval_lambdas( str ); str = eval_defs( str, true ); str = eval_sexprs( str ); str = postprocessing( str ); return str; }; The eval_sexprs() function starts a loop based on a single pattern (a Regular Expression) used in only one JS line to replace s-expressions by HTML expressions or evaluated math expressions: function eval_sexprs(str) { var rex=/\{([^\s{}]*)(?:[\s]*)([^{}]*)\}/g; while (str != (str = str.replace(rex,do_apply))); return str; } function do_apply() { var f = arguments[1], r = arguments[2]; if (dico.hasOwnProperty(f)) return dico[f].apply(null,[r]); else return '('+f+' '++')'; }; The three special forms "if, lambda, def" are pre-processed before the s-expressions evaluation. For instance, this is the simplified pseudo-code of the eval_lambda() function: function eval_lambda(s) { s = eval_lambdas(s); var name = random_name() var args = get_arguments(s) var body = get_body(s) dico[name] = function(vals) { return function(bod){ for every i in vals replace in bod args[i] by vals[i] return bod }(body) } return name; } The λ-talk's dictionary contains about 110 primitives handling HTML markup, math functions, ... For instance this the code of a simplified "*" function: dico['*'] = function() { return arguments[0]*arguments[1] };

4. ..... CONCLUSION With α-wiki and λ-talk, the beginner, the web-designer and the developer benefit from a simple text editor and a coherent syntax allowing them, in a gentle learning slope and a collaborative work, to build sets of complex and dynamic pages.

3. .....λ-talk EVALUATOR The λ-talk's code is a function defined and executed on page loading. This function creates a dictionary containing a set of pairs [function_name : function_value], defines the function evaluate() and a few associated ones. The function evaluate() is called at

5. ..... REFERENCES [1] : Manuel Serrano, http://www-sop.inria.fr/, [2] : Manuel Serrano, http://en.wikipedia.org/wiki/Hop, [3] : Bruce R.Lewis, http://brl.sourceforge.net/, [4] : Alain Marty, http://epsilonwiki.free.fr/alphawiki_2/