Expressions and Conditions

In Emblem, an expression is a section of text which is parsed and evaluated as a mathematical statement. These can be used to concisely represent maths operations without using the arithmetic or logic directives. A condition is a special case of an expression, where if the expression is empty, false is returned instead of emitting a parse-error. These are commonly used in the flow-control directives.

It must be noted that expressions are only capable of handling numbers, so for checking textual equality for example, the .streq directive must still be used.

The following operators are recognised in expressions with the numbers giving their precedence level with higher numbers indicating that the associated operators bind more tightly. As the multiplication operator, *, has a higher precedence than the binary subtraction operator, -, we can see that the expression 1+2*3 is correctly evaluated to 7 instead of 9.

    • <==> -- Dual implication
    • ==> -- Single-implication (right)
    • <== -- Single-implication (left)
    • || -- Disjunction (‘lazy-or’)
    • && -- Conjunction (‘lazy-and’)
    • <=> -- Dual implication (higher precedence)
    • => -- Single implication (right, higher precedence)
    • != -- Numeric inequality
    • == -- Numeric equality
    • <= -- Inequality, less-than-or-equal, lazy
    • < -- Inequality, less-than, lazy
    • >= -- Inequality, greater-than-or-equal, lazy
    • > -- Inequality, less-than, lazy
    • ~ -- Bitwise exclusive disjunction (‘xor’)
    • | -- Bitwise disjunction (‘strict-or’)
    • & -- Bitwise conjunction (‘strict-and’)
    • + -- Addition
    • - -- Subtraction
    • // -- Integer division
    • % -- Modulo
    • * -- Multiplication
    • / -- Division
    • ! -- Logical negation
    • - -- Numeric negation
    • ~ -- Bitwise negation
    • + -- Unary plus
    • ^ -- Exponentiation

Example -- Fizz-Buzz

The following is a solution in Emblem to the FizzBuzz common interview problem. This is by no means a model solution for Emblem is not a programming language---first and foremost it is a typesetter, it just happens to have a handy extension language which can be programmed in.

.for{!i <- 1}{1 <= !i <= 100}{!i <~ !i + 1}:
	.if{!i % 15 == 0}:
		.echo: FizzBuzz
	::
		.if{!i % 5 == 0}:
			.echo: Buzz
		::
			.if{!i % 3 == 0}:
				.echo: Fizz
			::
				.echo: !i