🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.readers
8 messages
8 total messages Started by asf... Lloyd Zusman Mon, 07 Jul 1997 00:00
Generating vararg slrn intrinsic at run time ... ???
#34922
Author: asf... Lloyd Zusman
Date: Mon, 07 Jul 1997 00:00
36 lines
1674 bytes

I'm trying to do a somewhat tricky thing in an slrn macro.  This
requires making use of some of the intricacies of s-lang, but even
though I've read the slrn docs as well as the s-lang docs, I still
haven't been able to figure out how to do what I want to do.

The idea is this:  in my macro, I have a string that consists of a
comma-separated list of values, such as this ...

   "value1,value2, ... ,valueN"

The number of comma-separated components in this string is arbitrary,
and this is only known at run time.

What I'd like to do is to split this string into its components and then
generate the following call ...

   rsp = get_select_box_response ("Choose one:",
                                  "value1", "value2", ... , "valueN",
				  N);

I know that I can use the s-lang 'strchop' intrinsic to split the
string and push the components and the number of components onto the
stack. What I don't know how to do is to assemble the call to
'get_select_box_response' from these items on the stack.

Any ideas?

Thanks in advance.


-- 
 Lloyd Zusman
 l...@asfast.com
Re: Generating vararg slrn intrinsic at run time ... ???
#34902
Author: asf... Lloyd Zusman
Date: Mon, 07 Jul 1997 00:00
24 lines
1409 bytes

On 7 Jul 1997 15:18:51 GMT, John E. Davis <da...@space.mit.edu> wrote:
> On 7 Jul 1997 12:43:45 GMT, Lloyd Zusman <asf...@asfast.com>
> wrote:
> >I know that I can use the s-lang 'strchop' intrinsic to split the
> >string and push the components and the number of components onto the
> >stack. What I don't know how to do is to assemble the call to
> >'get_select_box_response' from these items on the stack.
> 
> Use the _stkdepth () intrinsic function.  Here is an example:
> 
> [ ... etc. ... ]

It's nice to be able to play with the stack like this.  SLang gives us
the advantages of languages like Forth along with the advantages of
languages like C.



-- 
 Lloyd Zusman
 l...@asfast.com
Re: Generating vararg slrn intrinsic at run time ... ???
#34912
Author: da... John E. Davis
Date: Mon, 07 Jul 1997 00:00
86 lines
2481 bytes

On 7 Jul 1997 12:43:45 GMT, Lloyd Zusman <asf...@asfast.com>
wrote:
>I know that I can use the s-lang 'strchop' intrinsic to split the
>string and push the components and the number of components onto the
>stack. What I don't know how to do is to assemble the call to
>'get_select_box_response' from these items on the stack.

Use the _stkdepth () intrinsic function.  Here is an example:

define get_color_for_object (title)
{
   variable n;
   
   n = _stkdepth ();
   return select_list_box (title,
			   "black",
			   "red",
			   "green",
			   "brown",
			   "blue",
			   "magenta",
			   "cyan",
			   "lightgray",
			   "gray",
			   "brightred",
			   "brightgreen",
			   "yellow",
			   "brightblue",
			   "brightmagenta",
			   "brightcyan",
			   "white",
			   "default",
			   _stkdepth () - n - 1,
			   0);
}

define color ()
{
   variable n, fg, bg;
   variable obj;
   
   n = _stkdepth ();
   obj = select_list_box ("Object",    %  title
			  
			  "normal",
			  "status",
			  "menu",
			  "menu_press",
			  "headers",
			  "group",
			  "subject",
			  "author",
			  "error",
			  "cursor",
			  "article",
			  "tree",
			  "quotes",
			  "signature",
			  "thread_number",
			  "header_number",
			  "high_score",
			  "description",
			  "grouplens_display",
			  "tilde",
			  "header_name",
			  "response_char",
			  "box",
			  "frame",
			  "selection",
			  _stkdepth () - n - 1,
			  0);
   
   fg = get_color_for_object (strcat ("Foreground for ", obj));
   bg = get_color_for_object (strcat ("Background for ", obj));
   
   set_color (obj, fg, bg);
}


-- 
John E. Davis                   Center for Space Research/AXAF Science Center
617-258-8119                    MIT 37-662c, Cambridge, MA 02139
http://space.mit.edu/~davis
Re: Generating vararg slrn intrinsic at run time ... ???
#34913
Author: ol... Olly Betts
Date: Mon, 07 Jul 1997 00:00
28 lines
1325 bytes

In article <slrn5s1os...@ljz.asfast.net>, Lloyd Zusman wrote:
>What I don't know how to do is to assemble the call to
>'get_select_box_response' from these items on the stack.

Just use "get_select_box_response;" and it will take its arguments from the
stack.  Here's an example (not very useful in its current form):

define list_refs ()
{
   variable refs = extract_article_header( "References" );
   
   % push title onto stack
   "Message-Ids of parent messages";
   
   strchop( refs, ' ', 0 );
      
   variable answer = get_select_box_response;

   message ( Sprintf( "You picked %d", answer, 1 ));
}

Cheers,
Olly
-- 
Don't send a man to do a buoy's job.
Re: Generating vararg slrn intrinsic at run time ... ???
#34915
Author: da... John E. Davis
Date: Mon, 07 Jul 1997 00:00
32 lines
1937 bytes

On 7 Jul 1997 15:10:40 GMT, Jan Hlavacek <lah...@math.ohio-state.edu>
wrote:
>get_select_box_response ("Choose one:", strchop (my_string)); ?

