Crystal Programming Language

repository·master·Indexed 12 days ago

https://github.com/crystal-lang/crystal

A compiled, statically typed programming language that combines the syntax expressiveness of Ruby with the performance of C. Features include native compilation, type inference, C interoperability, and compile-time metaprogramming.

Tokens
39.8K
Snippets
142
Records
383
Agent score
97%

What's inside Crystal

  1. Overview of the Crystal programming language

    master

    Crystal is a statically typed programming language designed to combine the developer productivity of Ruby's syntax with the execution performance of C.

    Key features include:

    • Ruby-like syntax: High developer efficiency for writing code.
    • Static typing with type inference: Statically type-checked without requiring explicit type annotations for most variables or method arguments.
    • C interoperability: Ability to call C code via bindings written directly in Crystal.
    • Compile-time metaprogramming: Supports compile-time evaluation and code generation to reduce boilerplate.
    • Native compilation: Compiles directly to efficient native machine code.
  2. New features in Crystal 1.4.0

    master

    Crystal 1.4.0 introduced several language and standard library enhancements, including:

    Language

    • Int128 Support: Added support for Int128 in codegen and macros.
    • ProcPointers: Support for ProcPointers with global path and top-level method references.
    • Type Inference: Experimental improvements to type inference for ivars and cvars.
    • Deprecation Support: Support for the @[Deprecated] attribute on constants.

    Standard Library Highlights

    • OptionParser: Now supports GNU-style optional arguments.
    • Collections:
      • Hash#select and #reject now accept Enumerable arguments.
      • Added Enumerable#find! and #index! (raising variants).
      • Added Hash#update.
      • Added Enumerable#tally and #tally_by overloads that accept a hash.
    • Networking: Optimized URI.decode and added space_to_plus option in URI::Params.
    • Serialization: Iterator.from_json and #to_json are now implemented.
    • WebAssembly: Added an MVP implementation of a WebAssembly entrypoint.
  3. New features in Crystal 0.25.0

    master

    Crystal 0.25.0 added several language and standard library features:

    • Macros: Added macro verbatim blocks to avoid nesting and user-defined annotations.
    • String Handling: Added String#to_utf16, String.from_utf16, and String#starts_with?(re: Regex).
    • Serialization: Added JSON::Serializable and YAML::Serializable attribute-powered mappings, including support for BigDecimal and UUID.
    • IO: Added IO::Stapled to combine two unidirectional IOs into a single bidirectional one.
    • Math/Numbers: Added Float32 and Float64 constants, and Number#round with no arguments to round to the nearest whole number.
    • System: Added Process.chroot and support for aarch64-linux-musl target.
  4. Compiler enhancements in Crystal 1.12.0

    master

    The 1.12.0 release included several compiler-level updates:

    Configuration & CLI

    • Added CRYSTAL_CONFIG_CC compiler configuration.
    • The compiler now respects the NO_COLOR environment variable.
    • Windows users can now use the --static flag.
    • eval and spec now support --single-module and --threads flags.

    Codegen & Interpreter

    • Added --frame-pointers flag to control preservation of frame pointers.
    • Added x86-64 Solaris / illumos support.
    • On Windows, the interpreter now supports @[Link]'s DLL search order and automatically detects MSVC tools.

    Parser & Semantic

    • Top-level macros now use ::foo as their short_reference.
    • Improved support for calling #[]= with a block using method syntax.
  5. New features in Crystal 1.12.0

    master

    Crystal 1.12.0 introduced several language and standard library enhancements:

    Language

    • Operators: Operators ending in = now allow multiple parameters and blocks.

    Standard Library

    • Concurrency: Improved handling of interleaved backtraces in spawn unhandled exceptions; fixed blocking issues when opening/reading from fifo/chardev files; fixed Atomics and Locks for ARM, AArch64, and X86.
    • Files: Added IO::FileDescriptor::Handle.
    • Macros: Added new macro methods for lib-related nodes, Primitive, TypeOf, Alias, Asm, and AsmOperand.
    • Numeric: Added #%, #tdiv, and #remainder methods to BigRational.
    • Runtime: [Experimental] Added ReferenceStorage for manual allocation of references.
    • System: Added Signal#trap_handler? and Process.on_terminate. Also added the ability to set thread names.
    • Time: Added support for Etc/UTC time zone identifiers without requiring tzdb.
  6. New features in Crystal 1.14.0

    master

    Crystal 1.14.0 includes several new capabilities:

    Language & Compiler

    • Support for ^ in constant numeric expressions.
    • Initial support for external commands via the CLI.
    • The interpreter is now enabled on Windows.

    Standard Library

    • Windows Support: Added support for Windows on aarch64, including non-blocking file I/O (File#read, File#write, File#read_at), non-blocking Process.run standard streams, async DNS resolution, and System::User/System::Group implementations.
    • Collections: Added Slice#same?.
    • Numeric: Added floating-point manipulation functions for BigFloat.
    • Text: Added underscore_to_space option to String#titleize and support for Unicode 16.0.0.
    • Serialization: Added URI::Params::Serializable and URI JSON support (URI.from_json_object_key?, URI#to_json_object_key).
  7. Windows support improvements in Crystal 1.1.0

    master

    Significant progress was made in porting core networking and error handling to Windows:

    • Socket::Address and Socket::Addrinfo are now ported to win32.
    • WinError is now portable and included in the prelude.
    • WinError.wsa_value is available for accessing Windows Sockets error codes.
    • Socket::Handle is used as the protocol for socket file descriptors.
  8. Use `Int#tdiv` for truncated division

    master

    In Crystal 0.36.0, the / operator for Int was changed to perform floored division. If your logic requires truncated division (the behavior in older versions), you must explicitly use the tdiv method.

    Example:

    # Floored division (current behavior of /)
    10 / 3 # => 3
    -10 / 3 # => -4
    
    # Truncated division (use tdiv)
    -10.tdiv(3) # => -3