Re: [racket-users] IO in racket is painful

2017-07-22 Thread Matthew Butterick
> On Jul 22, 2017, at 12:30 PM, David Storrs wrote: > > One thing that would solve a lot of this issue would be if the pregexp syntax > added support for named captures as in Perl and the PCRE library that exports > them. > > Alternatively, if 'match' made the

Re: [racket-users] IO in racket is painful

2017-07-22 Thread David Storrs
Oh, cool. I did not know about that. Thanks, Jon. On Sat, Jul 22, 2017 at 4:49 PM, Jon Zeppieri wrote: > On Sat, Jul 22, 2017 at 3:30 PM, David Storrs > wrote: > > > > Alternatively, if 'match' made the results of a successful regexp test > >

Re: [racket-users] IO in racket is painful

2017-07-22 Thread Jon Zeppieri
On Sat, Jul 22, 2017 at 3:30 PM, David Storrs wrote: > > Alternatively, if 'match' made the results of a successful regexp test > available to the bodies on the RHS then you could do the same thing by > accessing the result list. Perhaps if match would allow the RHS to be

Re: [racket-users] IO in racket is painful

2017-07-22 Thread David Storrs
One thing that would solve a lot of this issue would be if the pregexp syntax added support for named captures as in Perl and the PCRE library that exports them. Something like this: #lang at-exp racket (define str "[04, foo, 03.5]") (define pat @(pregexp @~a{\[(?\d+),\s*(?\w+),\s*(?[.\d]+)}))

Re: [racket-users] IO in racket is painful

2017-07-21 Thread Gustavo Massaccesi
IIRC the previous discussion, one way to fix this problem is to make a package that can parse strings easily using a C like format, like the expected in the contests. Something like #lang racket (require compatibility/scanf) (let-values ([(x y) (scanf "%d %d" (read-line))]) (display (+ x y)))

Re: [racket-users] IO in racket is painful

2017-07-21 Thread Brian Mastenbrook
On 07/21/2017 12:49 PM, Matthias Felleisen wrote: On Jul 21, 2017, at 1:56 AM, Sorawee Porncharoenwase wrote: Sorry for reviving an old thread. As someone who did a lot of programming competition in the past, I can totally see why IO in Racket is

Re: [racket-users] IO in racket is painful

2017-07-21 Thread Neil Van Dyke
Racket's underlying I/O seems sophisticated to me, and contest-friendly parsing conveniences can be layered atop that. IIRC, a long time ago, Olin Shivers made some parsing stuff for Scheme, which you might want to steal or at least look at. I'm not sure where it all went, or who else was

Re: [racket-users] IO in racket is painful

2017-07-21 Thread Matthias Felleisen
> On Jul 21, 2017, at 1:56 AM, Sorawee Porncharoenwase > wrote: > > Sorry for reviving an old thread. As someone who did a lot of programming > competition in the past, I can totally see why IO in Racket is difficult. As > mark.engelberg said, the goal is

Re: [racket-users] IO in racket is painful

2017-07-20 Thread Sorawee Porncharoenwase
Sorry for reviving an old thread. As someone who did a lot of programming competition in the past, I can totally see why IO in Racket is difficult. As mark.engelberg said, the goal is to solve as many problems as possible. After the competition is over, it's over. No one is going to care about

Re: [racket-users] IO in racket is painful

2016-03-31 Thread m . eckenbach
Isn't it true that the scanf format string is just a poor man's regular expression pattern (i.e. just character classes) that however also allows you to specify how to convert matches? It may be a succinct notation, but it is also misleading (for example, a single space in the format string

Re: [racket-users] IO in racket is painful

2016-03-22 Thread Mark Engelberg
On Tue, Mar 22, 2016 at 9:20 PM, Stephen Chang wrote: > :) I had started writing up a parsack example, and I was all set to > admonish the OP for not creating a parser when you want a parser but > then I saw it was for a programming contest where I guess this sort of >

Re: [racket-users] IO in racket is painful

2016-03-22 Thread Stephen Chang
> It may be overkill for this use case, but I would probably use the > parsack package, since I think its interface is pretty intuitive. :) I had started writing up a parsack example, and I was all set to admonish the OP for not creating a parser when you want a parser but then I saw it was for a

Re: [racket-users] IO in racket is painful

2016-03-22 Thread Alexis King
Honestly, judging from the responses in this thread, it would seem there may be a hole in Racket’s toolbox. Nothing I’ve seen so far is particularly stellar, especially since this is a problem that does not seem like it should be hard. It may be overkill for this use case, but I would probably

Re: [racket-users] IO in racket is painful

2016-03-22 Thread Mark Engelberg
Hi, I have coached several teams on using Racket in programming contests. In our local contests, the most common input format is to have one line per dataset, and each dataset is typically several pieces of data separated by spaces. For this common input format, the 2htdp/batch-io teachpack is

Re: [racket-users] IO in racket is painful

2016-03-22 Thread WarGrey Gyoudmon Ju
On Wed, Mar 23, 2016 at 8:26 AM, WarGrey Gyoudmon Ju wrote: > In Racket, (read) and (write) know all the builtin datatypes > > which > are already structured more than a stream of

Re: [racket-users] IO in racket is painful

2016-03-22 Thread WarGrey Gyoudmon Ju
In Racket, (read) and (write) know all the builtin datatypes which are already structured more than a stream of bytes (like in C). Thus, you don't need scanf to tell Racket what is the type of the next token.

Re: [racket-users] IO in racket is painful

2016-03-22 Thread Stephen Chang
A "read" variant that works with format strings would be a useful addition I think. Matthew, your solution is clever :) (but with symbols instead of strings). Another alternative could be to use match: #lang racket (define (trim-brackets str) (string-trim str #rx"\\[|\\]|,")) (define (pad n

Re: [racket-users] IO in racket is painful

2016-03-22 Thread Matthew Butterick
> Then, for all rows, read and split the string. The best that i have found to > do that is using regular expressions. > > (define split-row (regexp-match #rx"\\[(.+), (.+), (.+)\\]" (read-line))) > > Then you have to manually convert the substrings into values > > (define a

[racket-users] IO in racket is painful

2016-03-22 Thread rom cgb
Hi, I recently started using Racket and i couldn't find a good alternative to C's scanf/printf in the racket standard library. When doing programming challenges, you often need to comply to a specific input/ouput thus having something like scanf for string to values and printf for values to