PasteRack.org
Paste # 55285
2020-07-24 23:32:54

Fork as a new paste.

Paste viewed 426 times.


Embed:

  1. #lang racket
  2.  
  3. (define longer-list2
  4.   (for/list ([i (in-range 1 11)]) i))
  5.  
  6. ; tail-recursive, I think
  7. ; with helper function to avoid exposing the counter to the caller
  8. (define (my-length3 lst)
  9.   ( define (aux lst counter)  (cond
  10.                                 [(pair? lst) (aux (rest lst) (+ counter 1) )]
  11.                                 [else counter]))
  12.   (aux lst 0)
  13.   )
  14.  
  15. (my-length3 longer-list2 )

=>

10