1. Allow a sequence as a subscript
- Posted by lpuster Sep 22, 2010
- 1076 views
Wishlist item:
When a function returns a location in a multi-dimensioned array, it must return a sequence. It is very messy to use the sequence to access the array.
sequence array, subscript array = {{1,2,3},{4,5,6},{7,8,9}} subscript = {2,3} array[subscript[1]][subscript[2]] -- Current method array[subscript] -- Wishlist alternative method
2. Re: Allow a sequence as a subscript
- Posted by euphoric (admin) Sep 22, 2010
- 1071 views
Wishlist item:
When a function returns a location in a multi-dimensioned array, it must return a sequence. It is very messy to use the sequence to access the array.
sequence array, subscript array = {{1,2,3},{4,5,6},{7,8,9}} subscript = {2,3} array[subscript[1]][subscript[2]] -- Current method array[subscript] -- Wishlist alternative method
Check out extract(). That should work for now until using a sequence to access elements is built-in.
3. Re: Allow a sequence as a subscript
- Posted by jimcbrown (admin) Sep 22, 2010
- 1114 views
Wishlist item:
When a function returns a location in a multi-dimensioned array, it must return a sequence. It is very messy to use the sequence to access the array.
sequence array, subscript array = {{1,2,3},{4,5,6},{7,8,9}} subscript = {2,3} array[subscript[1]][subscript[2]] -- Current method array[subscript] -- Wishlist alternative method
Check out extract(). That should work for now until using a sequence to access elements is built-in.
extract() WILL NOT DO WHAT YOU WANT! extract() does something different.
Instead, see fetch() - http://oe.cowgar.com/docs/eu400_0070.html#_2482_fetch
4. Re: Allow a sequence as a subscript
- Posted by ArthurCrump Sep 22, 2010
- 1068 views
Wishlist item:
When a function returns a location in a multi-dimensioned array, it must return a sequence. It is very messy to use the sequence to access the array.
sequence array, subscript array = {{1,2,3},{4,5,6},{7,8,9}} subscript = {2,3} array[subscript[1]][subscript[2]] -- Current method array[subscript] -- Wishlist alternative method
I suppose that by about Euphoria version 5 or 6 there could be an assignment to a sequence of Euphoria variables, with a very strict format. For example:
sequence array, X, Y array = {{1,2,3},{4,5,6},{7,8,9}} {X,Y} = {2,3} -- Or some function returning {2,3} array[X][Y] -- Or you may want array[Y][X]
I don't think this syntax would conflict with any existing Euphoria syntax.
I am definitely NOT going to put a feature request in for it, even though I would often have found it useful in the past.
Arthur
5. Re: Allow a sequence as a subscript
- Posted by ArthurCrump Sep 22, 2010
- 1040 views
A more immediate solution would be to use a function to get the required element. I think the following function might work, but I have not tested it very well.
function getElement( object array, object subscripts ) subscripts &= {} -- Make it a sequence for n = 1 to length(subscripts) do array = array[subscripts[n]] end for return array end function
6. Re: Allow a sequence as a subscript
- Posted by euphoric (admin) Sep 22, 2010
- 1027 views
A more immediate solution would be to use a function to get the required element.
Methinks that's what fetch() does...?
public function fetch(sequence source, sequence indexes) object x for i=1 to length(indexes)-1 do source = source[indexes[i]] end for x = indexes[$] if atom(x) then return source[x] else return source[x[1]..x[2]] end if end function