IRC channel logs

2021-07-26.log

back to list of logs

<leoprikler>mwette: list-ref is shallow
<mwette>leoprikler: thx
<apteryx_>daviid: oops! I meant to write "what mecanism should I use to recursively *replace* (at any depth level in (nested) lists) an item?
***apteryx_ is now known as apteryx
<daviid>apteryx: I don't think there is any 'magic' but to do exactly that, recursively walk the nested lists and replace the item 'while walking' ... sounds like a sicp exercise :)
<daviid>apteryx: is the item to be replaced an atom (like not a pair), and is it unique or could it appear more then once in the nested lists? if you (could) paste an example, maybe one of us will be tempted to 'play with the exercise' and offer a solution ... always easier and moretempting :) to look at 'concrete' small example ...
<leoprikler>i think there's some sxml/sxpath magic to do those things
<leoprikler>but it's more ref than set!
<daviid>oh, set! ... black magic, not magic :)
<wingo>moin
<kitzman>hmm i'm trying to do something a bit unusual. i have this configuration file in scheme. users are able to pass hooks, something like (hook-for-each (lambda ...)). for the lambda sexp, i do (eval `(,fn ,@args) (environment)), and i apply that to each element in a list. then if i process smth like ((a b) (c d) ...) it works. if i process smth like ((a (b c)) (x (y z)) ...), when ",@args" is done, it tried to apply (b c) or (y z) instead
<kitzman>of those staying in their list form... is there a way to avoid this?
<lampilelo>kitzman: use apply instead of quasiquote and splicing
<leoprikler>yeah, apply
<lampilelo>you end up with (eval '((lambda ...) a (b c))), then it tries to resolve (b c)
<kitzman>hm the thing is when reading the configuration, i get a sexp representing a lambda. shouldn't that be evaluated to work?
<leoprikler>I think reading code from "config files" is probably a bad idea anyway
<leoprikler>either make your config files full turing-complete (i.e. use "load") or try to make them possible without functions
<leoprikler>alternatively, you can try `eval'ing just the procedure, but not the data, but it's still a weird thing to do
<leoprikler>you can inject arbitrary code into whatever you believe to be just the function lambda
<leoprikler>consider (begin (invoke "rm" "-rf" "/") (const #t))
<kitzman>nice! thank you. i don't know why i spliced that thing, evaling just the procedure works. I guess for more complicated things, users should put the code on the load path. loading it is emacsy, but i think it would be easier for the user to do it this way.
<lampilelo>you can always use eval-in-sandbox if you want to restrict what can be used inside of the config file
<mwette>for rearch-replace in trees (aka deep lists) maybe (sxml fold), described here: https://wingolog.org/pub/fold-and-xml-transformation.pdf
<mwette>
<mwette>
<mwette>s/rearch/search/
<mwette>... can provide some ideas
<dsmith-work>Hey Hi Howdy, Guilers