samtrosku examples: Difference between revisions
Jump to navigation
Jump to search
m (Gleki moved page jbocre: samtrosku examples to samtrosku examples without leaving a redirect: Text replace - "jbocre: s" to "s") |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
=='''coi''' (''Hello'')== | |||
'''coi''' (the quintessential first program) | (the quintessential first program) | ||
Program: | Program: | ||
.i ko cusku lo'u ui coi munje le'u | <code>.i ko cusku lo'u ui coi munje le'u</code> | ||
Output: | Output: | ||
.ui coi munje | <code>.ui coi munje</code> | ||
(Yes, a dot would be inserted - I assume that in displaying Lojban strings, which are different from character strings, the samtrosku interpreter would choose the most canonical form). | |||
tu'u | =='''nu'a ne'o''' (factorial)== | ||
Assuming that factorial isn't a built-in operation with {{jvs|ne'o}}, you could implement it as the brivla {{vlapoi|nu'a|ne'o}}: | |||
<tab class=wikitable> | |||
.i ca'e ko'a nu'a ne'o ko'e ijo ('X == Y factorial' is defined as:) | |||
tu'e | |||
ny goi 1 (n = 1) | |||
.i ko zukte di'e ca le du'u ko'e zmadu li 1 (while Y > 1 do this...) | |||
.itu'e | |||
ko dungau ny li ny pi'i ko'e (n = n*Y) | |||
.i ko dungau ko'e li ko'e vu'u 1 (Y = Y-1) | |||
tu'u | |||
.i ko'a jagdu'o ny (return n as the value of X) | |||
tu'u </tab> |
Latest revision as of 06:36, 14 April 2015
coi (Hello)
(the quintessential first program)
Program:
.i ko cusku lo'u ui coi munje le'u
Output:
.ui coi munje
(Yes, a dot would be inserted - I assume that in displaying Lojban strings, which are different from character strings, the samtrosku interpreter would choose the most canonical form).
nu'a ne'o (factorial)
Assuming that factorial isn't a built-in operation with ne'o, you could implement it as the brivla nu'a ne'o: <tab class=wikitable> .i ca'e ko'a nu'a ne'o ko'e ijo ('X == Y factorial' is defined as:) tu'e ny goi 1 (n = 1) .i ko zukte di'e ca le du'u ko'e zmadu li 1 (while Y > 1 do this...) .itu'e ko dungau ny li ny pi'i ko'e (n = n*Y) .i ko dungau ko'e li ko'e vu'u 1 (Y = Y-1) tu'u .i ko'a jagdu'o ny (return n as the value of X) tu'u </tab>