Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Kind of a out-of-curiosity question re. the "Function" command...

May
855
0
Just as a preface, all of the following is just for illustrative purposes only and not anything close to what I was trying to "accomplish".

Doing this:
Code:
Function MMM=`%1 %2 %3 %4 %5`
and entering this command:
Code:
Echo %@MMM[This Is a Test]
yeilds:
Code:
This Is a Test
pretty much what you would expect.

But doing this:
Code:
Function MMM=`%*`
and entering the same command:
Code:
Echo %@MMM[This Is a Test]
yeilds:
Code:
ECHO is OFF

Why is that?
 
Actually, Charles, no; although it really wouldn't make any practical difference in this case. "%$" is "the complete command tail, modified by SHIFT", whereas "%*" is "the complete command tail, unmodified by SHIFT", and since I am not (never will) be doing any "SHIFT" commands in this "application", it really doesn't matter in this case. (And frankly, that being the case, I have a slight bias for "%*"', I use "%$" only when I am explicitly doing shifts.)

- Dan

P. S. Thank you, Charles!!! You were correct!!!! I just did that "experiment" after originally hitting the "Save Changes" button on this; I thought "Just for the heck of let's see what this does...", and it does exactly what I would want it do. But do you know why "%*" doesn't work???
 
But do you know why "%*" doesn't work???

The Help page for "Function" says that "%$" does what you want, but doesn't mention "%*". Since the latter isn't mentioned, your function is presumably just returning "%*", regardless of the argument. So, the result you get is the same as doing "echo %*".
 
You are, of course, right as always, David. (My inability to see is, as oft mentioned before, a real handicap.) However, they not only do they not behave the way I would expect from the documentation, the "results" can actually be far worse (more on that at the bottom of this). So, to "illustrate" these things, here is a TCC "log".
Code:
   Sat  Dec 17, 2011  11:45:40p

ISO8601 plugin v1.1.1 loaded.
SafeChars plugin v1.5.7 loaded.

TCC  12.11.76   Windows 7 [Version 6.1.7601]
Copyright 2011  Rex Conn & JP Software Inc.  All Rights Reserved
Registered to Daniel Mathews
 
[Z:\]Function XPer=`%$`

[Z:\]Echo %@XPer[First 2ndParm Third 4th Fifth 6th Seventh]
First 2ndParm Third 4th Fifth 6th Seventh

[Z:\]Function XPer=`%*`

[Z:\]Echo %@XPer[First 2ndParm Third 4th Fifth 6th Seventh]
ECHO is OFF

[Z:\]Function XPer=`%3$`

[Z:\]Echo %@XPer[First 2ndParm Third 4th Fifth 6th Seventh]
Third 4th Fifth 6th Seventh

[Z:\]Function XPer=`%-3$`

[Z:\]Echo %@XPer[First 2ndParm Third 4th Fifth 6th Seventh]
2ndParm

So, from the documentation:

The parameter %-n$ means "the arguments from parameter 1 to n - 1".

However, the first parameter ("First"), is not being printed.

Code:
[Z:\]Function XPer=`%-2$`

[Z:\]Echo %@XPer[First 2ndParm Third 4th Fifth 6th Seventh]
ECHO is OFF

Again, the first parameter is not being printed (kind of obviously, I would say).

Code:
[Z:\]Function XPer=`%-1$`

[Z:\]Echo %@XPer[First 2ndParm Third 4th Fifth 6th Seventh]

And here is the end of the whole thing, because at this point TCC just crashed. (Since I knew it was going to crash from a previous run-through, I saved this to a file before I issued the above command.)

What's kind of remarkable to me is that nobody (apparently even you) has "noticed" this behavior before.

- Dan
 

Similar threads

Back
Top