| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| I want to promote the idea that 'we should use a higher level langauge, like lisp or scheme'. But I don't yet have enough fluency to give a good example. A suitable and not too big a task, to serve as a comparison against the currently used languages would be: rearrange a small text file, so that: * all lines of length > 78 are wrapped to len < 75, with breaks at word-boundries; * the "> " strings which start each line are replaced to the beginning of the new shorter lines; I guess something like this might do it: * delete all line-breaks and "> "; * Initialise counter/s; * While Not eof do write("> "); While lineNotFull do write(NextWord); Inc(lineLen by wordLen) EndWhile lineNotFull; EndWhile Not eof. I've got elisp ver xxx to start with - and an undocumented Scheme, which runs a graphics application, which I've tested on simple functions, but I don't know the syntax to: ' read/write in/out text from/to a file'. Please provide some source for the folowing skeleton, which could get me started: 1. Init files if needed; 2. For lines = 1st till last or eol do ReadLine from InFile & count chars; To OutFile write "line n =", lines 3. To OutFile write "Done". == TIA. |
|
#2
| |||
| |||
| <problems@gmail> wrote: +--------------- | I want to promote the idea that 'we should use a higher level langauge, | like lisp or scheme'. But I don't yet have enough fluency to give a good | example. A suitable and not too big a task, to serve as a comparison | against the currently used languages would be: | | rearrange a small text file, so that: | * all lines of length > 78 are wrapped to len < 75, with breaks at | word-boundries; | * the "> " strings which start each line are replaced to the beginning | of the new shorter lines; +--------------- As much as I like Lisp, this tiny task simply cries out for a "one-liner" shell script! sed -s 's/^> //' ${1+"$@"} | fmt -75 | sed -s 's/^/> /' -Rob ----- Rob Warnock <rpw3@rpw3.org> 627 26th Avenue <URL:http://rpw3.org/> San Mateo, CA 94403 (650)572-2607 |
|
#3
| |||
| |||
| Rob Warnock wrote: > <problems@gmail> wrote: > +--------------- > | I want to promote the idea that 'we should use a higher level langauge, > | like lisp or scheme'. But I don't yet have enough fluency to give a good > | example. A suitable and not too big a task, to serve as a comparison > | against the currently used languages would be: > | > | rearrange a small text file, so that: > | * all lines of length > 78 are wrapped to len < 75, with breaks at > | word-boundries; > | * the "> " strings which start each line are replaced to the beginning > | of the new shorter lines; > +--------------- > > As much as I like Lisp, this tiny task simply cries out > for a "one-liner" shell script! > > sed -s 's/^> //' ${1+"$@"} | fmt -75 | sed -s 's/^/> /' > Your one-liner doesn't meet the spec. The way I read it, all long lines are folded to be < 75 chars long but "> " is prepended only for folded lines that start with a "> ". The OP doesn't specify it but I think he'd want the "> " prepended lines to be < 75 chars long as well. |
|
#4
| |||
| |||
| On Wed, 20 Aug 2008 20:32:47 -0500, Rob Warnock wrote: > <problems@gmail> wrote: > +--------------- > | I want to promote the idea that 'we should use a higher level > langauge, | like lisp or scheme'. But I don't yet have enough fluency > to give a good | example. A suitable and not too big a task, to serve > as a comparison | against the currently used languages would be: | > | rearrange a small text file, so that: | * all lines of length > 78 are > wrapped to len < 75, with breaks at | word-boundries; > | * the "> " strings which start each line are replaced to the beginning > | of the new shorter lines; > +--------------- > > As much as I like Lisp, this tiny task simply cries out for a > "one-liner" shell script! > > sed -s 's/^> //' ${1+"$@"} | fmt -75 | sed -s 's/^/> /' > > > -Rob > > ----- > Rob Warnock <rpw3@rpw3.org> > 627 26th Avenue <URL:http://rpw3.org/> San Mateo, CA 94403 > (650)572-2607 There is also a very nice program "par" http://www.nicemice.net/par that does everything requested and much more. From the manual page examples Before: /* We the people of the United States, */ /* in order to form a more perfect union, */ /* establish justice, */ /* insure domestic tranquility, */ /* provide for the common defense, */ /* promote the general welfare, */ /* and secure the blessing of liberty */ /* to ourselves and our posterity, */ /* do ordain and establish the Constitution */ /* of the United States of America. */ After "par 59": /* We the people of the United States, in */ /* order to form a more perfect union, establish */ /* justice, insure domestic tranquility, provide */ /* for the common defense, promote the general */ /* welfare, and secure the blessing of liberty */ /* to ourselves and our posterity, do ordain */ /* and establish the Constitution of the United */ /* States of America. */ Most web searches for this program end up at http://www.cs.berkeley.edu/~amc/Par but this no longer seems to be valid. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.