Re: Need clarification on empty arrays and alocated space

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

I went through the manual but I could not find the answer I need.

Are OEu empty arrays a different type like the 'slices' in Go?
Do these 'slices' need a backup array with a certain predefined size?
Does the size of these backup arrays grow exponentially as the 'slice' increases its length (as they do in Go)?

Thank you.

Everything in Euphoria is an object. An object is either a number (called atoms in Euphoria) or a sequence. There are no "arrays". You can simulate arrays with sequences. The sequence {1,2,3,4} is like an array. Well, think of a sequence as an array of general objects.

print(1, sequence({})) -- prints 1 (for true) 
print(1, sequence({1,2,3})) -- also prints 1 (for true) 

See so empty sequences are sequences too. You can make a user defined type for empty sequence

type empty_sequence(object x) 
    if not sequence(x) then 
        return 0 
    end if 
    return length(x) = 0 
end type 

Then you can say:

print(1, empty_sequence({})) -- prints 1 (for true) 
print(1, empty_sequence({1,2,3})) -- but this prints 0 (for false) 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu