| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
srfi-2 - And-let* and-let* macro.
let*, but returns #f immediately
whenever the expression in bindings evaluates to #f.
Each binding should be one of the following form:
#f, stops evaluation and returns #f from and-let*.
Let's see some examples. The following code searches key from an assoc-list alist and returns its value if found.
(and-let* ((entry (assoc key alist))) (cdr entry)) |
If arg is a string representation of an exact integer, returns its value; otherwise, returns 0:
(or (and-let* ((num (string->number arg))
((exact? num))
((integer? num)))
num)
0)
|
The following is a hypothetical code that searches a certain server port number from a few possibilities (environment variable, configuration file, ...)
(or (and-let* ((val (sys-getenv "SERVER_PORT")))
(string->number val))
(and-let* ((portfile (expand-path "~/.server_port"))
((file-exists? portfile))
(val (call-with-input-string portfile port->string)))
(string->number val))
8080) ; default
|