racket Recursion Using a named let

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

A normal let form binds each value to its corresponding identifier, before executing the body. With a "named let", the body can then recursively be re-executed, passing a new value for each identifier.

#lang racket
(let sum-of-list ([l '(1 2 3)])
  (if (null? l)
      0
      (+ (car l) (sum-of-list (cdr l)))))
;; => 15

It is common to use rec as the name for the let, which gives:

#lang racket
(let rec ([l '(1 2 3 4 5)])
  (if (null? l)
      0
      (+ (car l) (rec (cdr l)))))
;; => 15


Got any racket Question?