Question: Doubt in List - Answers unable to explain


Dear colleagues, Can anyone explain what (a::list,b::list) will be understood by the programme?

I thought the programme is made for only adding the numbers in the list. But it seems there is something more than that, i could not get.

Equn label (6) onwards, I donot understand, how the answer was obtained.

Thanks for explaining.

Ramakrishnan V

with(MathematicalFunctions:-Evalf); -1; addList1 := proc (a::list, b::integer)::integer; local x, i, s; description "add a list of numbers and multiply by a constant"; x := b; s := 0; for i in a do s := s+a[i] end do; s := s*x end proc

proc (a::list, b::integer)::integer; local x, i, s; description "add a list of numbers and multiply by a constant"; x := b; s := 0; for i in a do s := s+a[i] end do; s := s*x end proc

(1)

s := addList1([1, 2, 3, 4], 2)

20

(2)

s := addList1([2, 2, 3, 4], 2)

22

(3)

x := 2 = 2NULL

s := addList1([x, 2, 3, 4], 2)

22

(4)

s := addList1([2, x, 3, 4], 2)

22

(5)

sumList := addList1([4, 3, 1, 3, 4, 3], 2)

26

(6)

s := addList1([4, 3, 1, 3, x, 3, 4, 3], 2)

34

(7)

s := addList1([2, 2, 3, 4], 2)

22

(8)

s := addList1([4, 3, 1, 8, x, 3, 4, 3], 2)

58

(9)

x

2

(10)

``


 

Download Doubt_on_list.mw

Please Wait...