Skip to page content

[2020-08-20 Thu 10:07]

Ahhh heck. I think I need to change how Things work.

So right now, for every quality, there’s procedures like set-thing-area-exits!.

This is really verbose, leads to lots of copy-pasting of code that might be nearly identical between qualities, except quality-name.

So, maybe what I should do is have the basic set of thing-quality APIs check universes and things for these procedures, as keys inside hashtables, the way certain things like the MUDSocket check the universe-procedures for a custom login message, for example.

This requires a new thing struct:

(struct thing (name universe grammar qualities procedures))

And a new make-thing procedure, but we’ll skip that for now to look at how the new set-thing-quality! might look:


(define (set-thing-quality! changed-thing changed-quality new-value)
  (let ([set-thing-quality!-procedure-key
       (string->symbol
	(join-list-of-strings-and-symbols-as-string
	 (list "set-thing-" changed-quality "!")))])
    (cond [(thing-has-procedure? set-thing-quality!-procedure-key)
	 ((thing-procedure set-thing-quality!-procedure-key)
	  changed-thing new-value)]
	[(and (thing-has-universe? changed-thing)
	      (universe-has-procedure? (thing-universe changed-thing)
				       set-thing-quality!-procedure-key))
	 ((universe-procedure (thing-universe changed-thing)
			      set-thing-quality!-procedure-key)
	  changed-thing new-value)]
	[else
	 (hash-set! (thing-qualities changed-thing)
		    changed-quality new-value)])))

That’s the idea anyway. This seems like a good choice of time to make use of the recently set-up git repository that this code rests in, to make a branch and tinker in it for a bit… after I take care of some real-world chores.