Wednesday, February 1, 2017

F# - Overview

F# is a functional programming language. To understand F# constructs, you need to read a couple of lines about the programming paradigm named Functional Programming.
Functional programming treats computer programs as mathematical functions.

F# - Environment Setup

The tools required for F# programming are discussed in this chapter.

Integrated Development Environment(IDE) for F#

Microsoft provides Visual Studio 2013 for F# programming.
The free Visual Studio 2013 Community Edition is available from Microsoft’s official website. Visual Studio 2013 Community and above comes with the Visual F# Tools.

F# - Program Structure

F# is a Functional Programming language.
In F#, functions work like data types. You can declare and use a function in the same way like any other variable.
In general, an F# application does not have any specific entry point. The compiler executes all top-level statements in the file from top to bottom.

F# - Basic Syntax

You have seen the basic structure of an F# program, so it will be easy to understand other basic building blocks of the F# programming language.

F# - Data Types

The data types in F# can be classified as follows −
  • Integral types
  • Floating point types
  • Text types
  • Other types

F# - Variables

A variable is a name given to a storage area that our programs can manipulate. Each variable has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.

F# - Operators

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. F# is rich in built-in operators and provides the following types of operators −
  • Arithmetic Operators
  • Comparison Operators
  • Boolean Operators
  • Bitwise Operators

F# - Decision Making

Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program. It should be along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.

F# - Loops

Programming languages provide various control structures that allow for more complicated execution paths.
A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages −

F# - Functions

In F#, functions work like data types. You can declare and use a function in the same way like any other variable.
Since functions can be used like any other variables, you can −

F# - Strings

In F#, the string type represents immutable text as a sequence of Unicode characters.

String Literals

