Re: General Beginner Issues
- Posted by jaygade Jul 15, 2013
- 3155 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.