RE: Possible feature for new Euphoria-version
- Posted by Tommy Carlier <tommy.carlier at pandora.be> Jan 09, 2004
- 455 views
Peter Blonner wrote: > While it is true that there are alternative meanings that could be > applied > to subscripting through sequences, in my opinion the first is by far the > most attractive. The ability to access various levels of a sequence at > run-time could be quite a powerful tool, however as with Pete Lomax > suggestion implementing it with Euphoria (as it is currently works) would > impose a hefty overhead. > So for me, implementing this as part of the language would be a > significant > improvement that would enable a lot of code to be written more > generically > with reasonable efficiency. Whereas the other alternative applications > could just as well be implemented though library functions. I agree, the second & third application could be easily coded like this: -- first application global function put_in_sequence(sequence source, sequence indices, sequence new_values) for i = 1 to length(indices) do source[ indices[i] ] = new_values[i] end for return source end function -- second application: doesn't use any hashing technique (yet) global function new_key_value_list() return { {}, {} } -- { keys, values } end function global function add_key_value_pair(sequence list, object key, object value) -- doesn't check for double keys (yet) list[1] = append(list[1], key) list[2] = append(list[2], value) return list end function global function get_index_of_key(sequence list, object key) return find(key, list[1]) end function global function get_value_at_index(sequence list, integer index) return list[2][index] end function global function get_value(sequence list, object key) integer index index = get_index_of_key(list, key) if index > 0 then return get_value_at_index(list, index) else return 0 -- this should perhaps be something else end if end function -- Tommy Carlier tommy online: http://users.pandora.be/tommycarlier