Thursday, February 24, 2011

Chapter 7

7.2.2:

Without -u (diff factorial-number factorial > factorial-nfix-ticket2604.patch)

6,7c6,7
< if n > 0:
< result = n * factorial_recursive(number-1) --- > if number > 0:
> result = number * factorial_recursive(number-1)

With -u (diff -u factorial-number factorial > factorial-nfix-ticket2604.patch)

--- factorial-number 2011-02-03 05:53:13.000000000 -0500
+++ factorial 2011-02-17 14:29:58.590786002 -0500
@@ -3,8 +3,8 @@
# define a factorial function in recursive flavor
def factorial_recursive(number):
result = 1
- if n > 0:
- result = n * factorial_recursive(number-1)
+ if number > 0:
+ result = number * factorial_recursive(number-1)
print "factorizing: ", number, " result: ", result
return result

Without -u, the output is only the changed lines. Diff run with the -u tag shows names of the two files that were compared, the time and date of the two files' creations, as well as the the code of the entire function that was changed. I am not sure what the numbers mean directly above the code in each example.


7.8:

Created a 'bar' file with these contents:
Contents of the "bar" file: blah blah blah

Command:
diff -u /dev/null bar > foo

Results (in 'foo' file):
--- /dev/null 2011-02-24 11:26:51.181903002 -0500
+++ bar 2011-02-24 12:04:15.292286001 -0500
@@ -0,0 +1 @@
+Contents of the "bar" file: blah blah blah

I'm not entirely sure if I understood the instructions correctly, but from what I can tell I did the exercise correctly.


7.9:

I tried running the first command (curl -O http://ftp.gnu.org/gnu/coreutils/coreutils-8.4.tar.gz) but I didn't have the 'curl' program installed. After running 'sudo apt-get curl', I ran the command again. The rest of the steps were as easy as copying and pasting the commands into terminal, with the exception of editing the 'echo.c' file and the 2nd to last step which reads: "$ ./configure$ make." The 'make' step should be on a new line.

The last step made me laugh; either it is written wrong or it was an intentional joke. The command list being reversed is the same backwards and forwards, so even if the echo command is now reversing the order, you can't tell. I instead ran 'src/echo is this reversed' and this gave the output 'reversed this is' proving that it is reversing the order of words.

No comments:

Post a Comment