Skip to main content
  1. The pint° programming language/
  2. Language overview/

Let declarations

The let keyword allows you to declare names, both regular declartions and function declarations. All names declared with let are available in the top-level scope of the pint° program.

let declarations are always immutable, and thus cannot be redefined.

Regular let declarations #

A regular let declaration has the syntax let a = b, where a is a name and b a expression which evaluated value will be assigned to a. The declared identifiers can then be referred by other let declarations or in function calls.

Here are some examples:

1
2
let name = "Mateus Pinto"
let numberOfcatsHeHas = 1

Function let declarations #

By appending a parameter to a let declaration identifier, it is converted to a function let declaration.

1
let printName (:name String) = print name

A function has to have exactly one parameter, and it has to be a struct. You can emulate parameterless functions by using the unit.

let receiveNoParameter () =
  print "No parameters"

let receiveSingleParameter (:param String) =
  print "Single parameter"

let receiveMultipleParameters (:param1 String, :param2 int) =
  print "Multiple parameters"

Identifiers #

As we are talking about name declarations, this may be a good place to define what are valid or invalid identifiers in pint°.

For interoperability reasons, pint° chose to follow Dart’s identifier rules, so:

  • Identifiers can have all regular ASCII letters (no diacritics), numbers, _ and $.;
  • Identifiers can’t start with a number.

Thus, those are some example of valid identifiers:

  • myVariable
  • _privateVar
  • totalAmount
  • calculate$um
  • UserName
  • MAX_VALUE
  • isValid123

And some invalid identifiers:

  • 123start (cannot start with a digit)
  • my-var (hyphens are not allowed)
  • my/function (operators can’t be used)