Re: General Beginner Issues

new topic     » goto parent     » topic index » view thread      » older message » newer message
Kirkkaf13 said...

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.

Kirkkaf13 said...

[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.

http://openeuphoria.org/docs/lang_def.html#_82_definition said...

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.

Kirkkaf13 said...

[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.

Kirkkaf13 said...

[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.  
 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu