Salam for Python, Go and JavaScript programmers: the traps

Salam looks like Python with end instead of indentation, but nine details behave differently from what Python, Go and JavaScript programmers expect: until is while, else cond is else if, switch falls through, integers are i32, strings are heap values you free, and more. Each trap has a program and its output.

The Salam team · December 2, 2026 · 9 min read

In this article

Most of Salam can be read on the first day by someone who knows Python, Go or JavaScript. Blocks open with a colon and close with end, println prints its arguments separated by spaces, := declares a variable, and each x in xs loops over a collection. The danger is not the syntax you cannot read; it is the syntax you read wrongly. This guide lists the places where the familiar meaning is the wrong one. Every program below was run, and the output shown is what it printed.

What carries over

You knowIn Salam
Python for x in xs:each x in xs: ... end
Python for i in range(n):repeat n in i: ... end
Python elifelse cond:
Go x := 1x := 1 (immutable; use mut x := 1 to reassign)
Go defer f.Close()defer f.Close()
Go for { ... }until true: with break
JavaScript const x = 1x := 1
JavaScript let x = 1mut x := 1
JavaScript x => x * 2(x: i32): ret x * 2 end
Exceptions or error returnsthrow, try f() and try: ... catch e: ... end

There are no braces, no semicolons (a ; is an error), no while and no for. The language reference has the full grammar; the rest of this page is about behaviour.

1. until is while

until reads like "until the condition is true", and it does the opposite: it repeats while the condition is true. There is no while keyword, so until is the only conditional loop. Copy the condition from a while loop unchanged.

salam
Try it
func main:
    mut i := 0
    until i < 3:
        println i
        i++
    end
end
output
0
1
2

Writing until i >= 3: here, the way the English word suggests, runs the body zero times and prints nothing, with no error. When a loop does nothing, check the polarity of its condition first.

2. else cond is else if

A chain of conditions uses else followed by the next condition. There is no elif (the parser also tolerates else if), and the whole chain has one end. A plain else: with a colon right after it is the final branch.

salam
Try it
func grade(score: i32): str:
    if score >= 90:
        ret "A"
    else score >= 80:
        ret "B"
    else:
        ret "C"
    end
end

func main:
    println grade(95), grade(85), grade(40)
end
output
A B C

elif is an error that tells you to write else.

3. switch falls through

A switch is not a match and not a Python match statement. Each label is a value, a list, a range (2 to 4) or a relational test (> 10), and the body of a label continues into the next label unless it ends with break (or ret). Every label has its own end, and else must be last.

salam
Try it
func main:
    n := 2
    switch n:
        1:
            println "one"
        end
        2:
            println "two"
        end
        3:
            println "three"
            break
        end
        else:
            println "other"
        end
    end
end
output
two
three

n is 2, so the program printed two, fell into the label for 3 and printed three, and stopped at that break. Go programmers will find this the reverse of Go, where each case ends by itself. If you want no fallthrough and a compiler that checks every enum member is handled, use match instead.

4. Integers are i32 unless you say otherwise

An integer literal is an i32 when it fits and an i64 when it does not. A variable made from it keeps that type, and arithmetic stays in that width. When the compiler can see the product overflow, it refuses (error[E148]: integer overflow: 'a * a' gives 10000000000, which does not fit in 'i32'). Cast one operand to a wider type first with as. A narrower type does not convert back for free: passing an i64 where an i32 is expected is error[E012]: argument 1: cannot pass 'i64' to 'i32'.

salam
Try it
func main:
    small := 100000
    wide := small as i64
    println wide * wide
    println 7 / 2, 7.0 / 2.0
end
output
10000000000
3 3.5

The second line shows two more differences. Integer / truncates, so 7 / 2 is 3, and / never turns integers into floats the way JavaScript or Python 3 would. Put the cast in parentheses when you cast and then multiply: (a as i64) * (b as i64), because after as i64 a * reads as the start of a pointer type.

5. A function that returns a string returns memory you free

str has no garbage collector behind it. A function that returns a str hands you a freshly allocated string, and you own it: free it with mem.Free when you are done. Strings that you only read through (literals, and arguments you were given) are not yours to free. This feels wrong after Python or JavaScript, where strings just disappear when nothing refers to them. In a short program the leak is harmless; in a server it adds up. Vectors, hash maps and structs that hold strings follow the same rule, usually with defer x.Free() right after you create them.

salam
Try it
import mem
import str

func main:
    label := str.FromInt(42 as i64)
    println "id:", label
    mem.Free(label as void*)
end
output
id: 42

Strings are also bytes, not UTF-16 or code points: the length of a Persian word is its byte count, and there is a separate method to count letters.

6. Structs copy, collections share

Assigning a struct copies it, as in Go: change the copy and the original is untouched. A Vector or HashMap is a handle to a buffer, and assigning it moves or shares that buffer, as with a Python list or a JavaScript array. The compiler guards the common mistake: reading the old name after the buffer may have moved is E259 or E258. If you want two independent collections, ask for a copy with .Copy().

salam
Try it
struct Point:
    pub x: i32 = 0
end

func main:
    p := Point { x = 1 }
    mut q := p
    q.x = 9
    println p.x, q.x
    list := Vector {} as Vector<i32>
    defer list.Free()
    list.Push(1)
    more := list.Copy()
    defer more.Free()
    more.Push(2)
    println list.Len(), more.Len()
end
output
1 9
1 2

p stays 1 while the copy q becomes 9, and the vector list keeps its one element while its copy more gets a second.

7. Unused things are errors

An unused variable, parameter, import or private function stops the build. This surprises everyone once. A variable declared with mut that is never reassigned is an error too. Remove what you do not use; a name that starts with _ silences the check, but it leaves dead code behind, so keep that for a parameter in a fixed callback signature.

salam
Try it
func main:
    unused := 1
end

The compiler says error[E059]: unused variable 'unused': nothing uses it after it is declared, with a fix that prefixes the name with _.

8. The order of a file is fixed

Go and Python let you define things in any order. Salam checks the order within a file: package, then import, then include, then global variables and constants, then types (struct, enum, type, interface, impl), then private functions, then pub functions. A struct written after the first function is E087, a global after a type is E085, and a private function after a pub one is E088. Functions may call each other in any order within that frame, so only the grouping matters. main is exempt from the pub rule.

9. Lambdas capture by value

A lambda is written (x: i32): ret x * 2 end, with no func and no return type, and it copies the variables it uses at the moment it is created. A JavaScript closure sees later changes; a Salam lambda does not.

salam
Try it
func main:
    mut n := 1
    show := (): ret n end
    n = 5
    println show(), n
end
output
1 5

show still returns 1 after n became 5. To share state with a lambda, put it behind a pointer, a collection or a global.

Where to go next

The Salam vs Python article compares the two languages on speed and ecosystem, the static typing article covers the type system, and the /learn/ course walks through the language from the start.

Try Salam yourself

Salam is free and open source. Run the examples from this article in the online editor, follow the course from the first lesson, or install the compiler with one command.