www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Proposal for a Rosettacode task

reply "bearophile" <bearophileHUGS lycos.com> writes:
I keep most discussions about Rosettacode tasks in the D.learn 
newsgroup, but perhaps this time this is of interest of more 
people.

I have created an empty Task in that site that I think is 
particularly fit for D compile-time evaluation and code 
generation (it's probably also fit for Lisp macros), and perhaps 
a D solution for this little coding problem could even be useful:

http://rosettacode.org/wiki/ASCII_art_diagram_converter

A D solution is welcome.

Bye,
bearophile
Oct 18 2013
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Saturday, 19 October 2013 at 00:19:34 UTC, bearophile wrote:
 A D solution is welcome.
I implemented one solution: http://arsdnet.net/dcode/asciiarttable.d My parser is kinda minimal, it just counts the bits and doesn't strictly validate, though there are some asserts there. It also supports larger values like: +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | ID | | | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ is 32 bits. It makes a ubyte[size] to hold the data, ensuring the exact layout the diagram proscribes without worrying too much about endianness. It uses property functions for getting and setting everything, with asserts to ensure things are in the right range. Anyway, the make thing is a code generator that spits out an anonymous struct. You can just mix it in to a named struct (as I did in the file there) to use it.
Oct 18 2013
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Adam D. Ruppe:

 I implemented one solution:

 http://arsdnet.net/dcode/asciiarttable.d
Tomorrow I'll take a better look at it. Are you willing for your code to be put in the Rosettacode site? Bye, bearophile
Oct 18 2013
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Saturday, 19 October 2013 at 03:33:12 UTC, bearophile wrote:
  Are you willing for your code to be put in the Rosettacode 
 site?
sure. I didn't format it but if you convert my tabs to spaces and maybe break up some long lines it should be good. (I use awfully long lines when doing code generators...)
Oct 18 2013
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Adam D. Ruppe:

 sure. I didn't format it but if you convert my tabs to spaces 
 and maybe break up some long lines it should be good.
Good, I have reformatted the code (I have chosen a narrow 72/73 line width for the code in that site, to see it well on smaller screens or larger fonts), and I have tried to improve it a little in many details: http://rosettacode.org/wiki/ASCII_art_diagram_converter The signature of the nested routine now takes all the variables it works on. I think this code makes it more clear that this routine needs to modify all those variables: static void commitCurrent(ref uint anonCount, ref uint totalBits, ref uint currentBits, ref string code, ref string currentName) pure safe { If you want to modify code I suggest you to modify it directly on that site. Bye, bearophile
Oct 19 2013
parent reply "Daniel Davidson" <nospam spam.com> writes:
On Saturday, 19 October 2013 at 10:58:11 UTC, bearophile wrote:
 Adam D. Ruppe:

 sure. I didn't format it but if you convert my tabs to spaces 
 and maybe break up some long lines it should be good.
Good, I have reformatted the code (I have chosen a narrow 72/73 line width for the code in that site, to see it well on smaller screens or larger fonts), and I have tried to improve it a little in many details: http://rosettacode.org/wiki/ASCII_art_diagram_converter The signature of the nested routine now takes all the variables it works on. I think this code makes it more clear that this routine needs to modify all those variables: static void commitCurrent(ref uint anonCount, ref uint totalBits, ref uint currentBits, ref string code, ref string currentName) pure safe { If you want to modify code I suggest you to modify it directly on that site. Bye, bearophile
I get following errors when trying to run: STDERR| asciiart.d(17): Error: pure function 'commitCurrent' cannot call impure function 'text' STDERR| asciiart.d(17): Error: safe function 'asciiart.makeStructFromDiagram.commitCurrent' cannot call system function 'std.conv.text!(uint).text' Thanks Dan
Oct 19 2013
parent "bearophile" <bearophileHUGS lycos.com> writes:
Daniel Davidson:

 I get following errors when trying to run:

 STDERR| asciiart.d(17): Error: pure function 'commitCurrent' 
 cannot call impure function 'text'
 STDERR| asciiart.d(17): Error: safe function 
 'asciiart.makeStructFromDiagram.commitCurrent' cannot call 
 system function 'std.conv.text!(uint).text'
Rosettacode entries are designed to work with the latest updates of the compiler. In dmd 2.064beta2 text is pure. Bye, bearophile
Oct 19 2013