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: Why do `test' and a`test' make a difference?
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Why do `test' and a`test' make a difference?
Date
Mon, 11 Feb 2013 13:24:40 +0000
Daniel's excellent, thorough answer is difficult to gloss.
Cory's elegant summary "Stata kinda sucks with strings..." is,
however, I think a little hard and so some more general comments seem
in order.
Every programming or command language of substance faces a challenge
that once you give specific syntactic meaning to certain characters,
then you make it more difficult to use those characters with their
standard, customary or literal meanings. Also, you may get bitten by
forgetting or not knowing about the difference. (Me too, naturally.)
Also, programmers in my experience tend to get accustomed to the
particular choices made in a certain language and then are inclined to
regard other solutions in other languages as defective or at least
strange.
Stata is quirky in wanting to interpret `stuff' as a reference to a
local macro named stuff. Extensions of that syntax `: ' and `= ' may
seem equally strange. So, that can get complicated when you want
either or both single quotation marks for other purposes.
The original syntax for local macro references was fairly ugly
%_stuff was a reference to what was defined by
mac def _stuff "some stuff"
You can still use that under version control!
Nick
On Mon, Feb 11, 2013 at 11:53 AM, daniel klein
<[email protected]> wrote:
> As for Jeph's request for a systematic account of how word lists are
> parsed, I think this is explained in the manuals and is more about
> macro expansion than lists of words.
>
> When you type
>
> `: word 1 of `test''
>
> Stata sees
>
> `: word 1 of Jeph's Example'
>
> since `: word 1 of Jeph' expands to Jeph, you get
>
> Jephs Example'
>
> When you type
>
> : word 1 of `test'
>
> Stata sees
>
> : word 1 of Jeph's Example
>
> which expands to Jeph's
>
> When you type
>
> `"`:word 1 of `test''"'+"[ ]"+`"`:word 2 of `test''"'
>
> Stata sees
>
> `"`: word 1 of Jeph's Example'"' + "[]" + `"`: word 2 of Jeph's Example'"''
>
> we already coverd the first part of this, so lets take a look on the
> second. Since `: word 2 of Jeph' is an empty string teh hole
> expression becomes
>
> `"Jephs Example'[]s Example'"'
>
>
> These outputs might not be what you want, but exactly what you would
> expect following Stata's logic of macro expansion. Thre is nothing
> unsensical or mysterious about it.
>
> Best
> Daniel
> --
> It's getting tripped up by the apostrophe in test since it's a
> character with special meaning. Stata kinda sucks with strings...
>
> Try local test "Jephs Example" and it will be more sensical.
>
> On Sun, Feb 10, 2013 at 10:10 PM, Jeph Herrin <[email protected]> wrote:
>> I'd like a systematic account of how word lists are parsed. For instance, I
>> have been scratching my head over the output of this:
>>
>> local test "Jeph's Example"
>> local wordA `: word 1 of `test''
>> local wordB : word 1 of `test'
>> local wordC =`"`:word 1 of `test''"'+"[ ]"+`"`:word 2 of `test''"'
>> di "`wordA'"
>> di "`wordB'"
>> di "`wordC'"
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/