Re: Euphoria 4.0.1
- Posted by Vinoba Mar 13, 2011
- 2662 views
-- Start of test code stest.ex without type_check without warning include std/console.e include machine.e include sort.e include misc.e sequence spurchages = { "Screws" , "Nails" , "Rivets" } sequence spr = { 7.34, 2.54, 6.72 } sequence squan = { 12, 20, 24 } -- atom squan = 12 -- sequence squan = 12 -- integer squan = 12 -- sequence squan = { 12, 12, 12 } atom ttotal = 0 sequence sdetails sdetails = invoice ( spr , squan ) -- Now go and print invoice using spr, squan, sdetails and ttotal function invoice (sequence sprice , sequence squantity ) -- Multiply each element of sequence sprice with each element of squantity and return in ttotal integer isize = length ( sprice ) sequence sitemcost = repeat (0 , isize) for i = 1 to isize do sitemcost [ i ] = sprice [ i ] * squantity [ i ] ttotal = ttotal + sitemcost [ i ] end for return sitemcost end function -- End of test code stest.ex
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.