# An Introduction to Dragon/Printable version

The current, editable version of this book is available in Wikibooks, the open-content textbooks collection, at
https://en.wikibooks.org/wiki/An_Introduction_to_Dragon

# Lessons/Introduction
## Introduction

Welcome to the Dragon programming language!
In this chapter we are going to discuss the goals behind the language design and implementation.

# Lessons/History
## History

In Oct. 2016 I started the design and the implementation of the Dragon programming language. After 15 months of development, in Jan 2018 the language Interpreter and environment were ready for use!
The first version of the language Dragon 1.0 was released on January 4th, 2018.

# Lessons/Features
## Features

The Dragon language comes with the following features:
* Interpreted
* Declarative programming on top of object-oriented programming
* No explicit end for statements (No ; or ENTER is required)
* Portable (Windows, Linux, Mac OS X, Android, etc.)
* Comments (one line, inline, & multi-line)
* Dynamic typing
* Weakly typed
* Garbage collector - automatic memory management (escape analysis and reference counting)
* Structure-oriented programming
* Rich control structures & operators
* Procedures/functions
* No main function
* Call function before the definition
* Recursion
* Multi-line literals
* Reflection and metaprogramming
* Clear program structure (statements, then functions)
* Exception handling
* I/O commands
* Math functions
* String functions
* Standard functions
* File processing functions
* Database support
* Create GUI applications for desktop

# Lessons/Variables
## Variables

To create a new variable, you just need to determine the variable name & value. The value will determine the variable type and you can change the value to switch between the types using the same variable name.
Syntax:
.. tip::
The operator '=' is used here as an assignment operator and the same operator can be used in conditions, but for testing equality of expressions.
.. note::
The variable will contain the real value (not a reference). This means that once you change the variable value, the old value will be removed from memory (even if the variable contains a list or object).

## Dynamic Typing

Dragon uses dynamic typing:

## Deep Copy

We can use the assignment operator '=' to copy variables. We can do that to copy values like strings & numbers, and even complete lists & objects! The assignment operator will do a complete duplication for us. This operation is called a deep copy.

## Weakly Typed

Dragon is a weakly typed language. This means that the language can automatically convert between data types (like string & numbers) when that conversion makes sense.

# Lessons/Operators
## Operators

In this chapter we will introduce the operators provided by the Dragon programming language.

## Arithmetic Operators

The next table presents all of the arithmetic operators provided by the Dragon language. Assume variable x = 50 and variable y = 10, then:

## Relational Operators

The next table presents all of the relational operators provided by the Dragon language. Assume variable x = 50 and variable y = 10, then:

## Logical Operators

The next table presents all of the logical operators provided by the Dragon language. Assume variable x = true and variable y = false, then:

## Bitwise Operators

The next table presents all of the bitwise operators provided by the Dragon language. Assume variable x = 8 and variable y = 2, then:

## Assignment Operators

The next table presents all of the assignment operators provided by the Dragon language.
Assume variable x = 8, then:

## Operator Precedence

The next table presents operators from highest precedence (evaluated first) to lowest precedence.
Example:

# Lessons/Control Structures
## Control Structures

In this chapter we are going to learn about the control structures provided by the Dragon programming language.

## Branching

* If Statement
Syntax:
Example:

## Looping

* While Loop
Syntax:
* For Loop
Syntax:
Example:
* Foreach Loop
Syntax:
Example:

## Do While Loop

Syntax:
Example:

# Lessons/Getting Input
## Getting Input

We can get input from the keyboard using the readln function.

## readln function

Syntax:
Example:
Output:

# Lessons/Functions
## Functions

In this chapter we are going to learn about the next topics :-
* Define functions
* Call functions
* Declare parameters
* Send parameters
* Variables Scope
* Return Value

## Define Functions

To define a new function:
Syntax:
Example:

## Call Functions

Tip: We can call the function before the function definition.
Example:
Example:

## Declare parameters

To declare the function parameters, write them in parentheses.
Example:

## Send Parameters

To send parameters to function, type the parameters inside after the function name
Syntax:
Example:

## Variables Scope

The Dragon programming language uses lexical scoping to determine the scope of a variable.
Variables defined inside functions (including function parameters) are local variables. Variables defined outside functions (before any function) are global variables.
Inside any function we can access the variables defined inside this function beside the global variables.
Example:

## Return Value

The function can return a value using the return command.
Syntax:
Example: