RE: Possible feature for new Euphoria-version

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

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

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

Search



Quick Links

User menu

Not signed in.

Misc Menu