I'm trying to car/cdr to get a particular element in a list:
(define x7 '(1 3 (5 7) 9))
; The cdr (3 (5 7) 9)
; The cddr ((5 7) 9)
; The caddr (5 7)
; The cdaddr (7)
I've been able to get that far down, however, if I then do car
on the result it works, but if I add another a
into the short-hand form, I get an error:
(car (cdaddr x7)) ; OK
(cadaddr x7) ; cadaddr: unbound identifier in: cadaddr
Does the short-hand form only go up to five chars/steps, or is there something else I'm missing here?
According to the R6RS report:
Arbitrary compositions, up to four deep, are provided. There are twenty-eight of these procedures in all.
This is identical to R5RS and the new R7RS report. There is nothing stopping an implementation from adding more of course, but using these removes portability of your program as other implementations might only provide the required 4 deep.
You can provide your own of course:
(define (cadadadr p)
(cadar (cdadr p)))
Since Scheme does not have any reserved words this should work even if the language or the implementation decides to include these at a later time. It will simply never use the new one and use your definition.