পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Wednesday, February 1, 2017

Euphoria - Functions

Euphoria functions are just like procedures, but they return a value, and can be used in an expression. This chapter explains how to write your own functions in Euphoria.

Function Definition

Before we use a function we need to define it. The most common way to define a function in Euphoria is by using the function keyword, followed by a unique function name, a list of parameters (that might be empty), and a statement block which ends with end function statement. The basic syntax is shown here −
function functionname(parameter-list)

   statements
   ..........
   return [Euphoria Object]

end function

Example

A simple function called sayHello that takes no parameters is defined here −
function sayHello()
   puts(1, "Hello there")
   return 1
end function

Calling a Function

To invoke a function somewhere later in the script, you would simple need to write the name of that function as follows −
#!/home/euphoria-4.0b2/bin/eui

function sayHello()
   puts(1, "Hello there")
   return 1
end function

-- Call above defined function.
sayHello()
This produces the following result −
Hello there

Function Parameters

Till now we have seen function without a parameters. But there is a facility to pass different parameters while calling a function. These passed parameters can be captured inside the function and any manipulation can be done over those parameters.
A function can take multiple parameters separated by comma.

Example

Let us do a bit modification in our sayHello function. This time it takes two parameters −
#!/home/euphoria-4.0b2/bin/eui

function sayHello(sequence name,atom  age)
   printf(1, "%s is %d years old.", {name, age})
   return 1
end function

-- Call above defined function.
sayHello("zara", 8)
This produces the following result −
zara is 8 years old.

The return Statement

A Euphoria function must have return statement before closing statement end function. Any Euphoria object can be returned. You can, in effect, have multiple return values, by returning a sequence of objects. For example
return {x_pos, y_pos}
If you have nothing to return, then simply return 1 or 0. The return value 1 indicates success and 0 indicates failure

No comments:

Post a Comment