Website | Download (Source included in download)
Character hello world
puts(1,"Hello world!\n")
{} = wait_key()
GUI hello world
{} = message_box("world!","Hello",MB_OK)
A simple sorting routine
function merge_sort(sequence x)
-- put x into ascending order using a recursive merge sort
integer midpoint
sequence merged, first_half, second_half
if length(x)<=1 then
return x -- trivial case
end if
midpoint = floor(length(x)/2)
first_half = merge_sort(x[1..midpoint])
second_half = merge_sort(x[midpoint+1..$])
-- merge the two sorted halves into one
merged = {}
while length(first_half)>0
and length(second_half)>0 do
if first_half[1]<=second_half[1] then
merged = append(merged, first_half[1])
first_half = first_half[2..$]
else
merged = append(merged, second_half[1])
second_half = second_half[2..$]
end if
end while
-- result is the merged data plus any leftovers
return merged & first_half & second_half
end function
sequence list = {9, 10, 3, 1, 4, 5, 8, 7, 6, 2}
? merge_sort(list)
https://github.com/petelomax/Phix
Phix is a self-hosted hybrid interpreter/compiler, developed by Pete Lomax. It is very easy to use, and similar to Euphoria.
Last modified 02 October 2024