Hello world
এই পেজে প্রথম Beans program-টা একদম খালি file থেকে শুরু করে native binary পর্যন্ত নিয়ে যাওয়া হবে।
program-টা লেখা
“program-টা লেখা” সেকশনএটা hello.b নামে save করুন:
import std.io
fn main() { let name: string = "beans" io.println("hello from {name}")}কয়েকটা জিনিস খেয়াল করুন:
import std.iostandard I/O package টেনে আনে।io.printlnওখানেই থাকে।fn main()হলো যেখান থেকে program শুরু হয়।let name: string = "beans"একটা value declare করে।letবলে দেয় এটা আর বদলাবে না। type-টা,string, লেখা আছে। Beans নিজে থেকে সেটা ধরে নেয় না।"hello from {name}"একটা interpolated string।{name}-এর জায়গায়name-এর value বসে যায়।
check করা
“check করা” সেকশনprogram-টা না চালিয়েই type-check করুন:
beansc check hello.bhello.b: okcheck type error আর অন্য ভুলগুলো দ্রুত ধরে ফেলে। এটা কিছু চালায় না।
চালানো
“চালানো” সেকশনকোনো build step ছাড়াই program-টা reference interpreter-এ চালান:
beansc run hello.bhello from beansকাজ করতে করতে output দেখার সবচেয়ে দ্রুত উপায় হলো run।
একটা native binary build করা
“একটা native binary build করা” সেকশনLLVM দিয়ে একটা সত্যিকারের executable-এ compile করুন:
beansc build hello.b -o hello./hellohello from beansinterpreter (run) আর native binary (build) একই output দেয়। দুই backend-ই হুবহু একরকম
আচরণ করে।
একটা optimized binary build করা
“একটা optimized binary build করা” সেকশনRelease build-এর জন্য optimization, link-time optimization আর নিজের CPU-এর জন্য tuning চালু করুন:
beansc build --release --lto --cpu native hello.b -o helloযে উদাহরণটা compile হয় না
“যে উদাহরণটা compile হয় না” সেকশনBeans-এ return type আছে এমন কোনো function-কে প্রতিটা পথেই return করতে হবে। এই program-টা ইচ্ছা করেই ভুল। docs-এর example checker নিশ্চিত করে যে এটা compile হতে ব্যর্থ হয়:
fn total() -> int { var sum: int = 0 sum // a trailing expression is discarded, not returned}error: 'total' must return int — the body can finish without a returnঠিক করার উপায় হলো return sum লেখা। দেখুন Function আর closure।
এক file পার হয়ে বড় হতে চাইলে একটা project তৈরি করুন। এখানে ব্যবহার করা command-গুলো নিয়ে আরও জানতে দেখুন Check আর run আর Build।