Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Uppercase arguments for programs


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Uppercase arguments for programs
Date   Fri, 3 Feb 2012 10:08:05 +0000

Here is a proof of concept:

program uppercaseoption
	version 8
	gettoken comma 0 : 0, parse(",")
	gettoken optname 0 : 0, parse("(")
	if "`optname'" != "K" error 198
	local K = `0'
	confirm integer number `K'

	di "K() option returned " `K'
end

Test with e.g. -uppercaseoption, K(7)-

Nick

On Fri, Feb 3, 2012 at 2:55 AM, Nick Cox <[email protected]> wrote:
> Arguments are a wider class than options. Thus a command given the
> arguments "frog toad newt" makes no use of options, and the arguments
> need not even be variable names. Immediate commands are an important
> class.
>
> So, the answer to your question is yes, as upper case text can easily
> be passed to programs. Also, even with options, an example from the
> past lives into the present in what since Stata 8 is called -graph7-
> which has an option -Rescale-.
>
> But evidently  the heart of your question is whether options defined
> by -syntax- can have upper case names, and to that  I guess No in so
> far as upper case in a -syntax- statement indicates minimal
> abbreviation, not capitalization.
>
> I guess with some effort and clever use of -gettoken- rather than
> -syntax- that could be by-passed, but it seems like hard work even to
> contemplate.
>
> Nick
>
> On Fri, Feb 3, 2012 at 2:04 AM, Bert Lloyd <[email protected]> wrote:
>
>> Is there a way to use uppercase arguments for programs? The use of
>> uppercase letters to designate the required portion of the argument's
>> name seems to prevent this.
>>
>> Consider the following simple example:
>>
>> --- begin example code ---
>>
>> cap program drop uppercase_argument
>> program define uppercase_argument
>>    syntax, K(integer)
>>
>>    di "there are `K' right-hand-side variables"
>>    di "there are `k' right-hand-side variables"
>>
>>    local K = `k'
>>
>>    di "there are `K' right-hand-side variables"
>> end
>>
>> capture noisily uppercase_argument, K(3)
>> di _rc
>>
>> capture noisily uppercase_argument, k(3)
>>
>> --- end example code ---
>>
>> This yields the following output:
>>
>> --- begin output ---
>> . capture noisily uppercase_argument, K(3)
>> option k() required
>>
>> . di _rc
>> 198
>>
>> .
>> . capture noisily uppercase_argument, k(3)
>> there are  right-hand-side variables
>> there are 3 right-hand-side variables
>> there are 3 right-hand-side variables
>>
>> --- end output ---
>>
>> There is a workaround that involves creating new local macros within
>> the program, e.g. in the above a line like
>>
>> local K = `k'
>>
>> but this is tedious and leads to errors, both from simple typos and
>> from Alice's White Knight "what the name of the song is called" type
>> mistakes confounding the macro with the name of the macro, etc.
>>
>> Many thanks in advance for any suggestions.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index