Open Euphoria

Implementation of programming language Euphoria

Open Source edition of Euphoria

Examples:

Hello, World!:

Example for versions Euphoria v3.1.1, Euphoria v4

The routine puts() writes the second argument (a string) to the device identified by the first argument. There are three predefined devices: 0 is STDIN, 1 is STDOUT, and 2 is STDERR.

puts(1, "Hello, World!\n")

Factorial:

Example for versions Euphoria v3.1.1, Euphoria v4

This example uses recursive factorial definition.

function factorial(integer n)
  atom result

  if n <= 1 then
    result =  1
  else
    result = n * factorial(n-1)
  end if

  return result
end function

for i = 0 to 16 do
 printf(1, "%d! = %d\n", {i, factorial(i)})
end for

Factorial:

Example for versions Euphoria v3.1.1, Euphoria v4

This example uses iterative factorial definition.

function factorial(integer n)
  atom result = 1

  if n < 1 then
    return 1
  end if

  for i = 2 to n do
    result *= i
  end for

  return result
end function

for i = 0 to 16 do
 printf(1, "%d! = %d\n", {i, factorial(i)})
end for

Fibonacci numbers:

Example for versions Euphoria v3.1.1, Euphoria v4

This example uses recursive definition of Fibonacci numbers.

function fibonacci(integer n)
  atom result = 1

  if n <= 2 then
    result =  1
  else
    result = fibonacci(n-1) + fibonacci(n-2)
  end if

  return result
end function

for i = 1 to 16 do
  printf(1, "%d, ", fibonacci(i))
end for
puts(1, "...\n")

Fibonacci numbers:

Example for versions Euphoria v3.1.1, Euphoria v4

This example uses iterative definition of Fibonacci numbers.

function fibonacci(integer n)
  sequence result

  result = repeat(1, n)
  for i = 3 to n do
  	result[i] = result[i-1] + result[i-2]
  end for
  return result
end function

sequence ans = fibonacci(16)
for i = 1 to length(ans) do
  printf(1, "%d, ", ans[i])
end for
puts(1, "...\n")