I think one way to do it would be to use read-syntax to get the expression, but then also put the file into a string. Walk the expression and look for patterns that you want to change rounds to squares and then mutate the string and write the file back out again. Use the position field of the syntax object to tell you where to mutate the string.
You could even take a check-syntax like approach (it is more complex, tho) and fully expand the program. Then, when you find 'cond' in the origin field of some syntax object you can be sure it really is racket/base's cond and not some other thing like, eg (lambda (cond) (cond 3 (+ 1 2))) Robby On Tue, Nov 20, 2012 at 5:09 PM, John Clements <cleme...@brinckerhoff.org> wrote: > > On Nov 20, 2012, at 11:28 AM, Eric Tanter wrote: > >> Thanks John, that's very helpful! >> >> Any idea about a whole-file racketify in DrRacket? > > That's a toughy. What you want is to be able to invert (read-syntax). It > seems to me that such a thing should be possible in many of the racket > languages, but I'm not aware of an implementation. > > Actually, thinking about it harder, I suppose you have the original string > text of the file, as well, so that makes it a hugely easier; you just need a > predicate on the (un-expanded) syntax objects that can tell you whether a > syntax list should have square or round brackets. > > So, here's the $64K question: can you specify precisely which places need to > be changed? If so, it sounds like this is do-able. > > John > > > >> >> -- Éric >> >> >> On Nov 20, 2012, at 3:16 PM, John Clements wrote: >> >>> >>> On Nov 20, 2012, at 10:01 AM, Eric Tanter wrote: >>> >>>> Hi, >>>> >>>> I'm converting code written with only standard parentheses, introducing >>>> squared ones where appropriate. >>>> >>>> This is obviously not very fun (I'm converting all of OOPLAI), and it >>>> would be great if there'd be a way to select an open paren and "convert" >>>> it so that the matching closing paren is changed automatically. >>>> >>>> Is this feasible? >>>> >>> >>> I'm pretty sure Sam and I added this binding last year. C-c C-[ ? I think >>> you can look it up in the keybindings. >>>> >>> >>> John >>> >> > > > ____________________ > Racket Users list: > http://lists.racket-lang.org/users > ____________________ Racket Users list: http://lists.racket-lang.org/users