WolframLang: CompoundExpression and Semicolon

By Xah Lee. Date: . Last updated: .

Semicolon in WolframLang, e.g. a;b is a short syntax for CompoundExpression[a,b]. It is used to group several expressions together as one syntactic unit. It is similar to many language's code block by braces {}, or lisp's progn.

Short syntaxFullForm
expr1;expr2CompoundExpression[expr1, expr2]
expr1;CompoundExpression[expr1,Null]
CompoundExpression[expr1, expr2, etc]
(short syntax: expr1;expr2;etc)

Eval all arguments and return the value of last argument. CompoundExpression

CompoundExpression is frequently used in If, Function, Module, or anytime when you need to do several computation as a single expression as one arg to function.

Examples:

If[x, doTrueExpr1; doTrueExpr2; etc, doFalseExpr1; doFalseExpr2; etc ]

[see WolframLang: If Then Else (Conditionals, Branching)]

Function[{vars}, expr1; expr2; etc]

[see WolframLang: Define Function]

Module[{vars}, expr1; expr2; etc ]

[see WolframLang: Local Variable]

Often, you'll find it convenient to put a semicolon at end of some expression. In particular, after assignment. It has the effect of suppressing output. For example, x=3 return 3, but x=3; return Null, and Null output is not printed.