Hi :) On Tue 05 Apr 2016 16:05, iyzs...@member.fsf.org (宋文武) writes:
> Andy Wingo <wi...@igalia.com> writes: > >> In that case I think the ideal is something like "edit-expression", >> which takes a source location that starts an expression, uses "read" to >> advance to the end of the expression, then edits the intervening string >> using whatever but verifies that the result can still be read as one >> expression. Having recorded the absolute byte positions of the start >> and end of the expression, you can then create the output by doing an >> efficient bytevector read of the prologue, then display the string for >> the edited expression, then the bytevector tail. >> >> Again, just a thought! Feel free to incorporate or not as you like, >> 宋文武 :) > Indeed this is better! To create the output from bytevector, it's > using `get-bytevector-n' to read and `utf8->string' to write, right? Hmm, good question. I think I would use put-bytevector, if I read using get-bytevector-n, assuming that the encoding of the input and the output ports were the same. Probably it is worth making sure that you set the encodings to be the same, but I don't know :) Hopefully everything is UTF-8 these days. > And I think `edit-expression' could be: > (define (edit-expression source-properties proc) > "Edit the object specified by SOURCE-PROPERTIS using PROC, which > should be a procedure that take the original object and returns > a new one." > ...) Yeah :) However probably the "proc" should take and return a string, so as to preserve formatting and comments. Good luck :) Andy