C(a|d)ⁿr 1.1: Future-proofing RacketCon

With (fifteenth RacketCon) coming up, we will once again be running out of list accessors in racket/list soon. Fortunately, with the new c(a|d)ⁿr release now providing list accessors into the millions and beyond, this pressing issue can finally be solved for good:

> (require cadnr)
> (define RacketCon
    (for/list ([year (in-range twenty-eleven one-million)])
      `(RacketCon ,year)))

; --------------- before ... ---------------
> (cadddddddddddddddddddddddddddr RacketCon) ;; hmm yes, this is lovely, but...
'(RacketCon 2038);    ^ 18... 19... ah! I lost count :(

; --------------- after...   ---------------
> (twenty-eighth RacketCon) ;; perfect!
'(RacketCon 2038)

It doesn't stop there, though! The new c(a|d)ⁿr knows about all sorts of numbers and containers, even those that haven't been written yet:

> (vector-fifth (list 1 2 3 4 5))
5
> (string-last "abcdefghijklmnopqrstuvwxyz")
          ; this one's clearly not that useful, writing out
          ;   (string-ref s (sub1 (string-length s)))
          ; is far easier on the eyes
#\z
> (non-empty-vector? (vector 1))
          ; analogous to the venerable non-empty-string?
#t
> (string-empty? "")
#t

> (require math/flonum)
> (define flvec (build-flvector ten-million (compose fl add2011)))
          ; unlike sequence-ref, cadnr accessors always
          ; use type-ref for maximum performance

> (time (sequence-two-millionth flvec))   ; linear time :(
cpu time: 45 real time: 46 gc time: 5
2002010.0

> (time (flvector-two-millionth flvec))   ; constant time! :)
cpu time: 0 real time: 0 gc time: 0
2002010.0

Read the documentation, and try it out today!

7 Likes

jay gatsby toast gif

Thank you. I will certainly use this to promote (fifteenth RacketCon) :smile:

Did you see RacketCon 2025: Call for Presentations ?

:beetle: