[racket] bracket conversion?
I agree with John that even if pathological cases are not handled, that'd be fairly helpful.
I'm done with my manual porting of OOPLAI though, and thanks to the C-c C-[ shortcut, it was not that terrible.
My $2 (<- chilean pesos) report is that:
- most of it was converting `let' and friends (many of which are multi-lines), as well as `cond' and `case'
- a bit of PLAI's define-type / type-case
- the other big part of it was about custom macros
(eg. the OBJECT or CLASS macros that the text is about; in these cases the rules of which parenthesis should be squared could even be taken directly from the define-syntax definition (?))
-- Éric
On Nov 20, 2012, at 8:59 PM, John Clements wrote:
>
> On Nov 20, 2012, at 3:53 PM, Robby Findler wrote:
>
>> 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.
>
> Yep, that's exactly what I was thinking.
>
>>
>> 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)))
>
> I think this would wind up being nearly impossible. I think the first one could be occasionally incorrect (e.g. someone re-binds the identifier 'new', and then what look like initialization clauses should be treated as applications), but that seems like a small price to pay for the massive simplification.
>
> My guess: the whole thing would take about three days of work.
>
> John
>
>
>>
>> Robby
>>
>> On Tue, Nov 20, 2012 at 5:09 PM, John Clements
>> <clements at 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
>>>
>