Difference between revisions of "Inverted syntax"

From Fōrmulæ wiki
Jump to: navigation, search
(Added Fōrmulæ)
 
Line 30: Line 30:
  
 
=== Answer ===
 
=== Answer ===
 +
 +
==== Inverted syntax with conditional expressions ====
 +
 +
The following is how is visualized the common [[Programming.If|If]] expression:
  
 
[[File:InvertedSyntax01.png|border]]
 
[[File:InvertedSyntax01.png|border]]
 +
 +
The following is the visualization of the [[Programming.InvertedIf|Inverted If]] expression. Note that they are different expressions, in order that they can be differently visualized, but they reduce the same way.
  
 
[[File:InvertedSyntax02.png|border]]
 
[[File:InvertedSyntax02.png|border]]
 +
 +
==== Inverted syntax with assignment ====
 +
 +
The [[Symbolic.Assignment|Assignment]] expression does not have an inverted form, so it looks as usual;
  
 
[[File:InvertedSyntax03.png|border]]
 
[[File:InvertedSyntax03.png|border]]
 +
 +
However, Fōrmulæ supports right to left orientation, in such a case the last expression looks like:
  
 
[[File:InvertedSyntax04.png|right|border]]
 
[[File:InvertedSyntax04.png|right|border]]
 +
 +
<br clear=all>Right to left orientation might look confusing. The following are the right to left visualization of the traditional and inverted conditional we have seen above:
  
 
[[File:InvertedSyntax05.png|right|border]]
 
[[File:InvertedSyntax05.png|right|border]]

Revision as of 15:06, 1 August 2019

This page is the answer to the task Inverted syntax in the Rosetta Code.

Description (from Rosetta Code)

Inverted syntax with conditional expressions

In traditional syntax conditional expressions are usually shown before the action within a statement or code block:

IF raining=true THEN needumbrella=true

In inverted syntax, the action is listed before the conditional expression in the statement or code block:

needumbrella=true IF raining=true

Inverted syntax with assignment

In traditional syntax, assignments are usually expressed with the variable appearing before the expression:

a = 6

In inverted syntax, the expression appears before the variable:

6 = a

Task

The task is to demonstrate support for inverted syntax forms within the language by showing both the traditional and inverted forms.

Answer

Inverted syntax with conditional expressions

The following is how is visualized the common If expression:

InvertedSyntax01.png

The following is the visualization of the Inverted If expression. Note that they are different expressions, in order that they can be differently visualized, but they reduce the same way.

InvertedSyntax02.png

Inverted syntax with assignment

The Assignment expression does not have an inverted form, so it looks as usual;

InvertedSyntax03.png

However, Fōrmulæ supports right to left orientation, in such a case the last expression looks like:

InvertedSyntax04.png


Right to left orientation might look confusing. The following are the right to left visualization of the traditional and inverted conditional we have seen above:

InvertedSyntax05.png
InvertedSyntax06.png