يرجى ملاحظة أن هذه اللغة هي العمل قيد التقدم.
hello_world is
# first we define a custom mutate effect.
# we will need this for buffered reading from stdin
#
lm : mutate is
# calling `lm` creates an instance of our mutate effect,
# `instate_self` is then used to instate this instance and
# run code in the context of the instated effect.
#
lm ! ()->
# read someone's name from standard input
#
get_name =>
(io.stdin lm) ! ()->
io.buffered.read_line lm ? str String => str | io.end_of_file => ""
# greet someone with the name given
#
greet(name String) is
say "Hello, {name}!"
# greet the user
#
x := greet get_name
# you can access any feature - even argument features of other features
# from outside
#
say "How are you, {x.name}?"
يوضح مثال hello_world أحد المفاهيم المهمة في Fuzion جيدًا: كل شيء هو ميزة . الميزات هي استجابة Fuzion للفوضى التي يتم إنشاؤها بواسطة الفصول والأساليب والواجهات والمفاهيم الأخرى المختلفة في لغات البرمجة الأخرى. نظرًا لأن كل شيء هو ميزة ، فإن المبرمج لا يحتاج إلى رعاية وسيقوم المترجم بهذا العمل. كما ترون ، من الممكن الوصول إلى ميزات وسيطة بعض الميزات من الخارج.
ex_gcd is
# return common divisors of a and b
#
common_divisors_of(a, b i32) =>
max := max a.abs b.abs
(1..max).flat_map i32 i->
if (a % i = 0) && (b % i = 0)
[-i, i]
else
[]
# find the greatest common divisor of a and b
#
gcd(a, b i32)
pre
safety: (a != 0 || b != 0)
post
safety: a % result = 0
safety: b % result = 0
pedantic: (common_divisors_of a b).reduce bool true (acc,cur -> acc && (result % cur = 0))
=>
if b = 0 then a else gcd b (a % b)
say <| gcd 8 12
say <| gcd -8 12
say <| gcd 28 0
هذا المثال ينفذ متغيرًا بسيطًا من الخوارزمية التي تجد أعظم مقسوم مشترك من رقمين. ومع ذلك ، فإنه يوضح أيضًا إحدى ميزات Fuzion البارزة: التصميم حسب العقد. من خلال تحديد شروط ما قبل وما بعدها للميزات ، يتم إجراء عمليات التحقق من الصواب.
generator_effect is
# define a generator effect with a yield operation
#
gen(T type,
yield T->unit # yield is called by code to yield values
) : effect is
# traverse a list and yield the elements
#
list.traverse unit =>
match list.this
c Cons => (generator_effect.gen A).env.yield c.head; c.tail.traverse
nil =>
# bind the yield operation dynamically
#
(gen i32 (i -> say "yielded $i")) ! ()->
[0,8,15].as_list.traverse
مفهوم رئيسي آخر في Fuzion هو مفهوم التأثير الجبري - نهج جديد لتغليف التعليمات البرمجية ذات الآثار الجانبية بطريقة آمنة.
في المثال أعلاه ، تم استخدام تأثير مخصص لتنفيذ مولد مع تشغيل yield . في بعض اللغات الأخرى ، يتطلب ذلك تقديم yield كلمة رئيسية بواسطة اللغة ، ولكن في Fuzion يمكن تنفيذ ذلك دون دعم اللغة.
إذا كنت ترغب في اللعب مع Fuzion ، جرب البرنامج التعليمي التفاعلي.
تحقق من fuzion-lang.dev لتصميم اللغة والتنفيذ.
لاحظ أن الدليل الحالي يجب ألا يحتوي على أي مسافات.
git clone https://github.com/tokiwa-software/fuzion
بالنسبة للأنظمة المستندة إلى دبيان ، يجب على هذا الأمر تثبيت جميع المتطلبات:
sudo apt-get install make clang libgc1 libgc-dev openjdk-21-jdk
يجب أن يقوم هذا الأمر بتثبيت جميع المتطلبات:
brew install bdw-gc gnu-sed make temurin llvmبالإضافة إلى ذلك ، قد تحتاج إلى تحديث متغير بيئة المسار على سبيل المثال:
export PATH:"/usr/local/opt/gnu-sed/libexec/gnubin:/usr/local/opt/gnu-make/libexec/gnubin:$PATH"
لاحظ أن البناء من PowerShell/CMD لا يعمل بعد.
تأكد من وجود Java/Javac و Clang في مسار $ الخاص بك.
cd fuzion
make
يجب أن يكون لديك مجلد يسمى Build الآن.
cd build
export PATH=$PWD/bin:$PATH
cd tests/rosettacode_factors_of_an_integer
fz factors
لتجميع نفس المثال (يتطلب برنامج التحويل البرمجي Clang C):
fz -c factors
./factors
استمتع!