Closed DjebbZ closed 4 years ago
Hi @DjebbZ, nice catch, thanks for the suggestion. I wouldn't put this in the docstring, but this looks like a good first entry for a 'Tips and Tricks' documentation chapter - would you like contributing it in the doc/
folder and linking it from the README?
I could imagine something like the following:
Problem: sometimes, you would like to evaluate an expression which uses locals saved in different Execution Points. For instance, you may need a req
local from an HTTP request handler, and a db
local from a data-fetching function.
One way to achieve that effect is to nest to sc.api/letsc
calls:
(sc.api/letsc [3 -1] ;; will bring `req` into scope
(sc.api/letsc [5 -2] ;; will bring `db` into scope
(do-something-with req db)))
Caveat: Of course, locals from the inner letsc
may shadow locals from the outer.
TODO: same tip with defsc
.
Added to the Tips and Tricks doc page.
Hi,
I've just discovered that when one captures with
spy
at different places of the code, even if they're executed at different moments (imagine 2 different HTTP requests to the same server), you can nest theletsc
to access both contexts at the same time! Ex:It works like nesting normal
let
s. I have no idea if it was obvious to you, but for me this discovery makes scope-capture even better-er. Should it be documented somehow? Only stating the possibility is enough, like "You can nestletsc
like you nestlet
".