Throughout this assignment, all programming should be done in Go. In addition, all printing should be done using fmt.Printf rather than fmt.Println (or just println). For the String() method (see below) use fmt.Sprintf.
The programs written for this assignment may be quite short (perhaps less than 20 lines of code, each). Nonetheless they should be properly commented.
In some cases below, it may be that the question is answered by providing a program that does not compile. This is OK, but in such cases you need to carefully explain why not compiling proves your point.
Associated with this part should be a textual description of your program(s) describing exactly why and how they prove the form of scoping used by Go. The discussion is worth at least as much as the actual programs.
f := makeIncrementer(3) fmt.Println(f()) fmt.Println(f())which would output
0 3When passed 7, the incrementor function should return 0,7,14,21,... Importantly the incrementor functions must be independent of each other. For instance, given a 3-incrementor a 7-incrementor, then alternating call to the two functions would yield 0,0,3,7,6,14,9,21,...
You program should be able to have an unbounded number of these iterators.
In addition to writing this code, write a testing function that demonstrates the use of your incrementor, and that multiple incrementors do not interact.
Finally, on a Linux machine, collect a "script" file for the execution of your testing code. One way to collect a script file is the following:
Associated with this part should be a textual description of your output file describing exactly why and how your tests and the output show that the incrementors do not interact (and that you can have an unbounded number of incrementors. (Unboundedness will require something more like a math proof than code; at the very least a logical argument.)
a:=[]int{1,2,3,4,5,6,7} for i,v:=range a { fmt.Printf("index:%v value:%v\n", i,v) }In this part of the assignment, write your own iterator function, and an iterator generating function to accomplish much the same thing that Go provides with range.Similar to the incrementor above (part 2), the iterator generating function should take a slice as its single parameter and return an iterator function. Also as with the incrementor above, the iterator function should take no arguments. Unlike the incrementor, the iterator should return a tuple, where the values returned are: the value of the next element in the slice and whether that value returned is valid. The value is not valid only if all of the elements in the slice have already been returned by the iterator. Once the iterator has indicated that the return value is not valid, it should never return an indication of validity.
(Side note) Go recently introduced Generics but we have not gotten there (and may not). So your functions should work on only slices of integers.
To repeat, your iterator should just work on slices containing items of type int.
In addition to writing the iterator and iteratorGenerator, write a set of code that illustrates the use of your iterator by doing the following things:
for initialization; termination; increment { // stuff }If you cannot figure out how to write an iterator that can be run from the for loops setup, you can write an infinite loop that contains break or return to stop the loop.
As with part 2, provide a script of the output of your part 3 program. Your script should show the iterator working on slices of at least 5 items (but no more than 10).
Finally, write a brief analysis of you incrementor. In your analysis:
Your submission will be handed in using the submit script.
If you write your program on computers other than those in the lab, be aware that your program will be graded based on how it runs on the department’s Linux server, not how it runs on your computer. The most likely problem is not submitting everything or hard coding file locations that are not correct on the Linux servers.Answers to the questions posed in each part of the assignment may be in the README or in a separate document.
cd 245I assume that already have a directory named HW3.
/home/gtowell/bin/submit -c 245 -p 3 -d HW3This says to submit for project 3 (-p) everything in the directory HW3 (-d) for the class 245 (-c). You should see listing of all the files you submitted and a message that says "success".
The submission should include the following items: