Writing algorithms in Lojban: Difference between revisions

From Lojban
Jump to navigation Jump to search
Line 57: Line 57:


'''To be improved:'''
'''To be improved:'''
1) {la broda cu du li re} is probably not right; perhaps {la'e la broda} would be better for refering to the variable value.
1) {la broda cu du li re} is probably not right; perhaps {la'e la broda} would be better for refering to the variable value.
2) "jo" is perhaps wrong for "if...then".
2) "jo" is perhaps wrong for "if...then".
3) {dubze'a} is probably nonsensical, it should be replaced with something else. :)
3) {dubze'a} is probably nonsensical, it should be replaced with something else. :)

Revision as of 17:11, 23 July 2014

Attempt at translating a piece of C code to Lojban

char* str_fill(char string[], char filling, uint_t count) {
   if (string) { 
      if (!count) while(string[count]) count++; 
      string[count] = '\0'; 
      while (count--) string[count] = filling; 
   } 
   return string; 
}

English translation:

Function str_fill returning char pointer, taking parameters:
    'string', of type char array; 'filling', of type char; 'count', of type uint_t. 
Variable list: empty.
Instruction list:
    if 'string' is not equal to 0: 
    >   if 'count' is equal to 0: 
    >   >   as long as the offset number 'count' of the array 'string' is not equal to 0: 
    >   >   >   we add 1 to 'count' 
    >   we set the offset number 'count' of the array 'string' to 0 
    >   as long as 'count' is not equal to 0: 
    >   >   we substract 1 from 'count' 
    >   >   we copy 'filling' into the offset number 'count' of the array 'string' 
    we return to the calling function giving the value 'string' 
End of function.

Lojban translation (to be improved):

ni'o ni'o ca'e pruce fa la lerpoiclugau fo di'e
fe la lerpoi noi me'oi .char. judri
ce'o la selclu noi me'oi .char.
ce'o la selzilkancu noi me'oi .uint_t.
fi lo me'oi .char. judri

ni'o to ve pruce liste toi
la lerpoi na du li no .i jo tu'e {
>   la selzilkancu cu du li no .i jo tu'e {
>   >   lo me la selzilkancu moi be la lerpoi na du li no .i jo
>   >   ko'oi rapli co'u lo nu ja'a go'i ku fa lo nu
>   >   ko'oi la selzilkancu cu dubze'a li pa
>   } tu'u
>   .i la selzilkancu na du li no .i jo
>   ko'oi rapli co'u lo nu ja'a go'i ku fa lo nu
>   ge ko'oi la selzilkancu cu dubjdika li pa
>   gi ko'oi lo me la selzilkancu moi be la lerpoi cu fukpi la selclu
} tu'u
.i ko'oi zilxru gi'e pruce fi la lerpoi

To be improved:

1) {la broda cu du li re} is probably not right; perhaps {la'e la broda} would be better for refering to the variable value.

2) "jo" is perhaps wrong for "if...then".

3) {dubze'a} is probably nonsensical, it should be replaced with something else. :)