This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Data Abstraction | |
| # Variable Naming | |
| # The key idea behind data abstraction is that we want to give meaning to data types. We already have | |
| # seen how the naming your variables more meaninfully would help us give meaning to primitive data. | |
| # For instance, | |
| x = 24 # Not exactly clear what x refers to, and what does 24 mean | |
| # Consider: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # For this question, you are suppose to create a poly generator function, that would create | |
| # a *function* that when passed in a value x, calculate the polynomial of using the coefficient | |
| # that was used when the function is created. | |
| # In short, we are given this function has already been defined for us: | |
| def poly(coefficient, x): | |
| # returns the following: | |
| # (coeff[0] * x^0) + (coeff[1] * x^1) + (coeff[2] * x^2) + ... | |
| # and we want to create a function which would create a function that looks like the above, but has fixed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # GCD HOF Question | |
| # For the filtered accumulate function, notice that the filtered function takes in 1 parameter, the | |
| # term number, and returns True/False, depending on whether we want to accept the term or not. | |
| # For the prime question, we can directly use the same is_prime function, because it takes in | |
| # a number, and returns True if it is prime, and False otherwise. Since we want to sum the square | |
| # of the prime numbers between a and b, is_prime works well as the filtered function. | |
| # For the GCD question, it is not that straightforward. The function that is provided to us, gcd, | |
| # takes in 2 values, and worse, it returns an integer which describes the GCD of the 2 numbers. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def bank_account(balance): | |
| # Inner functions are created in the scope of the | |
| # outer function, and as such have 'knowledge' of | |
| # the scope. | |
| # | |
| # In this case, it knows about the balance. | |
| # This function returns a string telling us | |
| # whether the owner is rich or poor | |
| def are_you_rich(): | |
| # The inner function can access/read the variables |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
| NSString* documentsDirectory = [paths objectAtIndex:0]; | |
| NSString *plistfile = [documentsDirectory stringByAppendingString:@"Global.plist"]; | |
| NSDictionary *dictionaryToSerialize = @{@"Hello": @"World", @"Dictionary": @{@"InnerHello": @"InnerWorld"}}; | |
| [dictionaryToSerialize writeToFile:plistfile atomically:YES]; | |
NewerOlder