- Subject: Re: [slang-users] Newbie question
- From: "John E. Davis" <davis@xxxxxxxxxxxxx>
- Date: Mon, 8 Nov 2004 02:53:39 -0500
TJ Walls <twalls@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
> variable
> article = article_as_string(),
> % TJ: Ok, article_as_string returns a String_Type ...
> i = is_substr (article, "\n\n"),
Here, i represents the offset into article at the first occurance
of "\n\n". It is a "one-based" offset.
[...]
> header = article[[0:i-1]];
> % TJ: Here the problems start ... [0:i-1] is an array with
> % TJ: elements initialized from 0 to (i-1), ok but
> % TJ: article is a String_Type what does article[array] mean?
It is also a String_Type. For example, if
article = "abcdefg";
then article[[0,2,4,6]] represents the string "aceg"; So, in your
example, since i represents the location of "\n\n", article[[0:i-1]]
represents the string formed by the preceeding characters of article.
> % TJ: Is it the first i members of the string ... it would seem
> % TJ: we want the first i lines, but why does this work?
> body = article[[i:]];
> }
>
> % remove continuation lines from the header
> while (str_replace (header, "\n ", " "))
> % TJ: Ok, replace the first newline character with a single
> % TJ: whitespace ...
> header = ();
> % TJ: What does this mean!?
Unfortunately, the str_replace function was poorly conceived on my
part. It has been made obsolete by the strreplace function.
Instead of using
while (str_replace (header, "\n ", " "))
header = ();
use:
(header,) = strreplace (header, "\n ", " ", strlen (header));
Here, strreplace returns 2 values: the modified string and an
integer that indicates how many replacements were made. In
contrast, the str_replace function returns the modified string only
if a replacement has been made. This is what the "header=()"
statement is all about. I strongly urge you too read
http://www.jedsoft.org/slang/doc/html/slang-9.html#ss9.5
for more infomation about such constructs.
> while (str_replace (header, "\n\t", " "))
> header = ();
>
> % convert the header to an array of strings
> header = strtok (header, "\n");
> % TJ: Didn't we just replace all the newline characters??
No, you replaced the combinations "\n " and "\n\t", but not "\n".
> % do the actual sorting
> sortres = array_sort (header, cmp);
> header = header[sortres];
> % TJ: header was a String_Type ... now it seems to be an array
> % TJ: of strings??
Right. The strtok function returns an array of strings. So after
header = strtok (header, "\n");
header is an array.
> Thanks in advance for any advice for a newbie. Is there further
>documentation on S-lang beyond http://www.s-lang.org so that I might not
>bother you with such silly questions in the future?
>
> Also, does anyone know of a S-Lang editing mode for XEmacs?
Good luck.
--John
_______________________________________________
To unsubscribe, visit http://jedsoft.org/slang/mailinglists.html
[2004 date index]
[2004 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]