creating tiddlers following the HTDP process

 9th February 2024 at 6:23pm

Given that the record-info objects are created, the second part of the project can proceed: to create tiddler files from each record-info. And I'll try to do this the proper HTDP way (which I wasn't necessarily following): to create the function header and definition first — of all functions — and even devise the tests to go along.


(include "utils.scm")

; record-info -> tiddler file

(define capri-ri (make-record-info title: "CAPRISONGS" artist: "FKA Twigs" year: 2022))

; creates a timestamp String
; -> timestamp
(define (get-timestamp)
  (time->string (seconds->utc-time) "%Y%m%d%H%M%S"))

; creates a tiddler-content String from record-info
; record-info timestamp -> tiddler-content
(define (create-tiddler-content record-info timestamp)
   '())
(test #t (let ((timestamp (get-timestamp)))
		   (string=? (create-tiddler-content capri-ri timestamp)
					 (string-append "created: " timestamp "\ncreator: recogarden-script\nmodified: " timestamp "\nmodifier: recogarden-script\ntags: music-record\ntitle: CAPRISONGS\nauthor: FKA Twigs\nyear: 2022\ntype: text/vnd.tiddlywiki"))))

; creates a file from a tiddler-content
; tiddler-content filepath -> Boolean
(define (create-tiddler-file tiddler-content filepath)
   '())
(test #t (let ((bool-result (create-tiddler-file capri-ri)))
		   (and (bool-result) (file-exists? filepath))))

This seems like it? In fact, create-tiddler-content can almost be done by just making small changes to the test string.

; creates a tiddler-content String from record-info
; record-info timestamp -> tiddler-content
(define (create-tiddler-content record-info timestamp)
   (string-append "created: " timestamp "\n"
				  "creator: recogarden-script\n"
				  "modified: " timestamp "\n"
				  "modifier: recogarden-script\n"
				  "tags: music-record\n"
				  "title: " (record-info-title record-info) "\n"
				  "author: " (record-info-artist record-info) "\n"
				  "year: " (record-info-year record-info) "\n"
				  "type: text/vnd.tiddlywiki"))

As for the next part, just the tests are a bit iffy — I'm cleaning up the test file as part of the test so as not to accidentally test a previous file; on the other hand, this test is obviously relying on the results of a function that is not of my responsibility.

; creates a file from a tiddler-content
; tiddler-content filepath -> Boolean
(define (create-tiddler-file tiddler-content filepath)
   (with-output-to-file filepath (lambda () (write-string tiddler-content))))
(let* ((filepath "test-tiddler.tid"))
	(test filepath 
		  (begin (create-tiddler-file (create-tiddler-content capri-ri (get-timestamp)) filepath)
				 (and (file-exists? filepath) (delete-file filepath)))))

In any case, it seems like this is working. I suppose the next step is to create the routine that will do all of the real work.