FCS Language Basics
1. File Structure
FCS scripts are plain text files with .fcs extension. A script consists of:
- Comments
- Variable assignments
- Data item definitions (geometry, materials, etc.)
- Import statements
# This is a comment
## Multi-line comments use multiple #
# Variable definitions
height := 10.5
width := 20
# Computed values
area := height * width
# Data items (geometry, mesh, analysis)
vertex {v1} xyz 0 0 0
2. Comments
# Single line comment
## Another comment style
# Comments can appear at end of line
x := 10 # inline comment
3. Variable Assignment
Two assignment operators:
Definition Assignment :=
Creates a lazy binding - the expression is evaluated when the variable is accessed.
# Simple values
x := 10
name := "hello"
pi := 3.14159
# Computed values (lazy - re-evaluated on access)
radius := 5
circumference := 2 * pi * radius
# Later if radius changes, circumference recalculates
Value Assignment =
Creates an immediate binding - evaluates once at assignment time.
x = 10 # immediate evaluation
y := x + 5 # lazy - will use current x when accessed
Best Practice: Use := for most definitions. Use = only for mutable state.
4. Data Types
Primitives
| Type | Examples | Description |
|---|---|---|
| Integer | 10, -5, 0 |
Whole numbers |
| Double | 3.14, -0.5, 1e6 |
Floating point |
| Boolean | True, False |
Logical values |
| String | "hello", 'world' |
Text |
Compound Types
# Lists (arrays)
numbers := [1, 2, 3, 4, 5]
mixed := [1, "two", 3.0]
empty := []
# Tuples
point := (1.0, 2.0, 3.0)
# Dynamic objects (anonymous)
config := { width := 10, height := 20, name := "box" }
Accessing Properties
# Object property access
obj := { x := 1, y := 2 }
xVal := obj.x # dot notation
# List indexing (0-based)
arr := [10, 20, 30]
first := arr[0] # 10
last := arr[-1] # 30 (negative = from end)
# Slicing
subset := arr[1:3] # [20, 30]
5. Operators
Arithmetic
a := 10 + 3 # Addition: 13
b := 10 - 3 # Subtraction: 7
c := 10 * 3 # Multiplication: 30
d := 10 / 3 # Division: 3.333...
e := 10 % 3 # Modulo: 1
f := 2 ** 3 # Power: 8 (or use Pow(2,3))
Comparison
a := 5 == 5 # Equal: True
b := 5 != 3 # Not equal: True
c := 5 > 3 # Greater: True
d := 5 < 3 # Less: False
e := 5 >= 5 # Greater or equal: True
f := 5 <= 3 # Less or equal: False
Logical
a := True and False # False
b := True or False # True
c := not True # False
String Concatenation
greeting := "Hello" + " " + "World" # "Hello World"
6. Control Flow
Ternary Expression
# condition ? if_true : if_false
max := a > b ? a : b
status := count > 0 ? "has items" : "empty"
If Expression (single line)
result := if (x > 0) then x else -x
7. Functions (Lambdas)
Single-argument Lambda
square := x => x * x
result := square(5) # 25
Multi-argument Lambda
add := (a, b) => a + b
multiply := a, b => a * b
sum := add(3, 4) # 7
prod := multiply(3, 4) # 12
Lambda with Body
# For complex functions, use block syntax
compute := (x, y) => {
temp := x * 2
result := temp + y
result # last expression is return value
}
8. Class Instantiation
Classes (defined elsewhere) are instantiated with curly braces:
# Basic instantiation
myBeam := BeamClass{}
# With property overrides
myBeam := BeamClass{ length = 10, width = 0.5 }
# Nested
config := OuterClass{
inner = InnerClass{ value = 100 }
}
Property Override (Updater Syntax)
# Clone with modified properties
original := MyClass{ a = 1, b = 2 }
modified := original{ a = 10 } # b remains 2
9. Built-in Functions
Math Functions
# Trigonometry (angles in radians)
s := Sin(0.5)
c := Cos(0.5)
t := Tan(0.5)
a := Asin(0.5)
a := Acos(0.5)
a := Atan(0.5)
a := Atan2(y, x)
# Other math
sq := Sqrt(16) # 4
pw := Pow(2, 3) # 8
ab := Abs(-5) # 5
mn := Min(3, 7) # 3
mx := Max(3, 7) # 7
rd := Round(3.7) # 4
fl := Floor(3.7) # 3
cl := Ceil(3.2) # 4
# Constants
pi := PI # 3.14159...
e := E # 2.71828...
Unit Conversions
# Common unit conversions
angle_rad := 45 * Unit.deg # degrees to radians
angle_deg := 0.785 / Unit.deg # radians to degrees
Type Conversions
intVal := Math.ToInteger(3.7) # 3
dblVal := Math.ToDouble(5) # 5.0
strVal := x.ToString() # "..."
List Operations
arr := [1, 2, 3, 4, 5]
count := arr.Count # 5
first := arr.First() # 1
last := arr.Last() # 5
sum := arr.Sum() # 15
avg := arr.Average() # 3.0
min := arr.Min() # 1
max := arr.Max() # 5
# Functional operations
doubled := arr.Select(x => x * 2) # [2, 4, 6, 8, 10]
filtered := arr.Where(x => x > 2) # [3, 4, 5]
any := arr.Any(x => x > 4) # True
all := arr.All(x => x > 0) # True
10. Import Statements
# Import another FCS file
import "path/to/file.fcs"
# All definitions from imported file become available
11. String Formatting
name := "beam"
length := 10.5
# String concatenation
msg := "The " + name + " is " + length.ToString() + " meters"
# Formatted strings (if supported)
formatted := $"Length: {length:F2} m"
12. Special Identifiers
| Identifier | Description |
|---|---|
this |
Reference to current class instance |
GCS |
Global Coordinate System |
Unit |
Unit conversion namespace |
Fcs |
FCS namespace for built-in types |
13. Syntax Rules Summary
- Case Sensitive:
myVar≠MyVar - Whitespace: Significant for line breaks, not indentation
- Semicolons: Not required (line breaks separate statements)
- Identifiers: Start with letter/underscore, contain letters/digits/underscores
- Keywords: Cannot be used as identifiers
14. Common Patterns
Parametric Design
# Parameters
L := 10 # Length
W := L / 2 # Width depends on L
H := 3 # Height
# Geometry uses parameters
vertex {v1} xyz 0 0 0
vertex {v2} xyz L 0 0
vertex {v3} xyz L W 0
vertex {v4} xyz 0 W 0
Conditional Geometry
includeSupport := True
supportHeight := includeSupport ? 1.0 : 0.0
Iteration via Select
# Create list of points
points := Fcs.Converters.EnumerableRange(10).Select(i => {
x := i * 0.1
y := Sin(x)
result := { X := x, Y := y }
})