+
1
|
list
|
skin
|
login
|
editor
α-wwwiki
::
xtending
user:none
(2594 bytes)
_h1 core vs inline functions _p Extending the core functions of lambdatalk can be done via two ways : _ul by hardcoding them in the xhtml array (in the file [[JS.js|meca/JS.js]]), _ul by writing them in the wiki pages using the "define" operator. _p This way, it's easy to test new functions which will eventually added in the lambdatalk core. Or to subtract some others without a global interest, and get a minimal library of main fundamental functions extended by optionnal libraries to be included on demand. A window towards a collaborative work. _h3 defining sqr(x) {pre 1) function could be defined in the lambdatalk core like this : °° xhtml['sqr'] = function () { return rest*rest; }°° 2) function is defined in this page like this : °°{define sqr (x) return x*x;}°° -> {define sqr (x) return x*x;} } _h3 serie & map example _p The functions serie and map could be defined in the lambdatalk core like this : {pre °° xhtml['serie'] = function () { // {serie start end} var args = rest.split( / /g ); var start = args[0]; var end = args[1]; for (var i=start, str=''; i< =end; i++) str += i + ' '; str = str.replace( / $/, '' ); return str; }; xhtml['map'] = function () { // {map func serie} var serie = rest.split( / /g ); var func = serie.shift(); for (var i=0, str=''; i< serie.length; i++) { str += '{' + func + ' ' + serie[i] + '} '; } return str; }; °° } _p The functions serie & map can be coded via the "define" operator : {pre °° {define iserie (start end) // {iserie start end} end++; for (var i=start, str=''; i< end; i++) str += i + ' '; return str; } {define imap () •• // {imap func iserie} var args = [].slice.call(arguments); var func = args[0]; var serie = args.slice( 1, args.length ); for (var i=0, str=''; i< serie.length; i++) { str += '{' + func + ' ' + serie[i] + '} '; } return str; ••} }°° {define iserie (start end) end++; for (var i=start, str=''; i< end; i++) str += i + ' '; return str; } {define imap () °° var args = [].slice.call(arguments); var func = args[0]; var serie = args.slice( 1, args.length ); for (var i=0, str=''; i< serie.length; i++) { str += '{' + func + ' ' + serie[i] + '} '; } return str; °°} } _p And now, calling serie & map {pre °°{iserie 1 20}°° -> {iserie 1 20} °°{imap sqr {iserie 1 20}}°° -> {imap sqr {iserie 1 20}} } _h3 note _p The code of the functions are similar, excepted the way arguments are handled.