Actually, the call should be:

  get_select_box_response ("Choose one:", strchop (my_string, ',', 0));

My previous suggestion about using _stkdepth can be ignored in this
case since strchop returns the number of strings.

Here is the documentation on the strchop function:

Prototype: Integer strchop (String str, Integer delim, Integer quote);
      This routine decomposes a string `str' into a series of substrings 
      and returns the substrings to the stack along with the number of 
      substrings.
      The string `str' is assumed to consist of the substrings delimited 
      by `delim'.  The character `quote' is assumed to quote the delimiter.
      For example,
            strchop ("apples,oranges,pears", ',', 0);
      will return `3' to the top of the stack followed by the three strings:
      `"apples"', `"oranges"', and `"pears"'
      Related Functions: `strchopr', `extract_element'

-- 
John E. Davis                   Center for Space Research/AXAF Science Center
617-258-8119                    MIT 37-662c, Cambridge, MA 02139
http://space.mit.edu/~davis
Re: Generating vararg slrn intrinsic at run time ... ???
#34917
Author: asf... Lloyd Zusman
Date: Mon, 07 Jul 1997 00:00
51 lines
2432 bytes

On 7 Jul 1997 15:10:40 GMT, Jan Hlavacek <lah...@math.ohio-state.edu> wrote:
> On 7 Jul 1997 12:43:45 GMT, Lloyd Zusman <asf...@asfast.com> wrote:
> >
> > [ ... ]
> >
> >What I'd like to do is to split this string into its components and then
> >generate the following call ...
> >
> >   rsp = get_select_box_response ("Choose one:",
> >                                  "value1", "value2", ... , "valueN",
> >				  N);
> >
> >I know that I can use the s-lang 'strchop' intrinsic to split the
> >string and push the components and the number of components onto the
> >stack. What I don't know how to do is to assemble the call to
> >'get_select_box_response' from these items on the stack.
> 
> Did you try simply calling
> 
> 
> get_select_box_response ("Choose one:", strchop (my_string)); ?
> 
> If this doesn't work,  perhaps 
> 
> "Choose one:";
> strchop (my_string);
> get_select_box_response ();
> 
> would do.

(sigh) Yes, both of those work.  I never thought of trying the first
one because it would have been invalid in most of the other,
similar-looking languages I've used (C, C++, Java, Perl, etc.).  I
shouldn't have made that assumption.  And I must have typed something
wrong when I initially tried the second method.

So, thank you.

By the way, for any of you who are interested in learning more about
why this works s-lang, look in the slang/doc directory.  The
'slang.tex' file talks about the structure of that language, and there
are other useful pieces of documentation there, as well.  Build the
'texconv' program in that directory and then use it to convert the tex
files into ASCII if you don't have TeX available.

-- 
 Lloyd Zusman
 l...@asfast.com
Re: Generating vararg slrn intrinsic at run time ... ???
#34924
Author: lah... Jan Hlavacek
Date: Mon, 07 Jul 1997 00:00
48 lines
2180 bytes

On 7 Jul 1997 12:43:45 GMT, Lloyd Zusman <asf...@asfast.com> wrote:
>I'm trying to do a somewhat tricky thing in an slrn macro.  This
>requires making use of some of the intricacies of s-lang, but even
>though I've read the slrn docs as well as the s-lang docs, I still
>haven't been able to figure out how to do what I want to do.
>
>The idea is this:  in my macro, I have a string that consists of a
>comma-separated list of values, such as this ...
>
>   "value1,value2, ... ,valueN"
>
>The number of comma-separated components in this string is arbitrary,
>and this is only known at run time.
>
>What I'd like to do is to split this string into its components and then
>generate the following call ...
>
>   rsp = get_select_box_response ("Choose one:",
>                                  "value1", "value2", ... , "valueN",
>				  N);
>
>I know that I can use the s-lang 'strchop' intrinsic to split the
>string and push the components and the number of components onto the
>stack. What I don't know how to do is to assemble the call to
>'get_select_box_response' from these items on the stack.

Did you try simply calling


get_select_box_response ("Choose one:", strchop (my_string)); ?

If this doesn't work,  perhaps 

"Choose one:";
strchop (my_string);
get_select_box_response ();

would do.

lahvak
-- 
Jan Hlav\'{a}\v{c}ek
lah...@math.ohio-state.edu  (Blind Carbon Copies will bounce)
www: http://www.math.ohio-state.edu/~lahvak/  is back!

Re: Generating vararg slrn intrinsic at run time ... ???
#35120
Author: lah... Jan Hlavacek
Date: Mon, 14 Jul 1997 00:00
21 lines
1607 bytes

On 7 Jul 1997 17:03:18 GMT, Lloyd Zusman <asf...@asfast.com> wrote:
>By the way, for any of you who are interested in learning more about
>why this works s-lang, look in the slang/doc directory.  The
>'slang.tex' file talks about the structure of that language, and there
>are other useful pieces of documentation there, as well.  Build the
>'texconv' program in that directory and then use it to convert the tex
>files into ASCII if you don't have TeX available.
>

Or visit 
http://www.math.ohio-state.edu/~lahvak/software/slang/slang.html

lahvak
-- 
Jan Hlav\'{a}\v{c}ek <lah...@math.ohio-state.edu>  (BCC's will bounce)
home page: http://www.math.ohio-state.edu/~lahvak/
slrn page: http://www.math.ohio-state.edu/~lahvak/software/slrn.html
slrn documentation: http://www.math.ohio-state.edu/~lahvak/software/slrn/
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads