Re: Discuss changing the behaviour of append()

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

I think the basic problem is that S[i] is not (fully) a sequence.

Every slice is a sequence,
S[i] has a length so it is a sequence,
Yet it can type as an atom.

It seems what you need here is an operator which 'converts' an atom to a sequence.

S[i] & {} -- would work as well as  
S[i..i]   -- but they are fixes 

Unfortunately, this is NOT the issue. I'll restate the problem using different words.

Given an object X, I want to create a sequence by adding another object Y, such that the last item in the newly created sequence is Y, and all the other items in X are unaltered.

Examples ...

X = 4      Y = {8,9}  --Result is {4, {8,9}} 
X = {4}    Y = {8,9}  --Result is {4, {8,9}} 
X = {4,5}  Y = {8,9}  --Result is {4, 5, {8,9}} 
X = {}     Y = {8,9}  --Result is {{8,9}} 

In all but the first case, the append() function will suffice. But with the first case I need to convert X to a sequence first. That is what I'm hoping to avoid doing; the 'manually' conversion. Instead I'd like Euphoria to do it automatically.

The only suggestion so far that works in each of the case above is the 'concatenate a sequence' trick, but that has a performance hit of creating a temporary sequence and then disposing of it after the operation has completed. Something I'd also like to avoid.

object X, Y 
X = 4      Y = {8,9}  X &= {Y} --Result is {4, {8,9}} 
X = {4}    Y = {8,9}  X &= {Y} --Result is {4, {8,9}} 
X = {4,5}  Y = {8,9}  X &= {Y} --Result is {4, 5, {8,9}} 
X = {}     Y = {8,9}  X &= {Y} --Result is {{8,9}} 

So, if the change is made to Euphoria's append()/prepend() functions to do this, programs that now currently fail in this situation will no longer fail. Is that okay?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu