User:Ramcinfo/fancu staile: Difference between revisions

From Lojban
Jump to navigation Jump to search
No edit summary
No edit summary
Line 26: Line 26:
       resu'ult buboi me'au fun buboi lo fu'un buboi be arg buboi kei kei goi compose buboi
       resu'ult buboi me'au fun buboi lo fu'un buboi be arg buboi kei kei goi compose buboi


   function compose(fuun, fun) {
   function compose(fun, fuun) {
     return function (arg) {
     return function (arg) {
       return fun(fuun(arg)); }}
       return fun(fuun(arg)); }}

Revision as of 19:03, 23 February 2015

Let us think about selbri as function taking its terbri as arguments and returning the predication, or bridi. This predication can be then claimed in context, returning truth-value of resulting bridi in that context.

 function tavla(speaker, listener, subject, language) {...} // returns predication
 function claim(predication, context) {...} // returns boolean
 claim(tavla("me", "you", "lojban", "lojban"), context);

To build functions returning other things, we can use {lo}. Let us not go into intricacies of descriptors and pretend what {lo selbri} returns simply some value s1 such that claim(selbri(s1, s2...sx), context) will be true for some values of s2...sx and claimed with some context. Arguments other than context could be restricted with {be...bei...be'o}. So {lo selbri be sumti2 bei sumti3 be'o} is x1 = selbri1(sumti2, sumti3).

{loka}- and {me'ei}-abstractions, then, are predication-returning functions as first-class values. {me'au} with these abstractions is function application; {kai'u} is immediate function application.

We are now ready to construct function taking a function as argument and returning other function. Let's start with apply (for unary function):

 lo ka result buboi fun buboi .arg buboi ce'ai
   result buboi me'au fun buboi .arg buboi kei goi .apli buboi
 function apply(fun, arg) {
   return fun(arg); } 

Now we can use it as such:

 lo me'au .apli buboi be me'ei tavla bei mi be'o

Function composition, compose (for unary functions, still):

 lo ka result buboi fun buboi fu'un buboi ce'ai
   result buboi ka resu'ult buboi arg buboi ce'ai
     resu'ult buboi me'au fun buboi lo fu'un buboi be arg buboi kei kei goi compose buboi
 function compose(fun, fuun) {
   return function (arg) {
     return fun(fuun(arg)); }}