Rewrap "> " lines from file ?

This is a discussion on Rewrap "> " lines from file ? within the Scheme forums in Programming Languages category; 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 ...

Go Back   Application Development Forum > Programming Languages > Scheme

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-17-2008, 10:03 PM
problems@gmail
Guest
 
Default Rewrap "> " lines from file ?

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.

Reply With Quote
  #2  
Old 08-20-2008, 09:32 PM
Rob Warnock
Guest
 
Default Re: Rewrap "> " lines from file ?

<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

Reply With Quote
  #3  
Old 08-21-2008, 11:44 AM
Bakul Shah
Guest
 
Default Re: Rewrap "> " lines from file ?

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.
Reply With Quote
  #4  
Old 08-21-2008, 12:22 PM
Icarus Sparry
Guest
 
Default Re: Rewrap "> " lines from file ?

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.
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 08:26 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.