1. General Beginner Issues
- Posted by Kirkkaf13 Jul 15, 2013
- 3159 views
Hello everyone,
Sorry I couldn't be more specific with the title I have a range of queries/issues.
[1]First of all I am a little confused after reading the documentation on atoms and sequences, as these are the only data objects in Euphoria.
All data objects in Euphoria are either atoms or sequences.
As I understand these vary from memory allocated the update as needed. Then I came across the normal integer data type, so now I have a choice between using an atom or integer? I must of misunderstood the documentation.
[2]If I run the following example; EDITED I think it was something to do with puts (I thought this was the same as print).
puts(1, "Hello, World\n")
As expected I get the words "Hello World" printed within the console. Now I attempted to do the same with a simple calculation;
integer x = 2 puts(1, x+x)
I get a symbol within the console and not the calculated answer, what am I doing wrong?
[3]Can someone explain how I can declare a string variable, is this using sequence?
Thank you for your time and I apologise if my questions are very basic.
Kirk
2. Re: General Beginner Issues
- Posted by _tom (admin) Jul 15, 2013
- 3185 views
The Archive has many resources. See the link to the right of this page.
Things to read first:
- http://rapideuphoria.com/abg_pdf.zip
- from the DOS era of Euphoria, so this is very old but still useful
- http://rapideuphoria.com/thinkeuphoria.zip
- needs updating, but at least you can complain to me directly
- http://rapideuphoria.com/euphoricMysteries%20v0.2.exe
- http://rapideuphoria.com/how2prog.pdf
The Euphoria trick is that everything is a number, but numbers can be used for many things.
print(1, x+x ) -- to show numbers puts(1, x+x ) -- to show text
Now, if the number value is withing the ASCII chart range, then you can display either integers (print) or characters (puts). Outside of this ASCII range using puts displays noise (only print is useful).
A sequence is good for both strings and lists of numbers.
- if you puts, you get text displayed
- if you print, you get numbers displayed
TOM
3. Re: General Beginner Issues
- Posted by jaygade Jul 15, 2013
- 3153 views
Hello everyone,
Sorry I couldn't be more specific with the title I have a range of queries/issues.
[1]First of all I am a little confused after reading the documentation on atoms and sequences, as these are the only data objects in Euphoria.
All data objects in Euphoria are either atoms or sequences.
As I understand these vary from memory allocated the update as needed. Then I came across the normal integer data type, so now I have a choice between using an atom or integer? I must of misunderstood the documentation.
Integers are a special case of atom -- technically, all integers are also atoms. They are included mainly for performance reasons, because most computers still work more quickly with whole numbers rather than with fractional numbers.
You can write all of your programs to use "atom" instead of "integer" if you want, and you will probably still get the results you expect. Reference: http://openeuphoria.org/docs/intro.html#_7_euphoriaisunique
[2]If I run the following example;
puts(1, "Hello, World\n")
As expected I get the words "Hello World" printed within the console. Now I attempted to do the same with a simple calculation;
integer x = 2 puts(1, x+x)
I get a symbol within the console and not the calculated answer, what am I doing wrong?
[3]Can someone explain how I can declare a string variable, is this using sequence?
Thank you for your time and I apologise if my questions are very basic.
Kirk
Euphoria has a lot of output routines. The built-in ones such as puts and printf are probably more familiar to people who have been programming for awhile; however for beginners it's probably best to use writef and writefln from std/io.e:
include std/io.e -- required for the writef and writefln function definitions integer x = 2 writefln("[]", {x}) -- it's okay to skip the {} for a single value, but it's good practice.
Formatted output can get pretty complex, but with that complexity comes great flexibility. Reference: http://openeuphoria.org/docs/std_io.html#_1777_writefln
See also http://openeuphoria.org/docs/std_io.html#_1579_printf for more traditional C-style formatted output.
4. Re: General Beginner Issues
- Posted by jaygade Jul 15, 2013
- 3147 views
[3]Can someone explain how I can declare a string variable, is this using sequence?
Thank you for your time and I apologise if my questions are very basic.
Kirk
Yes, a string is just a sequence of letters. There are many ways to define strings, but the most basic way is with double quotes:
include std/io.e sequence my_string = "Hello, world!" writefln("[]", my_string)
5. Re: General Beginner Issues
- Posted by DerekParnell (admin) Jul 16, 2013
- 3148 views
Hello everyone,
Sorry I couldn't be more specific with the title I have a range of queries/issues.
Not a problem. It can be a bit confusing at first, especially if you've had experience with other programming languages.
[1]First of all I am a little confused after reading the documentation on atoms and sequences, as these are the only data objects in Euphoria.
All data objects in Euphoria are either atoms or sequences.
As I understand these vary from memory allocated the update as needed. Then I came across the normal integer data type, so now I have a choice between using an atom or integer? I must of misunderstood the documentation.
Ok ... while it is true that there are only two data types, atoms and sequences, there are also two 'helper' data types.
An integer is just a specialized atom and can be used where your application needs a bit of extra speed and only in situations where whole numbers are expected.
An object is a variable that can hold anything, and this can change during the running of your program. That is, you can assign a sequence to an object, then later on assign an atom to the same object.
Also note that a sequence is an array of objects. This means that any element in a sequence can hold an atom or a sequence. This is how we get nested sequences and build complex data structures.
[2]If I run the following example; EDITED I think it was something to do with puts (I thought this was the same as print).
puts(1, "Hello, World\n")
As expected I get the words "Hello World" printed within the console. Now I attempted to do the same with a simple calculation;
integer x = 2 puts(1, x+x)
I get a symbol within the console and not the calculated answer, what am I doing wrong?
puts stands for "Put String". It is designed to output the 'string' you supply. If you supply a number (atom or integer), it first converts it to an integer in the range 0 - 255, and then assumes that the resulting number is the ASCII code for a single character. So it outputs one character.
[3]Can someone explain how I can declare a string variable, is this using sequence?
A string is a sequence containing only integer values. Each integer is the code for a character. By default, only ASCII codes are currently supported.
Note that as a convenience, literal strings can be used in source code as double-quoted character strings.
sequence Str Str = "abc" -- A string Str[2] = 3.142 -- No longer is it a string because the second element is no longer an integer. Str[2] = 65 -- Back to being a string (changes the 2nd element to an integer) Str[3] = "def" -- No longer a string because the 3rd element is now a sequence.
6. Re: General Beginner Issues
- Posted by mattlewis (admin) Jul 16, 2013
- 3076 views
[3]Can someone explain how I can declare a string variable, is this using sequence?
A string is a sequence containing only integer values. Each integer is the code for a character. By default, only ASCII codes are currently supported.
Technically, only bytes are supported. The rest is up to your console. In a typical Linux console, it's probably UTF-8, and you can output valid UTF-8. In Windows, of course, there are different code pages that allow you to use different character encodings.
Matt
7. Re: General Beginner Issues
- Posted by _tom (admin) Jul 16, 2013
- 3003 views
I have added a tutorial to the wiki showing how Euphoria can be programmed with just one data-type. The tutorial theme is: how programming with objects is possible, how Euphoria converts all data into numbers, and how objects are output.
Understanding how an object works should help people coming from a conventional programming background.
The wiki link is: http://openeuphoria.org/wiki/view/The%20All%20Mighty%20Object.wc
TOM
8. Re: General Beginner Issues
- Posted by K_D_R Jul 16, 2013
- 2980 views
I have added a tutorial to the wiki showing how Euphoria can be programmed with just one data-type. The tutorial theme is: how programming with objects is possible, how Euphoria converts all data into numbers, and how objects are output.
Understanding how an object works should help people coming from a conventional programming background.
I think your little Wiki page: "The Almighty Object" may be the very best introduction to Euphoria ever written. Great job, Tom!
Perhaps a link to the page could be included in the reference manual. It definitely needs to highly visible/available, particularly to beginners.
Ken Rhodes
9. Re: General Beginner Issues
- Posted by andi49 Jul 16, 2013
- 2962 views
I have added a tutorial to the wiki showing how Euphoria can be programmed with just one data-type. The tutorial theme is: how programming with objects is possible, how Euphoria converts all data into numbers, and how objects are output.
Understanding how an object works should help people coming from a conventional programming background.
The wiki link is: http://openeuphoria.org/wiki/view/The%20All%20Mighty%20Object.wc
TOM
Wow, thank you, Great job
Andreas
10. Re: General Beginner Issues
- Posted by Kirkkaf13 Jul 16, 2013
- 2987 views
Everything is now very clear to me, I agree tom that article has helped me understand how Euphoria works.
Thank you for taking the time to write it.
11. Re: General Beginner Issues
- Posted by _tom (admin) Jul 16, 2013
- 2992 views
Thank you for the encouragement.
It looks like I can include this tutorial in the next official Euphoria documentation.
Thanks
TOM
12. Re: General Beginner Issues
- Posted by jaygade Jul 16, 2013
- 2999 views
I also agree that it is very well written. Good job!
I think we need a manual and/or tutorial page just describing all of the different output routines. For general tutorials, we should probably just stick with one -- display or writefln or printf or puts or whatever. Mention that '?' and 'print' are more useful for quick debugging than for user-readable output.
13. Re: General Beginner Issues
- Posted by useless_ Jul 16, 2013
- 2989 views
I have added a tutorial to the wiki showing how Euphoria can be programmed with just one data-type. The tutorial theme is: how programming with objects is possible, how Euphoria converts all data into numbers, and how objects are output.
Understanding how an object works should help people coming from a conventional programming background.
The wiki link is: http://openeuphoria.org/wiki/view/The%20All%20Mighty%20Object.wc
TOM
Very good, Tom.
useless-kat