Announcement

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

  • why this is an invalid syntax: syntax anything , [opt(integer)]

    Dear all,

    Why this syntax is invalid?

    Code:
    cap program drop mypgm
    program define mypgm
        syntax anything , [opt(integer)]
        
        dis "`opt'"
    end
    
    mypgm 1, opt(123)


    Click image for larger version

Name:	September 18, 2024 at 22:18:59.png
Views:	1
Size:	162.8 KB
ID:	1764017


    Yours,
    Hall


  • #2
    If an option is indeed optional and requires an integer argument, then you must specify a default.

    See

    Code:
    help syntax
    and specifically

    Code:
    option_descriptor optional_integer_value
    
    type OPname (capitalization indicates minimal
    abbreviation)
    type (integer
    type # (unless the option is required)
    (the default integer value)
    type )
    
    Examples:
    syntax ... , ... Count(integer 3) ...
    syntax ... , ... SEQuence(integer 1) ...
    syntax ... , ... dof(integer -1) ...
    
    The result of the option is returned in a macro name formed by the first 31 letters of the option's name.
    
    The macro contains the integer specified by the user, or else it contains the default value.
    On a matter of style -- not syntax -- I recommend an option name more evocative than opt().

    Comment


    • #3
      Thanks! That's why...

      I indeed went to 'option_descriptor optional_integer_value'. But I only found something like ' # (unless the option is required) ', which is not as clear as your statement here ('If an option is indeed optional and requires an integer argument, then you must specify a default.').

      For the style thing, I use 'mypgm' and 'opt' just for an example. Your suggestion is indeed very good advice.


      Kind regards,
      Hall

      Comment

      Working...
      X