;Summary of Universal Function Design RecipeSunday October 13 Version
; This assumes you know what the terms function, function name, function definition, literal,
; argument, unary, binary, parameter name, expression, echo, and call a function mean.
; To understand an assignment, in particular the design process weve been following, understand ; those terms first. When those terms come up here and in the assignment comments, ask us about ; the terms you dont know first before asking about what to do for the assignment.
; This is a summary. If youre tempted to read about a skill more than practicing it, read ahead only
; after youve tried and practiced earlier parts explicitly. Reading ahead can be counterproductive if ; you try too hard to understand parts you arent ready for. When asking for help, let us know which ; step youre working on, and include the concrete work you have for the earlier steps.
; 1 Goal Example: write down at least one example of what you want your new function to accomplish. same! newfunctionname exampleliteralargument etc
; ; ; ;
exampleliteralresult
After making your example, you notice that you decided:
a name for your new function the name you used in your example
how many arguments it will takeneed the number of arguments you used in your example
in particular, you implicitly decided whether the function will be unary, binary, ternary, etc
; ;
; ;
; ; ;
; ; ; ; ; ;
and could even use that as a temporary definition, since its grammatically correct, and even has
the right number of parameters for the examples.
2 ProblemSolving: create an expression to produce your exampleliteralresult from your exampleliteralarguments.
Copy the exampleliteralarguments and exampleliteralresult into the Interactions area, so you can see them together there. Actually entering them and seeing them echoed back asis, with no errors, also confirms that you copied the literals and not other parts of your example.
Play around, following the ForwardBackward aspect of problemsolving.
Forward: play around with the arguments, calling functions on them, andor editing them manually to
get a feel for the computation, to try to produce results like the example result.
Backward: play around with the result, calling functions to try to produce it form arguments that are
more like the example arguments, andor edit it manually to try to break it into simpler parts that you might be able to produce from the example arguments eventually and then put together.
That also enables you to see the grammatical form of your future function definition. With one madeup parameter name per argument, you can write down the form
;
;
;define newfunctionname ; For example, if the function is binary.
3 Design Record: make a record of your problemsolving, in particular for the example expressions that can compute the result.
;
;
same! newfunctionname exampleliteralargument etc
oneofyourexpressionsthatcomputestheresult
; That is known as a Design example.
; When an expression to compute the result uses the arguments explicitly unedited asis, and nowhere ; else implicitly a part that would need to change if the arguments changed, then it fully expresses the ; computation generally, which is known as a Full Design. Other designs are known as Partial.
; 4 Fuction Definition: mechanically turn your Full Design example into a function definition. define newfunctionname aparamtername etc
; ; ; ; ;
modifiedfulldesignexpressionthatcomputestheresult
Turn a Full Design into a correct function definition by copypasting it, then simplymechanically:replace same! with define
choose a parameter name for each argument
modify the body by replacing each argument everywhere so both in the header and body
with your chosen name
Reviews
There are no reviews yet.