Joa treats IPv4 addresses and CIDR subnets as distinct native types, not strings. This prevents accidental misuse and enables type-safe network operations.
IP Literals
Any dotted-quad address is automatically parsed as an IP type:
let gateway = 192.168.1.1
let dns_server = 8.8.8.8
let loopback = 127.0.0.1
An invalid address causes a Type Error at runtime.
Subnet Literals
Any CIDR notation is automatically parsed as a Subnet type:
let lan = 192.168.0.0/16
let dmz = 10.10.10.0/24
let host_only = 172.16.0.1/32
IP Membership
The in / not in operators work natively between IP and Subnet:
let zone = 10.0.0.0/8
let host = 10.5.3.2
if host in zone {
print("Host is inside the zone")
}
if 172.16.0.1 not in zone {
print("External address detected")
}
Subnet Properties
| Property | Type | Description |
|---|---|---|
subnet.network |
String |
Network address as a string |
subnet.mask |
Integer |
Prefix length (e.g. 24) |
let net = 192.168.1.0/24
print(net.network) // 192.168.1.0
print(net.mask) // 24
Subnet Methods
See §16 Subnet Methods.