Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Behavior of word function in local macro

    Why does method2 produce the "desired" result, whereas method1 does not? I assume it has to do with differences in word-boundary rules, but I cannot find documentation on it. Thanks in advance!

    Code:
    . local nestedList "a b c" "x y z" "s t u"
    
    . local method1 = word("`nestedList'", 2)
    
    . local method2: word 2 of "`nestedList'"
    
    . macro list
    _nestedList:    a b c" "x y z" "s t u
    _method1:       b
    _method2:       x y z

  • #2
    This is explained in the respective documentations. From

    Code:
    help macro
    Macro functions for parsing

    word count string
    returns the number of words in string. A token is a word (characters separated by spaces) or set of words enclosed in quotes. Do not enclose string in
    double quotes because word count will return 1.

    word # of string
    returns the #th token of string.
    Do not enclose string in double quotes.
    whereas from

    Code:
    help word()
    word(s,n)
    Description: the nth word in s; missing ("") if n is missing

    Positive numbers count words from the beginning of s, and negative numbers count words from the end of s. (1 is the first word in s, and -1 is the
    last word in s.) A word is a set of characters that start and terminate with spaces. This is different from a Unicode word, which is a language
    unit based on either a set of word-boundary rules or dictionaries for several languages (Chinese, Japanese, and Thai).

    So the -word()- function identifies words using spaces and nothing else.

    Comment


    • #3
      I was mostly wrong in my earlier post; now edited.

      Still, you probably want to define the local macro as

      Code:
      local nestedList `""a b c" "x y z" "s t u""' // <- note compound double quotes
      Last edited by daniel klein; 21 Dec 2023, 01:30.

      Comment

      Working...
      X