example-02-with-converter.scm 828 B

12345678910111213141516171819202122232425262728293031
  1. (import (except (rnrs base) error)
  2. (only (guile)
  3. lambda* λ
  4. make-parameter
  5. parameterize))
  6. (define the-id (make-parameter "abc123"
  7. (λ (val)
  8. (cond
  9. [(symbol? val) (symbol->string val)]
  10. [(number? val) (number->string val)]
  11. [else val]))))
  12. (the-id)
  13. (define id-haver
  14. (λ (name)
  15. (simple-format #t "I am ~a! My id is: ~s\n" name (the-id))))
  16. ;; Call without specifying the id, implicitly uses the globally
  17. ;; previously defined one.
  18. (id-haver "Albert")
  19. ;; Specifying the-id.
  20. (parameterize ([the-id '456])
  21. (id-haver "Albert"))
  22. ;; Afterwards the-id is again the same as globally defined.
  23. (id-haver "Albert")