samtrosku examples

From Lojban
Revision as of 12:21, 23 March 2014 by Gleki (talk | contribs) (Gleki moved page jbocre: samtrosku examples to samtrosku examples without leaving a redirect: Text replace - "jbocre: s" to "s")
Jump to navigation Jump to search

coi (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}:

.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