5
$\begingroup$

Searching { in F1 documentation, one at least gets an item for List. But the same thing is not happening for ,, [ or ]. What are the positions of symbols as such in the Wolfram language's expression hierarchical structure? Do they have Heads?

$\endgroup$
  • 3
    $\begingroup$ They are not symbols but tokens that indicate expression structure / operators, see more in What the @#%^&*?! do all those funny signs mean? $\endgroup$ – Kuba Jul 9 '18 at 9:10
  • $\begingroup$ @Kuba Thanks for response. Apparently I know their basic usages. But for now I am somewhat surprised at it that it seems nothing can be dug out in the documentation about them. $\endgroup$ – Αλέξανδρος Ζεγγ Jul 9 '18 at 9:19
  • 1
    $\begingroup$ Search engine is not perfect, otoh [ ] , are fundamental parts of WL syntax, covered in any introduction $\endgroup$ – Kuba Jul 9 '18 at 9:48
  • $\begingroup$ @kuba OP's question baffles me, I should say. Indeed, these are fundamental parts of WL syntax, and I've known their meanings even before I learned the usage of the document, but in which document page can I find their introduction? [ and ] are briefly mentioned in tutorial/GettingUsedToMathematica. (I found this by browsing the virtual book from beginning. ) But I fail to find introduction of ,. $\endgroup$ – xzczd Jul 9 '18 at 11:03
  • 2
    $\begingroup$ For documentation on ( ), [ ], { }, or [[ ]] enter brackets, highlight, and press F1. Click on The Four Kinds of Bracketing in the Wolfram Language. For ; see CompoundExpression or Sequences of Operations. For , see List. $\endgroup$ – Bob Hanlon Jul 9 '18 at 13:42
5
$\begingroup$

I believe the documentation-page you are looking for is this here

And for some further reading, you might want to look at The Syntax of the Wolfram Language.

The comma has no such page that I could find. Probably, because it such a core part of the language that you instantly grasp. The comma is used to separate different arguments of functions. Even this {1,2,3} is only short for List[1,2,3] which separates the arguments of List.

From the viewpoint of the syntax, both , and [ are neither expressions nor atoms. They are tokens that cannot stand on their own. For your question, however, this does not really matter because even + or /@ is a token and still, you can lookup the documentation for it.

The word "token" comes from the process of turning an input string into a so called syntax-tree that can then be evaluated. When Mathematica reads your input for evaluation, it starts with your input string chunks it into tokens. You can use the nifty fultzTokenize from this answer to see the effect directly in Mathematica. Let's consider the following input

{1, aa, "str"}

and see how this is turned into a list of tokens

Row[Framed /@ fultzTokenize["{1,aa,\"str\"}"], Spacer[10]]

Mathematica graphics

You see that it is not separated after each character. Rather, it is divided into logical parts that are defined by the syntax of the language and these parts is what we call tokens. Important to notice is that some of the tokens are already valid, atomic expressions:

{Framed[#], SyntaxQ[#]} & /@ fultzTokenize["{1,aa,\"str\"}"]

Mathematica graphics

Mathematica now uses the rules of a parser to turn this list of tokens into an expression. For a Mathematica List, this rule could look like this

listExpr ::= '{' '}' | '{' sequenceExpr '}'

After the parsing, Mathematica has internal representation of your input which is usually called abstract syntax tree or AST

TreeForm[{1, aa, "str"}]

Mathematica graphics

Let me close the circle and come back to the documentation. When you press F1 anywhere inside your code, Mathematica will select the closest token near your cursor. Often, the token is already an atomic expression like a built-in function. For these, the reference page is always available.

Other times, you might be near a token that is not an expression by itself. Consider being near the -> or the <| in the following example

<|a -> 1|>

For some of these tokens, a direct documenation page is available but for others this might not be the case. For your specific cases, Mathematica does not have a reference page like it has for e.g. Plot.

In any case, there are two important parts: (1) which token is selected by Mathematica when you press F1 and (2) can it successfully find a reference page.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Yes, neither expressions nor atoms. So could you please say something more about tokens? $\endgroup$ – Αλέξανδρος Ζεγγ Jul 10 '18 at 6:08
  • $\begingroup$ Very informative! $\endgroup$ – Anton Antonov Jul 10 '18 at 14:03
0
$\begingroup$

If you are new to Mathematica, you may want to look at the following:

What are the most common pitfalls awaiting new users?

Where can I find examples of good Mathematica programming practice?

Extremely useful on the most common errors, misunderstandings and peculiarities of Mathematica,

Best

| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ That's quite broad considering the specific question from OP. Could you narrow it, quote relevant parts that answer the question? $\endgroup$ – Kuba Jul 9 '18 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.