-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuphoria.html
More file actions
4786 lines (3622 loc) · 204 KB
/
Copy patheuphoria.html
File metadata and controls
4786 lines (3622 loc) · 204 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html><html><body><title>Euphoria Programming Language Tutorial</title>
<h1>Euphoria Programming Language Tutorial</h1>
<p>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.</p>
<h1>Audience</h1>
<p>This tutorial is designed for the aspiring students who are keen to learn and understand Euphoria in detail. This tutorial would be of great help for the IT professionals working as programmers. The enthusiastic readers can access this tutorial as a source of additional reading.</p>
<h1>Prerequisites</h1>
<p>Before proceeding with this tutorial, you need to have a basic knowledge of working on Windows or Linux. You need to be familiar with any programming language such as C, C++. You need to have sound understanding of operating system, memory allocation and de-allocation, and basics of efficient programming and debugging.</p>
<p>© Copyright 2017. All Rights Reserved.</p>
<title>Euphoria Overview</title>
<h1>Euphoria - Overview</h1>
<p>Euphoria stands for <b>E</b>nd-<b>U</b>ser <b>P</b>rogramming with <b>H</b>ierarchical <b>O</b>bjects for <b>R</b>obust <b>I</b>nterpreted <b>A</b>pplications. 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.</p>
<p>It is a free, simple, flexible, easy to learn, and interpreted but extremely fast 32-bit high-level programming language for DOS, Windows, Linux, FreeBSD and more.</p>
<p>Euphoria is being used to develop Windows GUI programs, high-speed DOS games, and Linux/FreeBSD X Windows programs. Euphoria can also be used for CGI (Webbased) programming.</p>
<h2>Euphoria Features</h2>
<p>Here is the list of major features of Euphoria −</p>
<p>It is a simple, flexible, powerful language definition that is easy to learn and use.</p>
<p>It supports dynamic storage allocation which means variables grow or shrink without the programmer having to worry about allocating and freeing the memory. It takes care of garbage collection automatically.</p>
<p>It is extremely faster than conventional interpreters such as Perl and Python.</p>
<p>Euphoria programs run under Linux, FreeBSD, 32-bit Windows, and any DOS environment.</p>
<p>Euphoria programs are not subject to any 640K memory limitations.</p>
<p>It provides an optimizing Euphoria-To-C translator which you can use to translate your Euphoria program into C and then compile it with a C compiler to get an executable (.exe) file. This can boost your program speed by 2 to 5 times.</p>
<p>Underlying hardware are completely hidden which means programs are not aware of word-lengths, underlying bit-level representation of values, byte-order etc.</p>
<p>Euphoria installation comes along with a full-screen source debugger, an execution profiler, and a full-screen multi-file editor.</p>
<p>It supports run-time error-handling, subscript, and type checking.</p>
<p>It is an open source language and comes completely free of cost.</p>
<h2>Platform Requirements</h2>
<p>Euphoria is available on Windows, Linux, FreeBSD, and OSX. Here is the bare minimum version required with the following platforms −</p>
<p><b>WIN32 version</b> − You need Windows 95 or any later version of Windows. It runs fine on XP and Vista.</p>
<p><b>Linux version</b> − You need any reasonably up-to-date Linux distribution, that has libc6 or later. For example, Red Hat 5.2 or later works fine.</p>
<p><b>FreeBSD version</b> − You need any reasonably up-to-date FreeBSD distribution.</p>
<p><b>Mac OS X version</b> − You need any reasonably up-to-date Intel based Mac.</p>
<h2>Euphoria Limitations</h2>
<p>Here are some prominent limitations of Euphoria −</p>
<p>Even though Euphoria is simple, fast, and flexible enough for the programmers; it does not provide call support for many important functionalities. For example, network programming.</p>
<p>Euphoria was invented in 1993, and still you would not find any book written on this language. There is also not much documentation available for the language.</p>
<p>But these days, the language is getting popular very fast and you can hope to have nice utilities and books available for the language very soon.</p>
<h2>Euphoria Licensing</h2>
<p>This product is free and open source, and has benefited from the contributions of many people. You have complete royalty-free rights to distribute any Euphoria programs that you develop.</p>
<p>Icon files, such as euphoria.ico and binaries available in euphoria\bin, may be distributed with or without your changes.</p>
<p>You can <b>shroud</b> or <b>bind</b> your program and distribute the resulting files royalty-free. Some additional 3<sup>rd</sup> party legal restrictions might apply when you use the Euphoria- To-C translator.</p>
<p>© Copyright 2017. All Rights Reserved.</p>
<title>Euphoria Environment</title>
<h1>Euphoria - Environment</h1>
<p>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.</p>
<h2>Linux, Free BSD Installation</h2>
<p>Official website provides <b>.tar.gz</b> file to install Euphoria on your Linux or BSD OS. You can download your latest version of Euphoria from its official website − <a rel="nofollow" href="http://www.rapideuphoria.com/" target="_blank">Download Euphoria</a>.</p>
<p>Once you have .tar.gz file, here are three simple steps to be performed to install Euphoria on your Linux or Free BSD machine −</p>
<p><b>Step 1</b> − Installing Files</p>
<p>Untar the downloaded file <b>euphoria-4.0b2.tar.gz</b> in a directory where you want to install Euphoria. If you want to install it in /home directory as follows, then −</p>
<p>This creates a directory hierarchy inside <b>/home/euphoria-4.0b2</b> directory as follows −</p>
<p><b>NOTE</b> − File name euphoria-4.0b2.tar.gz depends on latest version available. We are using 4.0b2 version of the language for this tutorial.</p>
<p><b>Step 2</b> − Setting Up the Path</p>
<p>After installing Euphoria, you need to set proper paths so that your shell can find required Euphoria binaries and utilities. Before proceeding, there are following three important environment variables you need to set up −</p>
<p>Set PATH environment variable to point /home/euphoria-4.0b2/bin directory.</p>
<p>Set EUDIR environment variable to point to /home/euphoria-4.0b2.</p>
<p>Set EUINC environment variable to point to /home/euphoria-4.0b2/include.</p>
<p>These variables can be set as follows −</p>
<p><b>NOTE</b> − The above commands used to set environment variables may differ depending on your Shell. We used <i>bash</i> shell for executing these commands to set the variables.</p>
<p><b>Step 3</b> − Confirmation Installation</p>
<p>Confirm if you installed Euphoria successfully or not.</p>
<p>Execute the following command −</p>
<p>If you get following result, then it means you have installed Euphoria successfully; otherwise you have to go back and check all the steps again.</p>
<p>That is it, Euphoria Programming Environment is ready on your UNIX machine, and you can start writing complex programs in easy steps.</p>
<h2>WIN32, and DOS Installation</h2>
<p>Official website provides <b>.exe</b> file to install Euphoria on your WIN32 or DOS OS. You can download your latest version of Euphoria from its official website − <a href="http://www.rapideuphoria.com/" rel="nofollow" target="_blank">Download Euphoria</a>.</p>
<p>Once you have .exe file, here are three simple steps to follow for installing Euphoria Programming language on your WIN32 or DOS machine −</p>
<p><b>Step 1</b> − Installing Files</p>
<p>Double click on the downloaded <b>.exe</b> setup program to install all the files. We downloaded euphoria-40b2.exe file for installation.</p>
<p>The filename euphoria-40b2.exe depends on latest version available. We use version 4 beta 2 of the language.</p>
<p>By default Euphoria would be installed in C:\<i>euphoria-40b2</i> directory but you can also select a desired location.</p>
<p><b>Step 2</b> − Rebooting the Machine</p>
<p>Re-boot your machine to complete the installation.</p>
<p><b>Step 3</b> − Confirmation Installation</p>
<p>Confirm if you installed Euphoria successfully or not.</p>
<p>Execute the following command −</p>
<p>If you get following result, then it means you have installed Euphoria successfully; otherwise you have to go back and check all the steps again.</p>
<p>That is it, Euphoria Programming Environment is ready on your WIN32 machine, and you can start writing complex programs in easy steps.</p>
<h2>Euphoria Interpreters</h2>
<p>Depending on the platform you are using, Euphoria has multiple interpreters −</p>
<p>The main interpreter is <b>eui</b>.</p>
<p>On windows platforms, you have two choices. If you run <b>eui</b> then a console window is created. If you run <b>euiw</b> then no console is created, making it suitable for GUI applications.</p>
<p>Euphoria does not care about your choice of file extensions. By convention however; the console-based applications come with <b>.ex</b> extension.</p>
<p>GUI-based applications have <b>.exw</b> extension and the include files have <b>.e</b> extension.</p>
<p>© Copyright 2017. All Rights Reserved.</p>
<pre class="result notranslate">
$cp euphoria-4.0b2.tar.gz /home
$cd /home
$gunzip euphoria-4.0b2.tar.gz
$tar -xvf euphoria-4.0b2.tar
</pre>
<p>This creates a directory hierarchy inside <b>/home/euphoria-4.0b2</b> directory as follows −</p>
<pre class="result notranslate">
$ls -l
-rw-r--r-- 1 1001 1001 2485 Aug 17 06:15 Jamfile
-rw-r--r-- 1 1001 1001 5172 Aug 20 12:37 Jamrules
-rw-r--r-- 1 1001 1001 1185 Aug 13 06:21 License.txt
drwxr-xr-x 2 1001 1001 4096 Aug 31 10:07 bin
drwxr-xr-x 7 1001 1001 4096 Aug 31 10:07 demo
-rw-r--r-- 1 1001 1001 366 Mar 18 09:02 file_id.diz
drwxr-xr-x 4 1001 1001 4096 Aug 31 10:07 include
-rw-r--r-- 1 1001 1001 1161 Mar 18 09:02 installu.doc
drwxr-xr-x 4 1001 1001 4096 Aug 31 10:07 source
drwxr-xr-x 19 1001 1001 4096 Sep 7 12:09 tests
drwxr-xr-x 2 1001 1001 4096 Aug 31 10:07 tutorial
</pre>
<p><b>NOTE</b> − File name euphoria-4.0b2.tar.gz depends on latest version available. We are using 4.0b2 version of the language for this tutorial.</p>
<p><b>Step 2</b> − Setting Up the Path</p>
<p>After installing Euphoria, you need to set proper paths so that your shell can find required Euphoria binaries and utilities. Before proceeding, there are following three important environment variables you need to set up −</p>
<ul class="list">
<li><p>Set PATH environment variable to point /home/euphoria-4.0b2/bin directory.</p></li>
<li><p>Set EUDIR environment variable to point to /home/euphoria-4.0b2.</p></li>
<li><p>Set EUINC environment variable to point to /home/euphoria-4.0b2/include.</p></li>
</ul>
<p>These variables can be set as follows −</p>
<pre class="result notranslate">
$export PATH=$PATH:/home/euphoria-4.0b2/bin
$export EUDIR=/home/euphoria-4.0b2
$export EUINC=/home/euphoria-4.0b2/include
</pre>
<p><b>NOTE</b> − The above commands used to set environment variables may differ depending on your Shell. We used <i>bash</i> shell for executing these commands to set the variables.</p>
<p><b>Step 3</b> − Confirmation Installation</p>
<p>Confirm if you installed Euphoria successfully or not.</p>
<p>Execute the following command −</p>
<pre class="result notranslate">
$eui -version
</pre>
<p>If you get following result, then it means you have installed Euphoria successfully; otherwise you have to go back and check all the steps again.</p>
<pre class="result notranslate">
$eui -version
Euphoria Interpreter 4.0.0 beta 2 (r2670) for Linux
Using System Memory
$
</pre>
<p>That is it, Euphoria Programming Environment is ready on your UNIX machine, and you can start writing complex programs in easy steps.</p>
<h2>WIN32, and DOS Installation</h2>
<p>Official website provides <b>.exe</b> file to install Euphoria on your WIN32 or DOS OS. You can download your latest version of Euphoria from its official website − <a href="http://www.rapideuphoria.com/" rel="nofollow" target="_blank">Download Euphoria</a>.</p>
<p>Once you have .exe file, here are three simple steps to follow for installing Euphoria Programming language on your WIN32 or DOS machine −</p>
<p><b>Step 1</b> − Installing Files</p>
<p>Double click on the downloaded <b>.exe</b> setup program to install all the files. We downloaded euphoria-40b2.exe file for installation.</p>
<p>The filename euphoria-40b2.exe depends on latest version available. We use version 4 beta 2 of the language.</p>
<p>By default Euphoria would be installed in C:\<i>euphoria-40b2</i> directory but you can also select a desired location.</p>
<p><b>Step 2</b> − Rebooting the Machine</p>
<p>Re-boot your machine to complete the installation.</p>
<p><b>Step 3</b> − Confirmation Installation</p>
<p>Confirm if you installed Euphoria successfully or not.</p>
<p>Execute the following command −</p>
<pre class="result notranslate">
c:\>eui -version
</pre>
<p>If you get following result, then it means you have installed Euphoria successfully; otherwise you have to go back and check all the steps again.</p>
<pre class="result notranslate">
c:\>eui -version
Euphoria Interpreter 4.0.0 beta 2 (r2670) for Windows
Using Managed Memory
c:\>
</pre>
<title>Euphoria Basic Syntax</title>
<h1>Euphoria - Basic Syntax</h1>
<p>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.</p>
<p>This tutorial assumes you are working with Linux and all the examples have been written on Linux platform. But it is observed that there is no any prominent difference in program syntax on Linux and WIN32. Hence you can follow the same steps on WIN32.</p>
<h2>First Euphoria Program</h2>
<p>Let us write a simple Euphoria program in a script. Type the following source code in test.ex file and save it.</p>
<p>Let us say, Euphoria interpreter is available in <i>/home/euphoria-4.0b2/bin/</i> directory. Now run this program as follows −</p>
<p>This produces the following result −</p>
<p>This script used a built-in function <b>puts()</b> which takes two arguments. First argument indicates file name or device number, and second argument indicates a string which you want to print. Here 1 indicates STDOUT device.</p>
<h2>Euphoria Identifiers</h2>
<p>A Euphoria identifier is a name used to identify a variable, function, class, module, or other object. An identifier starts with a letter A to Z or a to z and then followed by letters, digits, or underscores.</p>
<p>Euphoria does not allow punctuation characters such as @, $, and % within identifiers.</p>
<p>Euphoria is a case sensitive programming language. Thus <b>Manpower</b> and <b>manpower</b> are two different identifiers in Euphoria. For example, the valid identifiers are −</p>
<h2>Reserved Words</h2>
<p>The following list shows the reserved words in Euphoria. These reserved words may not be used as constant or variable or any other identifier names. Euphoria keywords contain lowercase letters only.</p>
<h2>Expressions</h2>
<p>Euphoria lets you calculate results by forming expressions. However, in Euphoria you can perform calculations on entire sequences of data with one expression.</p>
<p>You can handle a sequence much as you would handle a single number. It can be copied, passed to a subroutine, or calculated upon as a unit. For example −</p>
<p>This is an expression that adds the sequence {1, 2, 3} and the atom 5 to get the resulting sequence {6, 7, 8}. You would learn sequences in subsequent chapters.</p>
<h2>Blocks of code</h2>
<p>One of the first caveats programmers encounter when learning Euphoria is the fact that there are no braces to indicate blocks of code for procedure and function definitions or flow control. Blocks of code are denoted by associated keywords.</p>
<p>The following example shows <b>if...then...end if</b> block −</p>
<h2>Multi-Line Statements</h2>
<p>Statements in Euphoria typically end with a new line. Euphoria does however, allow to write a single statement in multiple lines. For example −</p>
<h2>Escape Characters</h2>
<p>Escape characters may be entered using a back-slash. For example −</p>
<p>The following table is a list of escape or non-printable characters that can be represented with backslash notation.</p>
<h2>Comments in Euphoria</h2>
<p>Any comments are ignored by the compiler and have no effect on execution speed. It is advisable to use more comments in your program to make it more readable.</p>
<p>There are three forms of comment text −</p>
<p>Comments start by two dashes and extend to the end of the current line.</p>
<p>The multi-line format comment is kept inside /*...*/, even if that occurs on a different line.</p>
<p>You can use a special comment beginning with the two character sequence “#!” only on the first line of the program.</p>
<h3>Examples</h3>
<p>This produces the following result −</p>
<p><b>Note</b> − You can use a special comment beginning with “#!”. This informs the Linux shell that your file should be executed by the Euphoria interpreter.</p>
<p>© Copyright 2017. All Rights Reserved.</p>
<pre class="prettyprint notranslate">
#!/home/euphoria-4.0b2/bin/eui
puts(1, "Hello, Euphoria!\n")
</pre>
<p>Let us say, Euphoria interpreter is available in <i>/home/euphoria-4.0b2/bin/</i> directory. Now run this program as follows −</p>
<pre class="prettyprint notranslate">
$ chmod +x test.ex # This is to make file executable
$ ./test.ex
</pre>
<p>This produces the following result −</p>
<pre class="result notranslate">
Hello, Euphoria!
</pre>
<p>This script used a built-in function <b>puts()</b> which takes two arguments. First argument indicates file name or device number, and second argument indicates a string which you want to print. Here 1 indicates STDOUT device.</p>
<h2>Euphoria Identifiers</h2>
<p>A Euphoria identifier is a name used to identify a variable, function, class, module, or other object. An identifier starts with a letter A to Z or a to z and then followed by letters, digits, or underscores.</p>
<p>Euphoria does not allow punctuation characters such as @, $, and % within identifiers.</p>
<p>Euphoria is a case sensitive programming language. Thus <b>Manpower</b> and <b>manpower</b> are two different identifiers in Euphoria. For example, the valid identifiers are −</p>
<ul class="list">
<li>n</li>
<li>color26</li>
<li>ShellSort</li>
<li>quick_sort</li>
<li>a_very_long_indentifier</li>
</ul>
<h2>Reserved Words</h2>
<p>The following list shows the reserved words in Euphoria. These reserved words may not be used as constant or variable or any other identifier names. Euphoria keywords contain lowercase letters only.</p>
<table class="table table-bordered">
<tr>
<td>and</td>
<td>exit</td>
<td>override</td>
</tr>
<tr>
<td>as</td>
<td>export</td>
<td>procedure</td>
</tr>
<tr>
<td>break</td>
<td>fallthru</td>
<td>public</td>
</tr>
<tr>
<td>by</td>
<td>for</td>
<td>retry</td>
</tr>
<tr>
<td>case</td>
<td>function</td>
<td>return</td>
</tr>
<tr>
<td>constant</td>
<td>global</td>
<td>routine</td>
</tr>
<tr>
<td>continue</td>
<td>goto</td>
<td>switch</td>
</tr>
<tr>
<td>do</td>
<td>if</td>
<td>then</td>
</tr>
<tr>
<td>else</td>
<td>ifdef</td>
<td>to</td>
</tr>
<tr>
<td>elsedef</td>
<td>include</td>
<td>type</td>
</tr>
<tr>
<td>elsif</td>
<td>label</td>
<td>until</td>
</tr>
<tr>
<td>elsifdef</td>
<td>loop</td>
<td>while</td>
</tr>
<tr>
<td>end</td>
<td>namespace</td>
<td>with</td>
</tr>
<tr>
<td>entry</td>
<td>not</td>
<td>without</td>
</tr>
<tr>
<td>enum</td>
<td>or</td>
<td>xor</td>
</tr>
</table>
<h2>Expressions</h2>
<p>Euphoria lets you calculate results by forming expressions. However, in Euphoria you can perform calculations on entire sequences of data with one expression.</p>
<p>You can handle a sequence much as you would handle a single number. It can be copied, passed to a subroutine, or calculated upon as a unit. For example −</p>
<pre class="result notranslate">
{1,2,3} + 5
</pre>
<p>This is an expression that adds the sequence {1, 2, 3} and the atom 5 to get the resulting sequence {6, 7, 8}. You would learn sequences in subsequent chapters.</p>
<h2>Blocks of code</h2>
<p>One of the first caveats programmers encounter when learning Euphoria is the fact that there are no braces to indicate blocks of code for procedure and function definitions or flow control. Blocks of code are denoted by associated keywords.</p>
<p>The following example shows <b>if...then...end if</b> block −</p>
<pre class="prettyprint notranslate">
if condition then
code block comes here
end if
</pre>
<h2>Multi-Line Statements</h2>
<p>Statements in Euphoria typically end with a new line. Euphoria does however, allow to write a single statement in multiple lines. For example −</p>
<pre class="prettyprint notranslate">
total = item_one +
item_two +
item_three
</pre>
<h2>Escape Characters</h2>
<p>Escape characters may be entered using a back-slash. For example −</p>
<p>The following table is a list of escape or non-printable characters that can be represented with backslash notation.</p>
<table style="text-align:center;" class="table table-bordered">
<tr>
<th style="text-align:center;">Backslash notation</th>
<th style="text-align:center;">Description</th>
</tr>
<tr>
<td>\n</td>
<td>Newline</td>
</tr>
<tr>
<td>\r</td>
<td>Carriage return</td>
</tr>
<tr>
<td>\t</td>
<td>Tab</td>
</tr>
<tr>
<td>\\</td>
<td>Backslash</td>
</tr>
<tr>
<td>\"</td>
<td>Double quote</td>
</tr>
<tr>
<td>\'</td>
<td>Single quote</td>
</tr>
</table>
<h2>Comments in Euphoria</h2>
<p>Any comments are ignored by the compiler and have no effect on execution speed. It is advisable to use more comments in your program to make it more readable.</p>
<p>There are three forms of comment text −</p>
<ul class="list">
<li><p>Comments start by two dashes and extend to the end of the current line.</p></li>
<li><p>The multi-line format comment is kept inside /*...*/, even if that occurs on a different line.</p></li>
<li><p>You can use a special comment beginning with the two character sequence “#!” only on the first line of the program.</p></li>
</ul>
<h3>Examples</h3>
<pre class="prettyprint notranslate">
#!/home/euphoria-4.0b2/bin/eui
-- First comment
puts(1, "Hello, Euphoria!\n") -- second comment
/* This is a comment which extends over a number
of text lines and has no impact on the program
*/
</pre>
<p>This produces the following result −</p>
<pre class="result notranslate">
Hello, Euphoria!
</pre>
<title>Euphoria Variables</title>
<h1>Euphoria - Variables</h1>
<p>Variables are nothing but reserved memory locations to store values. This means when you create a variable, you reserve some space in memory.</p>
<p>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.</p>
<p>These memory locations are called variables because their value can be changed during their life time.</p>
<h2>Variable Declaration</h2>
<p>Euphoria variables have to be explicitly declared to reserve memory space. Thus declaration of a variable is mandatory before you assign a value to a variable.</p>
<p>Variable declarations have a type name followed by a list of the variables being declared. For example −</p>
<p>When you declare a variable, you name the variable and you define which sort of values may legally be assigned to the variable during execution of your program.</p>
<p>The simple act of declaring a variable does not assign any value to it. If you attempt to read it before assigning any value to it, Euphoria will issue a run-time error as <i>"variable xyz has never been assigned a value"</i>.</p>
<h2>Assigning Values</h2>
<p>The equal sign (=) is used to assign values to variables. Variable can be assigned in the following manner −</p>
<p>Variable_Name = Variable_Value</p>
<p>For example −</p>
<p>Here 100, 1000.0 and "John" are the values assigned to <i>counter</i>, <i>miles</i> and <i>name</i> variables, respectively. This program produces the following result −</p>
<p>To guard against forgetting to initialize a variable, and also because it may make the code clearer to read, you can combine declaration and assignment −</p>
<p>This is equivalent to the following −</p>
<h2>Identifier Scope</h2>
<p>The scope of an identifier is a description of what code can access it. Code in the same scope of an identifier can access that identifier and code not in the same scope as identifier cannot access it.</p>
<p>The scope of a variable depends upon where and how it is declared.</p>
<p>If it is declared within a <b>for, while, loop</b> or <b>switch</b>, its scope starts at the declaration and ends at the respective <b>end</b> statement.</p>
<p>In an <b>if</b> statement, the scope starts at the declaration and ends either at the next <b>else, elsif</b> or <b>end if</b> statement.</p>
<p>If a variable is declared within a routine, the scope of the variable starts at the declaration and ends at the routine's end statement. This is knows as a private variable.</p>
<p>If a variable is declared outside of a routine, its scope starts at the declaration and ends and the end of the file it is declared in. This is known as a module variable.</p>
<p>The scope of a <b>constant</b> that does not have a scope modifier, starts at the declaration and ends and the end of the file it is declared in.</p>
<p>The scope of a <b>enum</b> that does not have a scope modifier, starts at the declaration and ends and the end of the file it is declared in.</p>
<p>The scope of all <b>procedures, functions</b> and <b>types</b>, which do not have a scope modifier, starts at the beginning of the source file and ends at the end of the source file in which they are declared.</p>
<p>Constants, enums, module variables, procedures, functions and types, which do not have a scope modifier are referred to as <b>locals</b>. However, these identifiers can have a scope modifier preceding their declaration, which causes their scope to extend beyond the file they are declared in.</p>
<p>If the keyword <b>global</b> precedes the declaration, the scope of these identifiers extends to the whole application. They can be accessed by code anywhere in the application files.</p>
<p>If the keyword <b>public</b> precedes the declaration, the scope extends to any file that explicitly includes the file in which the identifier is declared, or to any file that includes a file that in turn <i>public</i> includes the file containing the <i>public</i> declaration.</p>
<p>If the keyword <b>export</b> precedes the declaration, the scope only extends to any file that directly includes the file in which the identifier is declared.</p>
<p>When you <b>include</b> a Euphoria file in another file, only the identifiers declared using a scope modifier are accessible to the file doing the <i>include</i>. The other declarations in the included file are invisible to the file doing the <i>include</i>.</p>
<p>© Copyright 2017. All Rights Reserved.</p>
<pre class="result notranslate">
integer x, y, z
sequence a, b, x
</pre>
<p>When you declare a variable, you name the variable and you define which sort of values may legally be assigned to the variable during execution of your program.</p>
<p>The simple act of declaring a variable does not assign any value to it. If you attempt to read it before assigning any value to it, Euphoria will issue a run-time error as <i>"variable xyz has never been assigned a value"</i>.</p>
<h2>Assigning Values</h2>
<p>The equal sign (=) is used to assign values to variables. Variable can be assigned in the following manner −</p>
<p>Variable_Name = Variable_Value</p>
<p>For example −</p>
<pre class="prettyprint notranslate">
#!/home/euphoria/bin/eui
-- Here is the declaration of the variables.
integer counter
integer miles
sequence name
counter = 100 -- An integer assignment
miles = 1000.0 -- A floating point
name = "John" -- A string ( sequence )
printf(1, "Value of counter %d\n", counter )
printf(1, "Value of miles %f\n", miles )
printf(1, "Value of name %s\n", {name} )
</pre>
<p>Here 100, 1000.0 and "John" are the values assigned to <i>counter</i>, <i>miles</i> and <i>name</i> variables, respectively. This program produces the following result −</p>
<pre class="result notranslate">
Value of counter 100
Value of miles 1000.000000
Value of name John
</pre>
<p>To guard against forgetting to initialize a variable, and also because it may make the code clearer to read, you can combine declaration and assignment −</p>
<pre class="result notranslate">
integer n = 5
</pre>
<p>This is equivalent to the following −</p>
<pre class="result notranslate">
integer n
n = 5
</pre>
<title>Euphoria Constants</title>
<h1>Euphoria - Constants</h1>
<p>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 −</p>
<p>The result of any expression can be assigned to a constant, even one involving calls to previously defined functions, but once the assignment is made, the value of the constant variable is "locked in".</p>
<p>Constants may not be declared inside a subroutine. The scope of a <b>constant</b> that does not have a scope modifier, starts at the declaration and ends and the end of the file it is declared in.</p>
<h3>Examples</h3>
<p>This produces the following error −</p>
<p>If you delete last two lines from the example, then it produces the following result −</p>
<h2>The <i>enums</i></h2>
<p>An enumerated value is a special type of constant where the first value defaults to the number 1 and each item after that is incremented by 1. Enums can only take numeric values.</p>
<p>Enums may not be declared inside a subroutine. The scope of an <b>enum</b> that does not have a scope modifier, starts at the declaration and ends and the end of the file it is declared in.</p>
<h3>Examples</h3>
<p>This will produce following result −</p>
<p>You can change the value of any one item by assigning it a numeric value. Subsequent values are always the previous value plus one, unless they too are assigned a default value.</p>
<p>This produce the following result −</p>
<p>Sequences use integer indices, but with enum you may write code like this −</p>
<p>© Copyright 2017. All Rights Reserved.</p>
<pre class="prettyprint notranslate">
constant MAX = 100
constant Upper = MAX - 10, Lower = 5
constant name_list = {"Fred", "George", "Larry"}
</pre>
<p>The result of any expression can be assigned to a constant, even one involving calls to previously defined functions, but once the assignment is made, the value of the constant variable is "locked in".</p>
<p>Constants may not be declared inside a subroutine. The scope of a <b>constant</b> that does not have a scope modifier, starts at the declaration and ends and the end of the file it is declared in.</p>
<h3>Examples</h3>
<pre class="prettyprint notranslate">
#!/home/euphoria-4.0b2/bin/eui
constant MAX = 100
constant Upper = MAX - 10, Lower = 5
printf(1, "Value of MAX %d\n", MAX )
printf(1, "Value of Upper %d\n", Upper )
printf(1, "Value of Lower %d\n", Lower )
MAX = MAX + 1
printf(1, "Value of MAX %d\n", MAX )
</pre>
<p>This produces the following error −</p>
<pre class="result notranslate">
./test.ex:10
<0110>:: may not change the value of a constant
MAX = MAX + 1
^
Press Enter
</pre>
<p>If you delete last two lines from the example, then it produces the following result −</p>
<pre class="result notranslate">
Value of MAX 100
Value of Upper 90
Value of Lower 5
</pre>
<h2>The <i>enums</i></h2>
<p>An enumerated value is a special type of constant where the first value defaults to the number 1 and each item after that is incremented by 1. Enums can only take numeric values.</p>
<p>Enums may not be declared inside a subroutine. The scope of an <b>enum</b> that does not have a scope modifier, starts at the declaration and ends and the end of the file it is declared in.</p>
<h3>Examples</h3>
<pre class="prettyprint notranslate">
#!/home/euphoria-4.0b2/bin/eui
enum ONE, TWO, THREE, FOUR
printf(1, "Value of ONE %d\n", ONE )
printf(1, "Value of TWO %d\n", TWO )
printf(1, "Value of THREE %d\n", THREE )
printf(1, "Value of FOUR %d\n", FOUR )
</pre>
<p>This will produce following result −</p>
<pre class="result notranslate">
Value of ONE 1
Value of TWO 2
Value of THREE 3
Value of FOUR 4
</pre>
<p>You can change the value of any one item by assigning it a numeric value. Subsequent values are always the previous value plus one, unless they too are assigned a default value.</p>
<pre class="prettyprint notranslate">
#!/home/euphoria-4.0b2/bin/eui
enum ONE, TWO, THREE, ABC=10, XYZ
printf(1, "Value of ONE %d\n", ONE )
printf(1, "Value of TWO %d\n", TWO )
printf(1, "Value of THREE %d\n", THREE )
printf(1, "Value of ABC %d\n", ABC )
printf(1, "Value of XYZ %d\n", XYZ )
</pre>
<p>This produce the following result −</p>
<pre class="result notranslate">
Value of ONE 1
Value of TWO 2
Value of THREE 3
Value of ABC 10
Value of XYZ 11
</pre>
<p>Sequences use integer indices, but with enum you may write code like this −</p>
<pre class="prettyprint notranslate">
enum X, Y
sequence point = { 0,0 }
point[X] = 3
point[Y] = 4
</pre>
<title>Euphoria Data Types</title>
<h1>Euphoria - Data Types</h1>
<p>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.</p>
<p>Euphoria has some standard types that are used to define the operations possible on them and the storage method for each of them.</p>
<p>Euphoria has following four standard data types −</p>
<p>The understanding of atoms and sequences is the key to understanding Euphoria.</p>
<h2>Integers</h2>
<p>Euphoria integer data types store numeric values. They are declared and defined as follows −</p>
<p>The variables declared with type integer must be atoms with <b>integer</b> values from -1073741824 to +1073741823 inclusive. You can perform exact calculations on larger integer values, up to about 15 decimal digits, but declare them as atom, rather than integer.</p>
<h2>Atoms</h2>
<p>All data objects in Euphoria are either atoms or sequences. An atom is a single numeric value. Atoms can have any integer or double-precision floating point value. Euphoria atoms are declared and defined as follows−</p>
<p>The atoms can range from approximately -1e300 to +1e300 with 15 decimal digits of accuracy. An individual character is an <b>atom</b> which must may be entered using single quotes. For example, all the following statements are legal −</p>
<h2>Sequences</h2>
<p>A sequence is a collection of numeric values which can be accessed through their index. All data objects in Euphoria are either atoms or sequences.</p>
<p>Sequence index starts from 1 unlike other programming languages where array index starts from 0. Euphoria sequences are declared and defined as follows −</p>
<p>A character string is just a <b>sequence</b> of characters which may be entered using double quotes. For example, all the following statements are legal −</p>
<p>Character strings may be manipulated and operated upon just like any other sequences. For example, the above string is entirely equivalent to the sequence −</p>
<p>You will learn more about sequence in <a href="/euphoria/euphoria_sequences.htm">Euphoria − Sequences</a>.</p>
<h2>Objects</h2>
<p>This is a super data type in Euphoria which may take on any value including atoms, sequences, or integers. Euphoria objects are declared and defined as follows −</p>
<p>An object may have one of the following values −</p>
<p>a sequence</p>
<p>an atom</p>
<p>an integer</p>
<p>an integer used as a file number</p>
<p>a string sequence, or single-character atom</p>
<p>© Copyright 2017. All Rights Reserved.</p>
<pre class="prettyprint notranslate">
integer var1, var2
var1 = 1
var2 = 100
</pre>
<p>The variables declared with type integer must be atoms with <b>integer</b> values from -1073741824 to +1073741823 inclusive. You can perform exact calculations on larger integer values, up to about 15 decimal digits, but declare them as atom, rather than integer.</p>
<h2>Atoms</h2>
<p>All data objects in Euphoria are either atoms or sequences. An atom is a single numeric value. Atoms can have any integer or double-precision floating point value. Euphoria atoms are declared and defined as follows−</p>
<pre class="prettyprint notranslate">
atom var1, var2, var3
var1 = 1000
var2 = 198.6121324234
var3 = 'E'
</pre>
<p>The atoms can range from approximately -1e300 to +1e300 with 15 decimal digits of accuracy. An individual character is an <b>atom</b> which must may be entered using single quotes. For example, all the following statements are legal −</p>
<pre class="result notranslate">
-- Following is equivalent to the atom 66 - the ASCII code for B
char = 'B'
-- Following is equivalent to the sequence {66}
sentence = "B"
</pre>
<h2>Sequences</h2>
<p>A sequence is a collection of numeric values which can be accessed through their index. All data objects in Euphoria are either atoms or sequences.</p>
<p>Sequence index starts from 1 unlike other programming languages where array index starts from 0. Euphoria sequences are declared and defined as follows −</p>
<pre class="prettyprint notranslate">
sequence var1, var2, var3, var4
var1 = {2, 3, 5, 7, 11, 13, 17, 19}
var2 = {1, 2, {3, 3, 3}, 4, {5, {6}}}
var3 = {{"zara", "ali"}, 52389, 97.25}
var4 = {} -- the 0 element sequence
</pre>
<p>A character string is just a <b>sequence</b> of characters which may be entered using double quotes. For example, all the following statements are legal −</p>
<pre class="prettyprint notranslate">
word = 'word'
sentence = "ABCDEFG"
</pre>
<p>Character strings may be manipulated and operated upon just like any other sequences. For example, the above string is entirely equivalent to the sequence −</p>
<pre class="prettyprint notranslate">
sentence = {65, 66, 67, 68, 69, 70, 71}
</pre>
<p>You will learn more about sequence in <a href="/euphoria/euphoria_sequences.htm">Euphoria − Sequences</a>.</p>
<h2>Objects</h2>
<p>This is a super data type in Euphoria which may take on any value including atoms, sequences, or integers. Euphoria objects are declared and defined as follows −</p>
<pre class="prettyprint notranslate">
object var1, var2, var3
var1 = {2, 3, 5, 7, 11, 13, 17, 19}
var2 = 100
var3 = 'E'
</pre>
<title>Euphoria Operators</title>
<h1>Euphoria - Operators</h1>
<p>Euphoria provides a rich set of operators to manipulate variables. We can divide all the Euphoria operators into the following groups −</p>
<h2>The Arithmetic Operators</h2>
<p>Arithmetic operators are used in mathematical expressions in the same way that they are used in Algebra. The following table lists the arithmetic operators. Assume integer variable A holds 10 and variable B holds 20 then −</p>
<p><a href="/euphoria/euphoria_arithmatic_operators.htm">Show Examples</a></p>
<h2>The Relational Operators</h2>
<p>There are following relational operators supported by Euphoria language. Assume variable A holds 10 and variable B holds 20 then −</p>
<p><a href="/euphoria/euphoria_relational_operators.htm">Show Examples</a></p>
<h2>The Logical Operators</h2>
<p>The following table lists the logical operators. Assume boolean variables A holds 1 and variable B holds 0 then −</p>
<p><a href="/euphoria/euphoria_logical_operators.htm">Show Examples</a></p>
<p>You can also apply these operators to numbers other than 1 or 0. The convention is: zero means false and non-zero means <i>true</i>.</p>
<h2>The Assignment Operators</h2>
<p>There are following assignment operators supported by Euphoria language −</p>
<p><a href="/euphoria/euphoria_assignment_operators.htm">Show Examples</a></p>
<p><b>Note</b> − The equals symbol '=' used in an assignment statement is not an operator, it is just a part of the syntax.</p>
<h2>Miscellaneous Operators</h2>
<p>There are few other operators supported by Euphoria Language.</p>
<h3>The '&' Operator</h3>
<p>Any two objects may be concatenated using “&” operator. The result is a sequence with a length equal to the sum of the lengths of the concatenated objects.</p>
<p>For example −</p>
<p>This produces the following result −</p>
<h2>Precedence of Euphoria Operators</h2>
<p>Operator precedence determines the grouping of terms in an expression. This affects how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has higher precedence than the addition operator.</p>
<p>For example, x = 7 + 3 * 2</p>
<p>Here, x is assigned 13, not 20 because operator * has higher precedence than +.</p>
<p>Hence it first starts with 3*2 and then adds into 7.</p>
<p>Here operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. Within an expression, higher precedence operators is evaluated first.</p>
<p>© Copyright 2017. All Rights Reserved.</p>
<pre class="prettyprint notranslate">
#!/home/euphoria-4.0b2/bin/eui
sequence a, b, c
a = {1, 2, 3}
b = {4}
c = {1, 2, 3} & {4}
printf(1, "Value of c[1] %d\n", c[1] )
printf(1, "Value of c[2] %d\n", c[2] )
printf(1, "Value of c[3] %d\n", c[3] )
printf(1, "Value of c[4] %d\n", c[4] )
</pre>
<p>This produces the following result −</p>
<pre class="result notranslate">
Value of c[1] 1
Value of c[2] 2
Value of c[3] 3
Value of c[4] 4
</pre>
<title>Euphoria Branching</title>
<h1>Euphoria - Branching</h1>
<p>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.</p>
<p>Following diagram shows a simple scenario where a program needs to take one of the two paths based on the given condition.</p>
<p>Euphoria provides following three types of decision making (branching or conditional) statements −</p>
<p><a href="/euphoria/euphoria_if_statement.htm">if statement</a></p>
<p><a href="/euphoria/euphoria_switch_statement.htm">switch statement</a></p>
<p><a href="/euphoria/euphoria_ifdef_statement.htm">ifdef statement</a></p>
<p>Let us see the statements in detail −</p>
<p>© Copyright 2017. All Rights Reserved.</p>
<title>Euphoria Loop Types</title>
<h1>Euphoria - Loop Types</h1>
<p>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.</p>
<p>There are several ways to specify for how long the process should go on, and how to stop or otherwise alter it. An iterative block may be informally called a loop, and each execution of code in a loop is called an iteration of the loop.</p>
<p>The following diagram shows a simple logical flow of a loop −</p>
<p>Euphoria provides following three types of loop statements −</p>
<p><a href="/euphoria/euphoria_while_statement.htm" title="while statement">while statement</a></p>
<p><a href="/euphoria/euphoria_until_statement.htm" title="loop until statement">loop until statement</a></p>
<p><a href="/euphoria/euphoria_for_statement.htm" title="for statement">for statement</a></p>
<p>All the above statements provide you flexibility and ease of use based on different situations. Let us see them in detail one by one −</p>
<p>© Copyright 2017. All Rights Reserved.</p>
<title>Euphoria Flow Control</title>
<h1>Euphoria - Flow Control</h1>
<p>Program execution flow refers to the order in which program statements get executed. By default the statements get executed one after another.</p>
<p>However; many times the order of execution needs to be altered from the default order, to get the task done.</p>
<p>Euphoria has a number of <i>flow</i> control statements that you can use to arrange the execution order of statements.</p>
<h2>The <i>exit</i> statement</h2>
<p>Exiting a loop is done with the keyword <b>exit</b>. This causes flow to immediately leave the current loop and recommence with the first statement after the end of the loop.</p>
<h3>Syntax</h3>
<p>The syntax of an exit statement is as follows −</p>
<p>The <b>exit</b> statement terminates the latest and innermost loop until an optional label name or number is specified.</p>
<p>A special form of <b>exit N</b> is <b>exit 0</b>. This leaves all levels of loop, regardless of the depth. Control continues after the outermost loop block. Likewise, exit -1 exits the second outermost loop, and so on.</p>
<h3>Example</h3>
<p>This produces the following result −</p>
<h2>The <i>break</i> statement</h2>
<p>The <b>break</b> statement works exactly like the <b>exit</b> statement, but applies to if statements or switch statements rather than to loop statements of any kind.</p>
<h3>Syntax</h3>
<p>The syntax of break statement is as follows −</p>
<p>The <b>break</b> statement terminates the latest and innermost if or switch block until an optional label name or number is specified.</p>
<p>A special form of <b>break N</b> is <b>break 0</b>. This leaves the outer most if or switch block, regardless of the depth. Control continues after the outermost block. Likewise, break -1 breaks the second outermost if or switch block, and so on.</p>
<h3>Example</h3>