[Thread Prev][Thread Next][Index]

Re: [ferret_users] trailing slash in symbol



Hi,

Interesting thread.  I hadn't been aware of that detail regarding the equal sign on DEFINE SYMBOL.

Some of this is described in Command Syntax, https://ferret.pmel.noaa.gov/Ferret/documentation/users-guide/introduction/COMMAND-SYNTAX and other documentation about syntax is linked in that section,


In the Ferret/PyFerret command parser, the first thing that happens, is that the different "words" in the command are located.  They're separated by spaces,

    LET variable = 7

or by slashes

   PLOT/X=157/Y=33/Z=20/COLOR=blue/title="measured oxygen" o2_observed

If it finds quotes, then everything inside those quotes is grouped together, until the next quote is found.  Likewise the start and end of square brackets or curly braces is located.

During command parsing, any expression within any grave-accents, so `stuff`  is immediately evaluated and its value put into the command line.

Once the "words" are located, their role is identified, is it a command, or a subcommand, e.g. DEFINE SYMBOL are a command and subcommand.  Or is it a qualifier, /X=157, or /TITLE=  or is it an argument, or an element of an expression.


There seem to be some odd little artifacts about trailing slashes.

On the left-hand side of an equal sign, a slash is generally seen as the start of the next qualifier, and if there isn't one,

   yes? let/title=myvar/units=m/ var = 8
 **ERROR: unknown command qualifier: var = 8

but if it's in an expression, it's ignored.

yes? let/title=myvar/units=m  var = 9/
yes? list var
             VARIABLE : myvar (m)
          9.000


DEFINE SYMBOL seems to be set up so the value of the symbol is taken to be everything following "define symbol" on the command line, up to but not including a ! comment,  and not including a trailing slash.

yes? define symbol sym1 = Some text including $ and / but not including this comment ! comment yes? define symbol sym2 Some text including $ and / but not including this comment ! comment

yes? show symbol sym*
SYM1 = "Some text including $ and / but not including this comment"
SYM2 = "Some text including $ and / but not including this comment"




In scripts, I sometimes build up a set of qualifiers, so the qualifiers for a PLOT command might be built up depending on the state of things and different settings, so over the course of running a set of scripts that open a dataset and make a plot, these definitions might be scattered in there.  If the first one starts with a slash, and each new one gets its own slash, it all works out in the end.  The PLOT command also works even if there are no qualifiers set at all.

cancel symbol qualifiers  ! at the start of the session.

DEFINE SYMBOL qualifiers = ($qualifiers)/X=157/Y=33/Z=20
DEFINE SYMBOL qualifiers = ($qualifiers)/T=1-jan-2020:31-mar-2020
DEFINE SYMBOL qualifiers = ($qualifiers)/title="the title"
DEFINE SYMBOL qualifiers = ($qualifiers)/dash/color=red

plot($qualifiers)  theta
 !-> plot/X=157/Y=33/Z=20/T=1-jan-2020:31-mar-2020/title="the title"/dash/color=red theta




On 6/20/2020 12:55 PM, Marco van Hulten wrote:
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


--
Ansley Manke
Science Data Integration Group
NOAA Pacific Marine Environmental Laboratory
7600 Sand Point Way NE
Seattle WA 98115

I am currently teleworking and am available Tue-Wed-Thu.


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

Privacy Policy | Disclaimer | Accessibility Statement