User:Ramcinfo/fancu staile

From Lojban
< User:Ramcinfo
Revision as of 01:12, 24 February 2015 by Ramcinfo (talk | contribs)
Jump to navigation Jump to search

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.

apply

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

 lo goi .apli buboi ge'u ka result buboi fun buboi .arg buboi ce'ai
   result buboi me'au fun buboi .arg buboi kei
 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

It could be rewritten in CLL Lojban, but would be (even) less readable:

 cylylypapi'epa jo'au
 lo ka bridi ce'u ce'u ce'o ce'u kei goi ko'a
 zo'u co'e zo'e poi bridi be ko'a bei lo ka ce'u tavla ce'u ku ce'o ke'a ce'o mi

compose

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

 lo goi compose buboi ge'u 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 me'au fu'un buboi be .arg buboi kei kei
 function compose(fun, fuun) {
   return function (arg) {
     return fun(fuun(arg)); }}

Recursion

Infinite recursion (do not try it at home):

 lo goi .inf bu rec buboi ge'u ka me'oi .inf bu rec buboi kei 
 function infRec() {
   infRec();
 }

I am not sure of the last one. Maybe {goi} works only forward in scope. {me'oi ka nei} (or simply {nei}) will do almost the same, I guess.

if

Confitional (taken from Tsani’s recursive predicate definition, replacing {ckaji} with {du}):

 lo goi .if buboi ge'u ka result buboi condition buboi by boi cy boi ce'ai
   ge ganai condition buboi gi result buboi du by boi
      gi ga condition buboi gi result buboi du cy boi kei

Maybe also la gleki's {ifle} will work:

 lo goi .if buboi ge'u ka result buboi condition buboi by boi cy boi ce'ai
   condition buboi ifle
     lo du'u result buboi du by boi kei
     lo du'u result buboi du cy boi kei

Recursion (again)

Now we are ready to build a simple recursion. {krasi} and {fanmo} are used to get first and last elements of sequence, respectively; I am not very sure if this is appropriate. Now if the style is to be developed in the direction of LISP, then functions working on sequences, like head, tail and cons are to be defined.

{ja'ebo goi} is a hack even dirtier than it is usual for these matters; it is used to both a) group the sequence as one sumti to attach relative clause to it and b) to move that clause to the front.

 lo goi len buboi ge'u ka result buboi list buboi .item buboi ce'ai
   result buboi me'au .if buboi lo du'u .item buboi cu fanmo list buboi kei li pa
     lo sumji be li pa lo me'au len buboi
       be list buboi bei lo bavla'i be .item buboi bei list buboi kei
 je'abo goi sample buboi ge'u by ce'o cy ce'o dy zo'u
 li ci cu me'au len buboi sample buboi lo krasi be sample buboi
 // approximately
 function len(list, item) {
   return (list.indexOf(item) === list.length - 1) ? 1 :
      1 + len(list, list[list.indexOf(item)] + 1); }
 var sample = ["b", "c", "d"];
 assert(3 === len(sample, sample[0]));


aulbuboi.jpg