nicholasbs/statemachines — comment on commit 4fc7e8d6e8b7414c8f30a2ad7f2a4be01f049fec
File: pda.ss line 15
By apgwoz:

I'm not sure if neil/sicp has this, but most scheme implementations have a `define-record` or `define-structure` macro that takes care of this for you. It also creates accessors (and setters) that, by convention, don't begin with "get-" (which is very much a javaism).

SRFI-9 has `define-record-type` which looks like this. It's verbose, but that's because R5RS macros don't allow you introduce your own names in them so they have to be provided. In R6RS, this could be simplified drastically, because syntax-case macros allow you to break hygiene and introduce names. This maybe more explanation than you were looking for, but whatever!

(define-record-type pda
(make-pda start-state accept-state transitions)
pda?
(pda-start-state start-state)
(pda-accept-state accept-state)
(pda-transitions transitions))

(Not that this matters, but `define-record-type` will end up using a vector and field access is therefore constant time.)