There is no previous knowledge needed to read and understand the SRFI. Taken straight from the SRFI under Procedure specification:
- Parameters given in square brackets are optional.
- An
s
parameter is a string.
The other parameters, kons
and knil
, are not mentioned and thus they are mere names that needs explaining. string-fold
gets explained twice:
The left-fold operator maps the kons procedure across the string from left to right
(... (kons s[2] (kons s[1] (kons s[0] knil))))
string-fold
obeys the (tail) recursion:
(string-fold kons knil s start end) ; ==
(string-fold kons (kons s[start] knil) start+1 end)
Thus it shows that:
(string-fold add-char 0 "abracadabra" 8)
is the same as:
(string-fold add-char (add-char #\b 0) "abracadabra" 9 11)
is the same as:
(add-char #\a (add-char #\r (add-char #\b 0)))
And with the definition:
(define add-char
(let ((ma (- (char->integer #\a))))
(lambda (char num)
(+ (char->integer char) ma num))))
(string-fold add-char 0 "abracadabra" 8) ; ==> 18
Now kons
and knil
is used in many SRFIs and very often in such combining situation. It does resemble the procedures cons
and the name of '()
. If you use those:
(string-fold cons '() "abracadabra" 8) ; ==
(cons #\a (cons #\r (cons #\b '()))) ; ==> (#\a #\r #\b)
Thus the names, while not random, is not needed to be understood in order to read and understand the SRFI. All other SRFIs have similar specifications. You might be interested in SRFI-9 Defining record types which has the following example:
(define-record-type :pare
(kons x y)
pare?
(x kar set-kar!)
(y kdr))
defines KONS to be a constructor, KAR and KDR to be accessors, SET-KAR! to be a modifier, and PARE? to be a predicate for :PAREs.
(pare? (kons 1 2)) --> #t
(pare? (cons 1 2)) --> #f
(kar (kons 1 2)) --> 1
(kdr (kons 1 2)) --> 2
(let ((k (kons 1 2)))
(set-kar! k 3)
(kar k)) --> 3