Basic Syntax

Source Files

Sec source files use the .sec extension. A source file belongs to exactly one module, and the module declaration appears at the top of the file.

module internal.storage

Multiple files may belong to the same module when they are placed in the same module directory. The module name must match the directory structure used by the project.

Modules

A module declaration defines the namespace seen by the compiler. It does not define a project. Project-level metadata belongs in sec.module, not in ordinary source files.

module cmd.server

Executable entry points normally live under cmd. Unlike Go, executables do not all share a generic main package name. The module name reflects the executable's logical location.

module cmd.server

fn main() void {
}

Imports

Imports are explicit and only make symbols available. Importing a module must not execute code, initialize subsystems, register handlers, or change program state.

import (
    "fmt"
    "internal/storage"
    "modules/database"
)

The last path component becomes the default module name.

storage.Load(...)
database.Open(...)

Aliases are supported when two imports would otherwise have the same visible name.

import (
    db "modules/database"
    extdb "github/foo/database"
)
Rule: Dot-imports and blank imports are not supported. Imports never execute code.

Blocks

Braces define blocks. Blocks are used for functions, control flow, unsafe regions, match bodies, struct literals, and other grouped constructs.

if ready {
    run()
}

Parentheses are not required around normal conditions. The formatter removes redundant parentheses where the syntax is already clear.

if value in 1..10 {
    print(value)
}

Comments

Single-Line Comments

// This is a single-line comment.

Everything after // until the end of the line is ignored.

Block Comments

/*
    This is a block comment.
    It may span multiple lines.
*/

Block comments may be nested.

/*
    Outer comment

    /*
        Inner comment
    */

    Still inside outer comment.
*/

Documentation Comments

Documentation uses normal comments. There is no separate documentation-comment syntax in the initial language design.

// Calculates the average speed.
fn CalculateSpeed(...) decimal<m/s> {
}
Rule: Comments are not language semantics. Compiler directives are not hidden in comments.

Declarations

Sec uses short, explicit declaration keywords.

Keyword Meaning
moduleDeclares the source file's module.
importImports symbols from another module.
typeDeclares a named type.
fnDeclares a function or method.
letDeclares an immutable binding.
let mutDeclares a mutable binding.
implDeclares behavior for a type or an interface implementation.

Punctuation

Sec reserves punctuation for narrow meanings.

Syntax Meaning
()Function parameters and calls.
{}Blocks, struct bodies, enum bodies, union bodies, and literals.
[]Generics and collection forms.
<>Units of measure.
@Attributes.
#Compiler directives.
...Expansion or spread.

The spread operator ... always belongs to the expansion meaning family. It is used for variadic parameters, argument expansion, and struct copy/update syntax.

Formatting

Sec is intended to have an official formatter. The formatter should make formatting decisions boring and consistent, similar to the philosophy behind gofmt.

The language should not require programmers to argue about alignment, brace placement, or redundant parentheses. The canonical formatted output is the style of the language.