master

Index

Introduction §

One is a general-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.

  • Easy - Easy to build with clean syntax includes library.
  • Robust - Behavior is correct even for edge cases such as out of memory.
  • Optimal - Write programs the best way they can behave and perform.
  • Reusable - The same code works in many environments which have different constraints.
  • Small - You can compile and execute code everywhere, for example on rescue disks (about 200KB for compiler)
  • Fast - No byte code overhead. Compile, assemble and link several times faster than GCC.
  • Performance - Efficient performance software and Acceptable performance against other languages.
  • Maintainable - Precisely communicate intent to the compiler and other programmers. The language imposes a low overhead to reading code and is resilient to changing requirements and environments.
  • Safe - Includes an optional memory and bound checker. Bound checked code can be mixed freely with standard code.
  • Practical Multi-threading - Safe concurrency.
  • Self-hosted - Compiler and linker works without any third-party tools.
  • Bootstrapping - All codes did written in this language. (In next version)

Often the most efficient way to learn something new is to see examples, so this documentation shows how to use each of One's features. It is all on one page so you can search with your browser's search tool.

If you search for something specific in this documentation and do not find it, please file an issue or say something on IRC.

The code samples in this document are compiled and tested as part of the main test suite of one. This HTML document depends on no external files, so you can use it offline.

CLI §

$ one help
One is a tool for managing One source code.

Usage:

    one [command] [arguments]

The commands are:

    build       compile packages and dependencies
    get         download and install packages and dependencies
    install     compile and install packages and dependencies
    list        list packages or modules
    run         compile and run program
    version     print One version

Use "one help [command]" for more information about a command.

Compiling §

$ one build hello.one
$ ./hello
Hello, world!

Example §

Hello World §

hello.one

main:
   __ "Hello, World!"
end
main:
   _ "Hello, World!\n"
end

Usually you don't want to write to stdout. You want to write to stderr. And you don't care if it fails. It's more like a warning message that you want to emit. For that you can use a simpler API:

hello.one

main:
    io.write("Hello, World!\n")
    io.error("Oops!\n")
end

Line Count §

line_count.one

main:
   if io.argument[1]:
      string filePath=io.argument[1]
      // io.write("Reading ", filePath, " file\n")
      __ "Reading ", filePath, " file"
      int size=file.size(filePath) # fseek SEEK_END and ftell in `C`

      __ "File size is: ", size
      string data=file.read(filePath, size)

      // string[] lines=data.split("\n")
      // int lineCount=lines.count()

      // int lineCount=0
      // each lines as line:
      //    lineCount++
      // end

      int lineCount=data.count("\n")
      __ "File Lines: ", lineCount
   else:
      io.error("Oops!\n")
   end
end

Runtime Library §

Math Class §

  • math.sin(float radian)
  • math.cos(float radian)
  • math.cot(float radian)
  • math.tan(float radian)
  • math.abs(float value)
  • math.sqrt(float value)
  • math.log2(float value)
  • math.log(float value)
  • math.ceil(float value)
  • math.floor(float value)
  • math.round(float value)

IO Class §

  • io.write(string format, ...)
  • io.error(string format, ...)
  • io.read(string format, ...)

See also: