Operators and precedence
এই পেজে প্রতিটা operator আর সেটা কতটা শক্ত করে বাঁধে, তার তালিকা।
Binary operator precedence
“Binary operator precedence” সেকশনPrecedence ঢিলা (1) থেকে শক্ত (10)-এর দিকে ওঠে। সংখ্যা যত বড়, তত শক্ত করে
বাঁধে, তাই a + b * c পড়া হয় a + (b * c) হিসেবে।
| Level | Operator | অর্থ |
|---|---|---|
| 1 | .. ..= || | range (শেষটা বাদ / শেষটাসহ), logical OR |
| 2 | && | logical AND |
| 3 | == != | সমান কিনা |
| 4 | < <= > >= | তুলনা |
| 5 | | | bitwise OR |
| 6 | ^ | bitwise XOR |
| 7 | & | bitwise AND |
| 8 | << >> | shift |
| 9 | + - | যোগ, বিয়োগ |
| 10 | * / % | গুণ, ভাগ, ভাগশেষ |
range (0..10, 0..=10) সবচেয়ে নিচের level-এ বসে, ||-এর পাশে। এগুলো
ব্যবহার করা হয় for i: int in 0..10-এ, আর match arm-এ (400..=499 => ...)।
Unary আর postfix
“Unary আর postfix” সেকশন- Unary
-(ঋণাত্মক করা) আর!(logical not)। - Postfix
.field/.method(...),[index], আর call(...)। ?কোনোResult/Option-এ error উপরে পাঠায়।err/noneহলে সেটা উপরে return করে দেয়; নয়তো unwrap করে। দেখুন Option and Result।asহলো একটা স্পষ্ট numeric cast বা upcast:qty as decimal।as?হলো একটা check করা downcast, যেটা একটাOptionফেরত দেয়। দেখুন Interface আর inheritance।
Postfix, as, as? আর ? উপরের binary operator-গুলোর চেয়ে শক্ত করে বাঁধে।
Assignment
“Assignment” সেকশনAssignment একটা statement, precedence-এর ওঠানামার অংশ না:
= += -= *= /= %=var n: int = 1n += 4n *= 2 // n is now 10Bracket assignment list, map আর fixed array-তে খাটে: xs[i] = v,
m[key] = v। List আর Map-এর bracket assignment-এর কোনো compound form নেই
(xs[i] += 1 চলবে না); fixed array কিন্তু compound element assignment
সমর্থন করে, কারণ তার element একটা আসল inline জায়গা।
Number আর তুলনার নিয়ম
“Number আর তুলনার নিয়ম” সেকশন- fixed-width integer-এর
+,-,*, unary-, আর bit operation-গুলো type-এর width অনুযায়ী wrap করে। shift-এর countwidth - 1দিয়ে mask হয়। শূন্য দিয়ে ভাগ বা modulo করলে panic। - কোনো implicit numeric conversion নেই।
int,floatআরdecimalমেশাতে হলে একটা স্পষ্টasলাগে। - Float-এর তুলনা IEEE-754 মেনে চলে: একটা NaN operand থাকলে
==,<,<=,>,>=false হয়ে যায় আর!=true।
দেখুন Number আর decimal।
যেগুলোর জন্য কোনো operator নেই
“যেগুলোর জন্য কোনো operator নেই” সেকশন- string-এ কোনো
+নেই। string তৈরি করা হয় interpolation দিয়ে ("a {b} c"),std.fmtদিয়ে, বাlist.join(sep)দিয়ে। - কোনো
++/--নেই।+= 1/-= 1ব্যবহার করা হয়। - কোনো ternary নেই। value position-এ
if/matchব্যবহার করা হয় (দেখুন Control flow)।