Re: Euphoria 4.0.1

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

In this example, if I use the quantities in squan as a full matching length sequence, I am OK. But look at the alternatives I have commented out.

But supposing I want to use a derived amount as a result of some other calculations or simply if the quantities for all items purchased is 12, I have to use 12, 12, 12.

Thus the facility of one value being used against many in Math operations is not properly usable. I can use atoms but even then within the function, I have to do a direct

sitemcost = sprice * squantity

There is no comfortable way of doing the invoice presuming that a single value for quantity or price would be acceptable within the function off and on as the situation arises. Also if the invoicing function has to be used for a single item purchased the function will not work comfortably.

I'm not sure what the issue is here. You gave the solution that accomplishes what you appear to want. You could also use math:sum:

include std/math.e 
function invoice (sequence sprice , object squantity )  
	-- Multiply each element of sequence  sprice with each element of squantity and return in ttotal 
	sequence sitemcost = sprice * squantity 
	ttotal = sum( sitemcost & ttotal ) 
	return sitemcost  
end function  

Now, you end up with a sequence of totals, plus the total. For a single item, you simply have a sequence with a single price, or you do something like this (you'll find this idiom in a lot of euphoria code:

include std/math.e 
function invoice (object sprice , object squantity )  
	if atom( sprice ) then 
		sprice = {sprice) 
	end if 
	-- Multiply each element of sequence  sprice with each element of squantity and return in ttotal  
	sequence sitemcost = sprice * squantity 
	ttotal = sum( sitemcost & ttotal ) 
	return sitemcost  
end function  

Did I miss something else that you wanted to be able to do? Or why this isn't an acceptable solution?

Matt

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

Search



Quick Links

User menu

Not signed in.

Misc Menu