handle-los: list-of-symbol --> ??acc is pretty useless;
matches-so-farcond do two different things
(such as testing which type of list you have, and be
testing whether the leading symbols was the one being searched for).
(+ (cond [(symbol=? (first nums) target)
(+ 1 (nSyms (rest nums)))]
[else (nSyms (rest nums))]) 17)
is much more legible as
(+ (cond [(symbol=? (first nums) target)
(+ 1 (nSyms (rest nums)))]
[else (nSyms (rest nums))])
17)
Note how the latter makes it clear what the two arguments
to + are,
and also makes it clear that (in the first cond branch)
the answer is not a sub-expression of the question.
i (iota): The "purpose" statement should mention what each parameter means, and should probably mention them by name. So rather than "this function returns how many times a symbol occurs in a list of symbols", much preferred is "Return the number of times match-sym occurs in sym-list."
Note that for accumulator functions, your purpose statement needs to acknowledge/mention the parameter which is acting as an accumulator! For instance, some people had
;; nSyms2-help: symbol, list-of-symbol, number --> number ;; Returns the number of occurences of target in syms. ;; (define (nSyms2-help target syms so-far) ...)This purpose is a bald-faced lie! The function returns the number of occurences of
target in syms
plus so-far.
By the way, the Purpose statements have no need of saying
"this function takes in a symbol and a list of symbols
and returns a number" -- this is what the contract
already says for you (much more concisely).
(See also, the aside at a.)
In other languages, where you have statement-blocks, you use the placement of closing-punctuation to visually reinforce the code's structure, but that isn't needed in scheme.
Allowable exception:
in cond statements, sometimes you add or remove
entire lines at a time.
To make this easier, some schemers do put the closing
paren on a separate line:
(define (handle command)
(cond [(symbol=? command 'go-north) (voyage-to northern-wastelands)]
[(symbol=? command 'show-inventory) (display player-inventory)]
))
In the future, we'll see local, which has
this same list-of-codelines property.
Except for these situations, bunch your parens at the end.
Finally, a spelling note: in the honor pledge, many misspelled "received" (!)
Language is the apparel in which your thoughts parade in public. Never clothe them in vulgar and shoddy attire.
-- Dr. George W. Crane