1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

gosub variables

Discussion in 'Support' started by grimblefritz, May 16, 2009.

  1. grimblefritz

    Joined:
    Feb 25, 2009
    Messages:
    16
    Likes Received:
    0
    The help for tc10 states that:

    :Sub1 [str n world]

    when called with:

    Gosub Sub1 abc 15 "Hello World"

    will result in

    str=abc
    n=15
    world="Hello World"

    This is fine. I love gosub vars. Furthermore, if the sub is called with:

    Gosub Sub1 abc 15

    that results in:

    str=abc
    n=15
    world=

    However, if you call the sub like this:

    Gosub Sub1 abc 15 My World

    then you get this:

    str=abc
    n=15
    world=My

    Did I miss something? Is there no way to make the last variable "greedy"? The result I would like to see is:

    world=My World

    I can't find a way to do this, but if I've missed it do tell! And if it's just not there, then add it to the wishlist :-)

    Thx
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    On Sat, 16 May 2009 19:54:28 -0500, grimblefritz <> wrote:

    |Gosub Sub1 abc 15 My World

    I'd try

    GOSUB Sub1 abc 15 `My World`
    --
    - Vince
     
  3. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,726
    Likes Received:
    80
    grimblefritz wrote:


    WAD - and changing this would break a LOT of existing code. (Would you
    expect batch variable %3 to include %4 - %n?)

    You can use double quotes around any args you want to combine.

    Rex Conn
    JP Software
     
  4. grimblefritz

    Joined:
    Feb 25, 2009
    Messages:
    16
    Likes Received:
    0
    Just because it WAD doesn't mean AD is the best it can be :-)

    No, I expect %3 to include only %3. However, I DO expect %3$ to include %4 - %n.

    So why not allow %pvar$, when %pvar is the last parameter of a gosub, to behave the same? That would be a NEW convention would break NO existing code.

    Yes, but then you have to write extra code to check for and strip quotes.

    So, speaking of quotes, I wish tcc had a true quote that combined enclosures, allowed variable and function expansion, protected from other special characters, but did not ADD the quotes themselves to the content. Basically a combination of " and `. Maybe ""string""? Such a quoting mode would make so many things so much easier -- instead of having to constantly account for whether or not things picked up extra content as a result of quoting. Especially nice if there was an option to swap the " and "" usage :-) But, after a couple decades (yes, I started with 4DOS 1.0) of dealing with it you get used to the quotes, but it makes them no less annoying.

    All that said, until something changes I will continue to WAR the existing limitations. TCC is still by far the best command shell for Windows.

    Thanks!
     
  5. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    On Tue, 19 May 2009 10:04:02 -0500, grimblefritz <> wrote:

    |---Quote---
    |You can use double quotes around any args you want to combine.
    |---End Quote---
    |
    |Yes, but then you have to write extra code to check for and strip quotes.

    SET arg=%@UNQUOTE[%arg], no checking necessary.
    --
    - Vince
     
  6. grimblefritz

    Joined:
    Feb 25, 2009
    Messages:
    16
    Likes Received:
    0
    I think having to remember to %@UNQUOTE throughout your code is in itself a form of checking.
     
  7. grimblefritz

    Joined:
    Feb 25, 2009
    Messages:
    16
    Likes Received:
    0
    Just FYI to follow up on this post and especially the quoting issue.

    A few months ago I decided to use TCC to code the back end of a small web project, fronted by the Abyss server. It is not too difficult for the most part. I've coded quite a bit of php, and contributed code to the haserl project, so between the two I have a good idea how to manage the data flow and other issues. Except for some http and cgi specific situations, TCC is up to the task.

    Nonetheless, I have shot the TCC effort in the head and reverted to PHP.

    I was able to WAR several problems, such as special character handling (via frequent calls to setdos), the lack of being able to reading scripts from stdin, and the absence of a meaningful array capability (especially associative arrays.) It is, however, the lack of a real quoting system in TCC that creates far more points for potential execution and security flaws than are worth the effort to WAR.

    With the addition of some of the features I've suggested, here and in other threads, it would be quite possible to code a decent web back end using TCC.
     
  8. NetMage

    Joined:
    Nov 18, 2009
    Messages:
    17
    Likes Received:
    0
    This issue still seems to be a problem to me.

    How can I pass parameters (e.g. partial directory paths) containing spaces to a subroutine in a useful way?
    1. The help is actually wrong - it shows that abc and "Hello World" results in the same type of variable value (saying abc yields "abc" and "Hello World" yields "Hello World" but in fact abc yields a value of abc without quotes).
    2. The post above suggesting redefining the parameter using set is specifically listed as not working in a subroutine in help, so %@UNQUOTE has to be sprinkled everywhere you reference the argument.
    3. backquotes have no special meaning when assigning parameter values to a subroutine, so `Hello World` yields a value of `Hello

    Any better suggestions? There really should be a way to reassign a subroutine parameter value, and/or a way to pass space containing parameter values to subroutines.
     
  9. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,177
    Likes Received:
    11
    Assign the parameters to local variables and go from there.
    Code:
    :foo [_arg1]
    set arg1=%unquote[%_arg1]
    rem do something with %arg1
    return
    
     
  10. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    You can put the multi-word parameter in a variable and pass the name of the variable to the subroutine.

    Code:
    set param=one two three
    gosub foo param
    quit
    
    :foo [varname]
    echo %[%varname]
    return
     

Share This Page