Common Lisp – Why do “let” variables keep changes made to them in new iterations?

I’m a beginner lisper and I’ve decided to write a Telegram bot as a test project. Here I have faced some unexpected behaviour of let. The code is in a form of .asd system with one file containing the following code. The important part of it to pay attention to:

  1. long-poll-updates function is basically a loop.

  2. A call to read-updates in long-poll-updates function

  3. A call to check-integrity in read-updates function.

  4. checks variable in let form.

On each iteration of the main loop I do (prin1 checks) and see something that I struggle to look up or understand. On the first iteration of the loop it prints exactly the value that I’ve assigned to it. But each new iteration does not reassign nil values back, but uses the same exact values left behind by the previous iteration’s operations.

(defun long-poll-updates ()
    "Main loop. Repeatedly sends requests to get updates."
    ; Sets a variable for storing the last processed updates's ID.
    (let ((offset 0)) (loop
        (let* ((api-answer  (get-updates-request offset))
               (parsed-plist (jonathan:parse 
                             (flexi-streams:octets-to-string api-answer))))

            ;; Read response and modify offset parameter to get next updates.
            (let ((response-data (read-updates parsed-plist)))  
                (when (getf response-data :has-results) 
                    (setf offset 
                        (1+ (getf response-data :last-update-id)))))))))
(defun read-updates (response-plist)
    "Reads the incoming long poll response: 
     checks for response validity/errors, 
     proceeds to an appropriate action."
    (let ((response-data (check-integrity response-plist)))
            (cond ((getf response-data :has-ok)
                (cond ((getf response-data :is-ok)
        ;; Evaluate updates on successful poll
                    (cond
                        ((getf response-data :has-results)
                            (setf (getf response-data :last-update-id) 
                            (eval-updates response-plist)))
                    (t
                        (log-data "No results received."))))
                (t (log-errors response-plist))))
            (t (log-data "Received malformed JSON-response while long polling."))) 
        response-data))
(defun check-integrity (response-plist)
    "Runs checks for valid JSON received, success/faliure and presence of new updates.
     Returns a plist of checks passed/failed."
    (let ((checks '(:has-ok nil 
            :is-ok nil 
            :has-results nil)))
        (prin1 checks)

        (loop :for  (indicator value) on response-plist by #'cddr
              ;; If successful response:
              :when (eql indicator :|ok|)
              :do   (progn 
                    (setf (getf checks :has-ok) t)
                    (when (eql value t)
                    (setf (getf checks :is-ok) t)))
              ;; If any results:
              :when (and (eql indicator :|result|)
                     (listp value)
                     (< 0 (length value)))
              :do   (setf (getf checks :has-results) t))
        checks))

I suppose I expected function’s code to evaluate anew each time it is called, without realizing it even. Yet it seems that compiler evaluates data to some entity that never leaves memory, before the code is ever run. Could anyone point my mind at a greater idea that I’m dealing with here?

I see that lisp’s way is really “theory first” and I rarely find people actually documenting issues they face when approaching it in a blocky and litteral manner (or whatever it looks like when you’re new to lisp, but had prior coding experience). I find it incredibly strange even, but that’s not the point.

New contributor

Alteration Dream is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật