Hi Steven!
Your code looks fine. I wouldn't change anything about it from a functional viewpoint. As advice or comment which you can take or leave, I would just re-organize the expressions a bit.
These are just what I am comfortable with and somewhat personal, not universal truths. :-)
(1) I'd move some items which kind of control the processing into a group of
defines at the top of the source. This makes it easier to change the control items, instead of searching throughout the code for them.
(2) I'd change the "list" references to "set" references, e.g.
not-available-set vice
not-available-list, since the abstract notion we're working with is a set, but the implementation of the set is the list. BTW, nice use of the
difference function -- it's nice to see set theoretic functions used in programs.
(3) I'd wrap the rest of the processing (the "punchline"), starting from the
opening of the principal files, into a
let statement (see the code below). I love
let statements, they tell the reader "these variables are only meant to be used here." It doesn't really matter so much in your program since it is relatively small, but in larger programs, this usage of the
lets is a God send, when I have to go back and read my own code after 6 weeks. :-)
Code: Select all
;;;; This will clean out the numbers that should not be used when
;;;; loading a table.
;;;-------------------
;;; Control variables
(define code-domain (sequence 1 100))
(define unavail-filename "test4.txt")
(define in-filename "tempexp.txt")
(define out-filename "tempexpo.txt")
;;;-------------
;;; Consequents
;; The set of unavailable codes are contained in the file
;; 'unavail-filename'.
(setq not-available-set
(map int
(parse (read-file unavail-filename) {\r\n} 0)))
(println "not available " not-available-set)
;; Codes that are available to be dynamically alotted are from
;; 'code-domain', but which are also *not* in 'not-available-set'.
(setq is-available-set
(difference code-domain not-available-set))
(println "is available " is-available-set)
;;;-----------------------------------
;;; Now, let the rubber meet the road.
(let ((inFile (open in-filename "read"))
(outFile (open out-filename "write")))
(while (read-line inFile)
(letn ((the-line (parse (current-line) {,} 0))
(thepgmcode (int (eval-string (the-line 0))))
(repl-num (if (find thepgmcode not-available-set)
(pop is-available-set)
thepgmcode)))
(write-line (join (set-nth 0 the-line (string repl-num )) {,})
outFile))))
(λx. x x) (λx. x x)