[Thread Prev][Thread Next][Index]

Re: [ferret_users] trailing slash in symbol



Ryo—

Je Sat, 20 Jun 2020 14:52:57 +0900 skribis Ryo:
> On Fri, Jun 19, 2020 at 6:57 PM Marco van Hulten <Marco.Hulten@xxxxxx>
> wrote:
> 
> > I noticed that a trailing slash is ignored for in a string variable,  
> 
> 
> I guess the correct statement is that trailing slashes are ignored *by the
> commands.*
> 
> yes? define symbol ss "/abc/"
> yes? show symbol ss
> SS = "/abc/"
> yes? define symbol ss /abc/
> yes? show symbol ss
> SS = "/abc"
> 
> That means that it was the "DEFINE SYMBOL" command which ignored the
> trailing backslash.
> 
> Furthermore,
> 
> yes? define symbol ss "/abc/"
> yes? say ($ss)
>  !-> MESSAGE/CONTINUE /abc
> /abc
> yes? say "($ss)"
> !-> MESSAGE/CONTINUE "/abc/"
> /abc/
> 
> In this case, it was the SAY command which ignored the trailing backslash.
> 
> So, to avoid the trailing slash from being interpreted by the command, you
> quote the string.

Thanks, it looks like this works very well!

According to the manual [1], however, the syntax should contain an
equal sign, like

   define symbol ss = something

instead of

   define symbol ss something

Without the equal sign it works best, though, because you can use
quotation marks without them becoming part of the symbol.  The
following two statements seem equivalent (according to what a quoted
SAY command tells me):

   define symbol sja = ka\/\/
   define symbol sja "ka/"

Earlier I was referring to my "solution" as "doubly escaping", but that
would rather look like \\/ (or \\\\ that one sometimes needs to print
a backslash); I don't know what \/\/ is or why I thought it was a good
idea to try it out.

The behaviour of variables of type string (DEFINE VARIABLE or LET)
seems more predictable to me, so I guess it is best to only use DEFINE
SYMBOL when absolutely needed (basically, to avoid `embedded
`backtics``).

If one would use the non-= syntax for LET, this happens:

yes? let aa = 3
yes? list aa
             VARIABLE : 3
          3.000
yes? let bb 7
yes? list bb
             VARIABLE : 7
          7.000
yes? let cc "abc"
 **ERROR: command syntax: abc"
          unclosed quotation, parenthesis, or bracket

suggesting it may be a bad habit to omit the equal sign.  But I really
don't know!  It seems that Ferret is quite lax in its syntax, but that
introduces some unpredictable behaviour!  Unless we read the source, of
course.

—Marco

[1]: https://ferret.pmel.noaa.gov/Ferret/documentation/users-guide/commands-reference/DEFINE


[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement