Language Reference: Imports and Exports

null


Exports

binary.ptls:

-- Parse a binary string as a number

fn parse(string)
  result = 0

  for bit in chars(string) do
    result *= 2
    result += Bool.toNum(bit == "1")
  end

  result
end

-- Convert a positive integer to a binary string

fn of(n)
  digits = []

  while n > 0 or digits == "" do
    digits |= push(n % 2)
    n = Math.floor(n / 2)
  end

  digits
    | reverse
    | join("")
end

{ parse, of }

Imports

bin = import "binary.ptls"

bin.parse("1101")
bin.of(13)
13
"1101"

Import Specifiers

import "text:lyrics.txt"
"I said Rock\nWhat's a matter with you Rock\nDon't you see I need you Rock\nLord Lord Lord\nAll on that day"
import "lines:lyrics.txt"
[
  "I said Rock",
  "What's a matter with you Rock",
  "Don't you see I need you Rock",
  "Lord Lord Lord",
  "All on that day",
]