String literals are delimited by the quotation mark (") character.
Some special characters are there for special uses like newline, tab, etc. They are encoded using backslash (\) character. The backslash character and the related character make the escape sequence. The following table shows the escape sequence supported by F#.

F# - Options

The option type in F# is used in calculations when there may or may not exist a value for a variable or function. Option types are used for representing optional values in calculations. They can have two possible values − Some(x) or None.

F# - Tuples

A tuple is a comma-separated collection of values. These are used for creating ad hoc data structures, which group together related values.
For example, (“Zara Ali”, “Hyderabad”, 10) is a 3-tuple with two string values and an int value, it has the type (string * string * int).

F# - Records

A record is similar to a tuple, however it contains named fields. For example,
type website =
   { title : string;
      url : string }

Defining Record

F# - Lists

In F#, a list is an ordered, immutable series of elements of the same type. It is to some extent equivalent to a linked list data structure.
The F# module, Microsoft.FSharp.Collections.List, has the common operations on lists. However F# imports this module automatically and makes it accessible to every F# application.

F# - Sequences

Sequences, like lists also represent an ordered collection of values. However, the elements in a sequence or sequence expression are computed when required. They are not computed at once, and for this reason they are used to represent infinite data structures.

F# - Sets

A set in F# is a data structure that acts as a collection of items without preserving the order in which items are inserted. Sets do not allow duplicate entries to be inserted into the collection.

F# - Maps

In F#, a map is a special kind of set that associates the values with key. A map is created in a similar way as sets are created.

Creating Maps

Maps are created by creating an empty map using Map.empty and adding items using the Add function. The following example demonstrates this −

F# - Discriminated Unions

Unions, or discriminated unions allows you to build up complex data structures representing well-defined set of choices. For example, you need to build an implementation of a choice variable, which has two values yes and no. Using the Unions tool, you can design this.

F# - Mutable Data

Variables in F# are immutable, which means once a variable is bound to a value, it can’t be changed. They are actually compiled as static read-only properties.
The following example demonstrates this.

F# - Arrays

Arrays are fixed-size, zero-based, mutable collections of consecutive data elements that are all of the same type.

Creating Arrays

You can create arrays using various syntaxes and ways or by using the functions from the Array module. In this section, we will discuss creating arrays without using the module functions.
There are three syntactical ways of creating arrays without functions −

F# - Mutable Lists

The List<'T> class represents a strongly typed list of objects that can be accessed by index.
It is a mutable counterpart of the List class. It is similar to arrays, as it can be accessed by an index, however, unlike arrays, lists can be resized. Therefore you need not specify a size during declaration.

F# - Mutable Dictionary

The Dictionary<'TKey, 'TValue> class is the mutable analog of the F# map data structure and contains many of the same functions.
Recapitulating from the Map chapter in F#, a map is a special kind of set that associates the values with key.

F# - Basic I/O

Basic Input Output includes −
  • Reading from and writing into console.
  • Reading from and writing into file.

Core.Printf Module

We have used the printf and the printfn functions for writing into the console. In this section, we will look into the details of the Printf module of F#.

F# - Generics

Generics allow you to delay the specification of the data type of programming elements in a class or a method, until it is actually used in the program. In other words, generics allow you to write a class or method that can work with any data type.

F# - Delegates

A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime. F# delegates are similar to pointers to functions, in C or C++.

F# - Enumerations

An enumeration is a set of named integer constants.
In F#, enumerations, also known as enums, are integral types where labels are assigned to a subset of the values. You can use them in place of literals to make code more readable and maintainable.

F# - Pattern Matching

Pattern matching allows you to “compare data with a logical structure or structures, decompose data into constituent parts, or extract information from data in various ways”.
In other terms, it provides a more flexible and powerful way of testing data against a series of conditions and performing some computations based on the condition met.
Conceptually, it is like a series of if… then statements.

F# - Exception Handling

An exception is a problem that arises during the execution of a program. An F# exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero.
Exceptions provide a way to transfer control from one part of a program to another. F# exception handling provides the following constructs −

F# - Classes

Classes are types that represent objects that can have properties, methods, and events. ‘They are used to model actions, processes, and any conceptual entities in applications’.

F# - Structures

A structure in F# is a value type data type. It helps you to make a single variable, hold related data of various data types. The struct keyword is used for creating a structure.

F# - Operator Overloading

You can redefine or overload most of the built-in operators available in F#. Thus a programmer can use operators with user-defined types as well.

F# - Inheritance

One of the most important concepts in object-oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time.

F# - Interfaces

Interfaces provide an abstract way of writing up the implementation details of a class. It is a template that declares the methods the class must implement and expose publicly.

F# - Events

Events allow classes to send and receive messages between one another.
In GUI, events are user actions like key press, clicks, mouse movements, etc., or some occurrence like system generated notifications. Applications need to respond to events when they occur. For example, interrupts. Events are used for inter-process communication.

F# - Modules

As per MSDN library, an F# module is a grouping of F# code constructs, such as types, values, function values, and code in do bindings. It is implemented as a common language runtime (CLR) class that has only static members.

F# - Namespaces

A namespace is designed for providing a way to keep one set of names separate from another. The class names declared in one namespace will not conflict with the same class names declared in another.
As per the MSDN library, a namespace lets you organize code into areas of related functionality by enabling you to attach a name to a grouping of program elements.

F# - Quick Guide

F# - Overview

F# is a functional programming language. To understand F# constructs, you need to read a couple of lines about the programming paradigm named Functional Programming.
Functional programming treats computer programs as mathematical functions. In functional programming, the focus would be on constants and functions, instead of variables and states.

F# - Useful Resources

The following resources contain additional information on F#. Please use them to get more in-depth knowledge on this topic.

Discuss F#

F# helps you in the daily development of the mainstream commercial business software. This tutorial provides a brief knowledge about F# and its features, and also provides the various structures and syntaxes of its methods and functions.

Fortran - Overview

Fortran, as derived from Formula Translating System, is a general-purpose, imperative programming language. It is used for numeric and scientific computing.
Fortran was originally developed by IBM in the 1950s for scientific and engineering applications. Fortran ruled this programming area for a long time and became very popular for high performance computing, because.

Fortran - Environment Setup

Try it Option Online

We have set up the Fortran Programming environment online, so that you can compile and execute all the available examples online. It gives you confidence in what you are reading and enables you to verify the programs with different options. Feel free to modify any example and execute it online.

Fortran - Basic Syntax

A Fortran program is made of a collection of program units like a main program, modules, and external subprograms or procedures.
Each program contains one main program and may or may not contain other program units. The syntax of the main program is as follows:

Fortran - Data Types

Fortran provides five intrinsic data types, however, you can derive your own data types as well. The five intrinsic types are:
  • Integer type
  • Real type
  • Complex type
  • Logical type
  • Character type

Fortran - Variables

A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable should have a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.
The name of a variable can be composed of letters, digits, and the underscore character. A name in Fortran must follow the following rules:

Fortran - Constants

The constants refer to the fixed values that the program cannot alter during its execution. These fixed values are also called literals.
Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, a complex constant, or a string literal. There are only two logical constants : .true. and .false.
The constants are treated just like regular variables, except that their values cannot be modified after their definition.

Fortran - Operators

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. Fortran provides the following types of operators:
  • Arithmetic Operators
  • Relational Operators
  • Logical Operators

Fortran - Decisions

Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed, if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.

Fortran - Loops

There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially : The first statement in a function is executed first, followed by the second, and so on.

Fortran - Numbers

Numbers in Fortran are represented by three intrinsic data types:
  • Integer type
  • Real type
  • Complex type

Fortran - Characters

The Fortran language can treat characters as single character or contiguous strings.
Characters could be any symbol taken from the basic character set, i.e., from the letters, the decimal digits, the underscore, and 21 special characters.
A character constant is a fixed valued character string.

Fortran - Strings

The Fortran language can treat characters as single character or contiguous strings.
A character string may be only one character in length, or it could even be of zero length. In Fortran, character constants are given between a pair of double or single quotes.

Fortran - Arrays

Arrays can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.
All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.

Fortran - Dynamic Arrays

A dynamic array is an array, the size of which is not known at compile time, but will be known at execution time.
Dynamic arrays are declared with the attribute allocatable.
For example,
real, dimension (:,:), allocatable :: darray

Fortran - Derived Data Types

Fortran allows you to define derived data types. A derived data type is also called a structure, and it can consist of data objects of different types.
Derived data types are used to represent a record. E.g. you want to keep track of your books in a library, you might want to track the following attributes about each book:

Fortran - Pointers

In most programming languages, a pointer variable stores the memory address of an object. However, in Fortran, a pointer is a data object that has more functionalities than just storing the memory address. It contains more information about a particular object, like type, rank, extents, and memory address.
A pointer is associated with a target by allocation or pointer assignment.

Fortran - Basic Input Output

We have so far seen that we can read data from keyboard using the read * statement, and display output to the screen using the print* statement, respectively. This form of input-output is free format I/O, and it is called list-directed input-output.

Fortran - File Input Output

Fortran allows you to read data from, and write data into files.
In the last chapter, you have seen how to read data from, and write data to the terminal. In this chapter you will study file input and output functionalities provided by Fortran.
You can read and write to one or more files. The OPEN, WRITE, READ and CLOSE statements allow you to achieve this.

Fortran - Procedures

A procedure is a group of statements that perform a well-defined task and can be invoked from your program. Information (or data) is passed to the calling program, to the procedure as arguments.
There are two types of procedures:
  • Functions
  • Subroutines

Fortran - Modules

A module is like a package where you can keep your functions and subroutines, in case you are writing a very big program, or your functions or subroutines can be used in more than one program.
Modules provide you a way of splitting your programs between multiple files.

Fortran - Intrinsic Functions

Intrinsic functions are some common and important functions that are provided as a part of the Fortran language. We have already discussed some of these functions in the Arrays, Characters and String chapters.
Intrinsic functions can be categorised as:

Fortran - Numeric Precision

We have already discussed that, in older versions of Fortran, there were two real types: the default real type and double precision type.
However, Fortran 90/95 provides more control over the precision of real and integer data types through the kind specifie.

Fortran - Program Libraries

There are various Fortran tools and libraries. Some are free and some are paid services.
Following are some free libraries:

Fortran - Programming Style

Programming style is all about following some rules while developing programs. These good practices impart values like readability, and unambiguity into your program.
A good program should have the following characteristics:
  • Readability
  • Proper logical structure
  • Self-explanatory notes and comments

Fortran - Debugging Program

A debugger tool is used to search for errors in the programs.
A debugger program steps through the code and allows you to examine the values in the variables and other data objects during execution of the program.
It loads the source code and you are supposed to run the program within the debugger. Debuggers debug a program by:

Fortran - Quick Guide

Fortran - Overview

Fortran, as derived from Formula Translating System, is a general-purpose, imperative programming language. It is used for numeric and scientific computing.
Fortran was originally developed by IBM in the 1950s for scientific and engineering applications. Fortran ruled this programming area for a long time and became very popular for high performance computing, because.

Fortran - Useful Resources

The following resources contain additional information on Fortran. Please use them to get more in-depth knowledge on this topic.

Discuss Fortran

Fortran was originally developed by a team at IBM in 1957 for scientific calculations. Later developments made it into a high level programming language. In this tutorial, we will learn the basic concepts of Fortran and its programming code.


Euphoria - Overview

Euphoria stands for End-User Programming with Hierarchical Objects for Robust Interpreted Applications. Euphoria's first incarnation was created by Robert Craig on an Atari Mega-ST and it was first released in 1993. It is now maintained by Rapid Deployment Software.

Euphoria - Environment

This chapter describes about the installation of Euphoria on various platforms. You can follow the steps to install Euphoria on Linux, FreeBSD, and 32-bit Windows. So you can choose the steps based on your working environment.

Euphoria - Basic Syntax

The Euphoria language has many similarities to Perl, C, and Java. However, there are some definite differences between the languages. This chapter is designed to quickly get you up to speed on the syntax that is expected in Euphoria.

Euphoria - Variables

Variables are nothing but reserved memory locations to store values. This means when you create a variable, you reserve some space in memory.
Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals, or characters in these variables. Euphoria data types are explained in different chapter.

Euphoria - Constants

Constants are also variables that are assigned an initial value that can never change in the program’s life. Euphoria allows to define constants using constant keyword as follows −
constant MAX = 100
constant Upper = MAX - 10, Lower = 5
constant name_list = {"Fred", "George", "Larry"}

Euphoria - Data Types

The data stored in memory can be of many types. For example, a person's age is stored as a numeric value and his or her address is stored as alphanumeric characters.
Euphoria has some standard types that are used to define the operations possible on them and the storage method for each of them.

Euphoria - Operators

Euphoria provides a rich set of operators to manipulate variables. We can divide all the Euphoria operators into the following groups −
  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Assignment Operators
  • Misc Operators

Euphoria - Branching

Branching is the most important aspect of any programming language. While writing your program, you may encounter a situation when you have to take a decision or you have to select one option out of the given many options.

Euphoria - Loop Types

Looping is yet another most important aspect of any programming language. While writing your program, you may encounter a situation when you have to execute same statement many times and sometime may be infinite number of times.

Euphoria - Flow Control

Program execution flow refers to the order in which program statements get executed. By default the statements get executed one after another.
However; many times the order of execution needs to be altered from the default order, to get the task done.
Euphoria has a number of flow control statements that you can use to arrange the execution order of statements.

Euphoria - Short Circuit Evaluation

When a condition is tested by if, elsif, until, or while using and or or operators, a short-circuit evaluation is used. For example −
if a < 0 and b > 0 then
   -- block of code
end if

Euphoria - Sequences

A sequence is represented by a list of objects in brace brackets { }, separated by commas. A sequence can contain both atoms and other sequences. For example −
{2, 3, 5, 7, 11, 13, 17, 19}
{1, 2, {3, 3, 3}, 4, {5, {6}}}
{{"Zara", "Ayan"}, 52389, 97.25}
{} -- the 0-element sequence

Euphoria - Date & Time

Euphoria has a library routine that returns the date and time to your program.

The date() Method

The date() method returns a sequence value composed of eight atom elements. The following example explains it in detail −
#!/home/euphoria-4.0b2/bin/eui

Euphoria - Procedures

A procedure is a group of reusable code which can be called from anywhere in your program. This eliminates the need of writing same code again and again. This helps programmers to write modular code.
Like any other advance programming language, Euphoria also supports all the features necessary to write modular code using procedures.

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.

Euphoria - Files I/O

Using Euphoria programming language, you can write programs that read and change file data on your floppy drive or hard drive, or create new files as a form of output. You can even access devices on your computer such as the printer and modem.

Euphoria - Quick Guide

Euphoria - Overview

Euphoria stands for End-User Programming with Hierarchical Objects for Robust Interpreted Applications. Euphoria's first incarnation was created by Robert Craig on an Atari Mega-ST and it was first released in 1993. It is now maintained by Rapid Deployment Software.

Euphoria - Library Routines

A large number of library routines are provided. Some are built right into the interpreter, ex.exe, exw.exe or exu. Others are written in Euphoria and you must include one of the .e files in euphoria\include directory to use them.

Euphoria - Useful Resources

The following resources contain additional information on Euphoria. Please use them to get more in-depth knowledge on this topic.

Discuss Euphoria

This tutorial gives you basic understanding of Euphoria programming language. Euphoria is simple, flexible, easy to learn, and interpreted high-level programming language for DOS, Windows, Linux, FreeBSD, and more. This tutorial describes everything a programmer needs to know such as its environment, data types, syntax and operators, file handling, and controlling the flow of program.