Welcome to the CHICKEN Scheme pasting service
lazy parameters added by mario-goulart on Wed Jun 14 12:54:27 2023
(import (chicken pathname)) (define home-dir (make-parameter "/home")) (define username (make-parameter "mario")) (define user-dir (make-parameter (make-pathname (home-dir) (username)))) (print "### With SRFI-39 parameters:") (print "user-dir before rebinding home-dir: " (user-dir)) (home-dir "/mnt/storage/home") (print "user-dir after rebinding home-dir: " (user-dir)) (print "----------------------------------------------------") (define-syntax define-lazy-parameter (syntax-rules () ((_ var value) (define var (let ((state (lambda () value))) (lambda args (if (null? args) (state) (let ((val (car args))) (set! state (lambda () val)) val)))))))) (define-lazy-parameter home-dir "/home") (define-lazy-parameter username "mario") (define-lazy-parameter user-dir (make-pathname (home-dir) (username))) (print "### With lazy parameters:") (print "user-dir before rebinding home-dir: " (user-dir)) (home-dir "/mnt/storage/home") (print "user-dir after rebinding home-dir: " (user-dir)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $ csi -s lazy-parameters.scm ### With SRFI-39 parameters: user-dir before rebinding home-dir: /home/mario user-dir after rebinding home-dir: /home/mario ---------------------------------------------------- ### With lazy parameters: user-dir before rebinding home-dir: /home/mario user-dir after rebinding home-dir: /mnt/storage/home/mario