The English and Persian glossary
Every Salam program can be written in English or in Persian. The two spellings go through the same compiler and follow the same rules, so this glossary is all you need to read a program in the other language or move one across.
One program, two languages
These two programs are the same, and produce the same output:
func fibonacci(n: int): int:
if n < 2:
ret n
end
ret fibonacci(n - 1) + fibonacci(n - 2)
end
func main:
repeat 10 in i:
print fibonacci(i), ""
end
println ""
endتابع فیبوناچی(ن: صحیح): صحیح:
اگر ن < ۲:
برگشت ن
پایان
برگشت فیبوناچی(ن - ۱) + فیبوناچی(ن - ۲)
پایان
تابع ریشه:
تکرار ۱۰ در ک:
چاپ فیبوناچی(ک), ""
پایان
سرچاپ ""
پایانsalam translate fa program.salam turns English code into Persian, and salam translate en goes the other way. It rewrites keywords, types, the entry function and the built-in methods. The compiler decides which language a file is in from its keywords, and a file uses one language throughout: in a Persian file the English spelling of a built-in name is an error, and the message names the Persian one.
Keywords
| English | Persian | English | Persian |
|---|---|---|---|
func | تابع | ret | برگشت |
main | ریشه | end | پایان |
if | اگر | else | وگرنه |
repeat | تکرار | until / to | تا |
each / by | هر | in | در |
break | بشکن | continue | گذر |
match | همخوان | switch | ترابرد |
mut | ناپایا | const | پایا |
struct | ساختار | enum | جداشمار |
type | گونه | interface | میانجی |
impl | کاربست | on | بر |
pub | همگانی | this | این |
as | برگردان | defer | دیرکن |
true | درست | false | نادرست |
null | پوچ | input | ورودی |
print | چاپ | println | سرچاپ |
printerr | نادرستچاپ | printerrln | نادرستسرچاپ |
and | و | or | یا |
not | وارونه | eq / neq | برابر / نابرابر |
lt / gt | کوچکتر / بزرگتر | lte / gte | کوچکتربرابر / بزرگتربرابر |
package | بسته | import | واردسازی |
include | فراخوانی | extern | درونداد |
export | برونداد | layout | چیدمان |
component | بخش | pure | ناب |
inline | درخط | noinline | نادرخط |
noret | نابرگشت | deprecated | بیکاره |
The comparison words eq, neq, lt, gt, lte and gte stand for ==, !=, <, >, <= and >=, and both forms work in both languages. In Persian, تا is until at the start of a statement and to inside a repeat header, and هر is each at the start of a statement and the step by inside a repeat header. main is not a keyword but the name of the entry function, which a Persian program calls ریشه.
Context words
These words are keywords only in one position, so they can still be used as names elsewhere:
| English | Persian | English | Persian |
|---|---|---|---|
static | ایستا | link | پیوند |
dynamic | پویا | framework | چارچوب |
use | شامل | dyn | پویا |
mut func | ناپایا تابع | defined | تعریفشده |
static appears in static func and in link static. Persian پویا has two jobs: after پیوند it means dynamic, and in front of an interface type it means dyn. defined(NAME) belongs to conditional compilation.
Types
| English | Persian | English | Persian |
|---|---|---|---|
void | تهی | bool | منطقی |
char | نویسه | uchar | یونیکد |
str | رشته | int / i32 | صحیح / صحیح۳۲ |
i8 / i16 | صحیح۸ / صحیح۱۶ | i64 | صحیح۶۴ |
uint / u32 | طبیعی / طبیعی۳۲ | u8 / u16 | طبیعی۸ / طبیعی۱۶ |
u64 | طبیعی۶۴ | usize | اندازه مثبت |
size | اندازه | float / f32 | اعشار / اعشار۳۲ |
f64 | اعشار۶۴ | Vector | وکتور |
HashMap | نگاشت | MapIter | پیمایشگرنگاشت |
File | پرونده | Variant | گوناگون |
func (as a type) | تابع | dyn | پویا |
Watch the floating-point types in Persian: اعشار on its own is the 32-bit float, and a literal such as ۲.۵ is an اعشار۶۴. The digits in a type name can be Persian or ASCII, so صحیح۶۴ and صحیح64 are the same type.
Built-in functions
A handful of functions need no import. A Persian program must use their Persian names:
| English | Persian | English | Persian |
|---|---|---|---|
len | طول | sizeof | اندازهگونه |
hash | درهم | open | بازکردن |
args | آرگومانها | lang | زبان |
listdir | فهرستپوشه | char_code | کدنویسه |
char_from_code | نویسهازکد | strcmp | مقایسهرشته |
spawn | نخساز | join | نخپیوند |
callhandler | فراخواندستگیره | atomic_load | اتمیبخوان |
atomic_store | اتمیبنویس | atomic_add | اتمیبیفزا |
atomic_swap | اتمیجابجا | atomic_cas | اتمیمقایسه |
Most of them appear in earlier lessons: len on arrays and strings, spawn and join in Concurrency. sizeof takes a type, char_code gives the code of the first letter of a string, and lang() tells a program which language its own source is written in. This example uses several of them, with a few built-in methods:
func main:
word := "salam"
println lang(), len(word), sizeof(i64)
println char_code("A"), char_from_code(66), strcmp("ab", "ac") < 0
mut names := Vector {} as Vector<str>
defer names.free()
names.push("sara")
names.push("reza")
println names.len(), names.get(1), names.pop()
mut ages := HashMap {} as HashMap<str, int>
defer ages.free()
ages.put("sara", 31)
println ages.has("sara"), ages.get("sara"), ages.size()
text := " hello world ".trim()
println text.starts_with("hello"), text.find("world"), text.substr(0, 5)
println "سلام".len(), "سلام".char_count()
endBuilt-in methods
Strings, vectors, maps, files and map iterators have methods built into the language, and they have a Persian spelling as well:
| English | Persian | English | Persian |
|---|---|---|---|
push | بیفزا | pop | دربیاور |
get | بگیر | ref | ارجاع |
set | بنشان | len | طول |
cap | ظرفیت | free | آزادکن |
put | درج | has | دارد |
remove | حذف | size | اندازه |
iter | پیمایش | has_next | داردبعدی |
key | کلید | value | مقدار |
next | بعدی | read | خواندن |
readline | خواندن خط | write | نوشتن |
seek | جابجایی | close | ببند |
concat | پیوست | substr | زیررشته |
find | بیاب | split | بشکاف |
trim | پیراست | to_int | به صحیح |
to_float | به اعشار | char_count | شمارنویسه |
char_at | نویسه شماره | char_substr | زیررشته نویسه |
char_find | بیاب نویسه | starts_with | شروع با |
ends_with | ختم با | includes | دربردارد |
copy | رونوشت | deep_copy | رونوشت عمیق |
Two of the names count bytes, not letters: len and find work on the bytes of a string, so "سلام".len() is 8. Use char_count, char_at and char_find to work letter by letter, as the last line of the example above shows.
Compile-time constants
The constants of conditional compilation have Persian names too, and a Persian program must use them:
| English | Persian | English | Persian |
|---|---|---|---|
SALAM_OS_WINDOWS | سلام سیستم ویندوز | SALAM_OS_WIN64 | سلام سیستم ویندوز۶۴ |
SALAM_OS_WIN32 | سلام سیستم ویندوز۳۲ | SALAM_OS_WASM | سلام سیستم وباسمبلی |
SALAM_OS_ANDROID | سلام سیستم اندروید | SALAM_OS_LINUX | سلام سیستم لینوکس |
SALAM_OS_MAC | سلام سیستم مک | SALAM_OS_BSD | سلام سیستم بیاسدی |
SALAM_OS_FREEBSD | سلام سیستم فریبیاسدی | SALAM_OS_OPENBSD | سلام سیستم اوپنبیاسدی |
SALAM_OS_NETBSD | سلام سیستم نتبیاسدی | SALAM_OS_UNIX | سلام سیستم یونیکس |
SALAM_OS_UEFI | سلام سیستم یوئیافآی | SALAM_OS_SALAMOS | سلام سیستم سلام |
SALAM_ARCH_X64 | سلام معماری ایکس۶۴ | SALAM_ARCH_X86 | سلام معماری ایکس۸۶ |
SALAM_ARCH_ARM64 | سلام معماری آرم۶۴ | SALAM_ARCH_ARM | سلام معماری آرم |
SALAM_ARCH_WASM | سلام معماری وباسمبلی | SALAM_MEM_DEBUG | سلام اشکالزدایی حافظه |
SALAM_ASAN | سلام پاکساز نشانی | SALAM_SAFE | سلام ایمن |
SALAM_FREESTANDING | سلام خودایستا | SALAM_KERNEL | سلام هسته |
SALAM_JS | سلام جاوااسکریپت | SALAM_OS | سلام سیستم |
SALAM_ARCH | سلام معماری | SALAM_VERSION | سلام نگارش |
SALAM_VERSION_CODE | سلام کد نگارش | SALAM_GIT_COMMIT | سلام کامیت گیت |
SALAM_GIT_DATE | سلام تاریخ گیت | SALAM_GIT_DIRTY | سلام گیت ناپاک |
SALAM_BUILD_DATE | سلام تاریخ ساخت |
SALAM_JS exists only when the program is compiled to JavaScript, so ask defined(SALAM_JS) rather than testing it directly. SALAM_GIT_DIRTY is text, "-dirty" for a compiler built from uncommitted sources.
Standard library packages and their functions have Persian names as well, such as رشته for str and ریاضی.جذر for math.Sqrt. Each package page in the library reference lists both names.