Starlark

Lightweight programming language From Wikipedia, the free encyclopedia

Starlark is a lightweight, high-level programming language designed for embedded use in applications. It uses a subset of the Python syntax. By default, the code is deterministic and hermetic.[1]

History

Starlark was released in 2015 as part of Bazel under the name Skylark.[3] This first implementation was written in Java. In 2018, the language was renamed Starlark.[4]

In 2017, a new implementation of Starlark in Go was announced.[5]

In 2021, Meta announced an implementation of Starlark written in Rust,[6] to be used for the Buck build system.[7][8]

Popularity

In addition to the Bazel[9] and Buck build systems, Starlark is used by dozens of projects,[10][11] including Isopod,[12] skycfg,[13] Uber's Starlark Worker,[14] and Tilt.[15]

On GitHub, Starlark is among the top 50 languages based on the developer activity.[16][17]

Syntax

Starlark syntax is a strict subset of Python syntax.[1] Similar to Python syntax, Starlark relies on indentation to delimit blocks, using the off-side rule.

Statements and control flow

Starlark's statements include:[18]

  • The = statement to assign a value to a variable
  • The augmented assignment statements to modify a variable
  • The if statement to execute conditionally a block of code (with else or elif)
  • The for statement to iterate over an iterable object
  • The def statement to define a function
  • The break statement to exit a loop
  • The continue statement to skip the rest of the current iteration and continues with the next
  • The pass statement, serving as a NOP, syntactically needed to create an empty code block
  • The return statement to return a value from a function.
  • The load statement, which replaces Python import, to import a value from another module.[19] Unlike Python, the order of load statements does not affect the semantics of the code.[20]

Unlike Python, Starlark statements don't include: while, try, raise, class, with, del, assert, yield, import, match and case.[21]

Freezing

To ensure thread safety and support parallel computing, Starlark has a feature called freezing. At the end of the evaluation of a module, all values become immutable. This means that the values that can be accessed from multiple threads can no longer be modified, which removes the risk of race conditions.[3][22]

See also

References

Related Articles

Wikiwand AI