이 언어는 진행 중입니다.
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
재미있게 보내세요!