1
7
Fork
You've already forked sidef
1
Modern object-oriented programming language implemented in Perl https://tio.run/#sidef
  • Ruby 61.6%
  • Perl 37.8%
  • Shell 0.2%
  • Julia 0.2%
  • Raku 0.1%
Find a file
trizen 4d85134049
- Use PARI/GP in znlog() when Num!USE_PARI_GP=true.
Much faster for large modulus.
 Num!USE_PARI_GP = true
 say znlog(expmod(97, 123456, 2**128 + 1), 97, 2**128 + 1) #=> 123456 (takes 0.67s; previously: 85.1s)
2026年07月13日 08:17:52 +03:00
.github Update FUNDING.yml 2019年11月04日 22:40:56 +02:00
bin Version 26.07 2026年07月02日 15:19:22 +03:00
lib - Use PARI/GP in znlog() when Num!USE_PARI_GP=true. 2026年07月13日 08:17:52 +03:00
scripts Added more tests for the antidivisor_sigma(n,k) function. 2026年07月10日 19:02:52 +03:00
t - Changed the value of bernoulli(1) from 1/2 to -1/2. 2026年06月28日 14:57:43 +03:00
utils Version 26.07 2026年07月02日 15:19:22 +03:00
.gitignore Version 24.05 2024年05月12日 10:30:07 +03:00
_config.yml Set theme jekyll-theme-hacker 2018年11月17日 00:31:23 +02:00
Build.PL Version 26.04 2026年04月01日 15:32:54 +03:00
Changes Changed file permissions 2015年07月31日 12:34:55 +03:00
COMPUTATIONAL_ALGEBRA_GUIDE.md modified: COMPUTATIONAL_ALGEBRA_GUIDE.md -- fix summary 2026年05月20日 12:20:17 +03:00
CONTRIBUTING.md Version 26.04 2026年04月01日 15:32:54 +03:00
LICENSE - Fixed the interactive help when Sidef is installed. 2016年12月07日 02:15:12 +02:00
Makefile.PL Version 26.04 2026年04月01日 15:32:54 +03:00
MANIFEST Version 26.07 2026年07月02日 15:19:22 +03:00
MANIFEST.SKIP Version 24.05 2024年05月12日 10:30:07 +03:00
NUMBER_THEORY_CHEATSHEET.md modified: NUMBER_THEORY_CHEATSHEET.md -- align comments nicely 2026年07月04日 09:09:43 +03:00
NUMBER_THEORY_GUIDE.md Version 26.07 2026年07月02日 15:19:22 +03:00
NUMBER_THEORY_REFERENCE.md Version 26.07 2026年07月02日 15:19:22 +03:00
README.md modified: README.md -- fix typo 2026年05月20日 12:11:26 +03:00
SECURITY.md new file: SECURITY.md 2026年04月04日 12:27:01 +03:00
SIDEF_ADVANCED_GUIDE.md Version 26.07 2026年07月02日 15:19:22 +03:00
SIDEF_BEGINNER_GUIDE.md Version 26.07 2026年07月02日 15:19:22 +03:00
TODO - Added the PolyMod([...], m) built-in class. 2023年10月18日 11:24:50 +03:00

The Sidef Programming Language

 ** ** **** * ********* *********
 * * ** * * **** ** ** ** ** ** ** **
 ** ** **** *** ********* * * *
 ** ** ** **** * * ****** ******
* * * * * * * * * **** ** ** ** ** ** **
 ** ** ** **** ****** ****** * *
 ** ** **** * * * ********* ***
 * * ** * * **** ** ** ** ** ** ** **
 ** ** **** ********* ********* *

A modern, high-level programming language for versatile general-purpose applications

WebsiteTutorialDocumentationTry OnlineDiscussions

CPAN Perl License


🌟 Why Sidef?

Sidef is a modern, expressive programming language that combines the elegance of Ruby, the versatility of Raku, and the mathematical power of a built-in computer algebra system. It features exact rational arithmetic by default, an extensive number theory library (1,000+ functions), and seamless Perl module integration — making it equally at home for scripting, mathematical research, and general-purpose programming.

# Exact rational arithmetic — no floating-point surprises
say (1/3 + 1/6) #=> 1/2
# Built-in number theory
say (2**127 - 1) #=> 170141183460469231731687303715884105727 (Mersenne prime)
say factor(2**64 - 1) #=> [3, 5, 17, 257, 641, 65537, 6700417]
# Expressive, concise syntax
say 29.primes #=> [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

Key Features

Programming Paradigms

  • Object-oriented programming with multiple dispatch
  • Functional programming and pattern matching
  • Lexical scoping and closures
  • Keyword arguments and optional lazy evaluation

Numeric Computing

  • Exact rational numbers by default
  • Arbitrary-precision integers, floats, and complex numbers
  • 1,000+ built-in number theory functions (backed by GMP, MPFR, MPC)
  • Gaussian integers, quaternions, matrices, polynomials

Language & Integration

  • Regular expressions and string interpolation
  • Optional dynamic type checking
  • Seamless Perl module integration
  • REPL with interactive help (-H flag)

🚀 Quick Start

Prerequisites

Sidef requires Perl 5.18+ and the following C libraries:

Library Purpose
GMP Big integers and rationals
MPFR Arbitrary-precision floats
MPC Arbitrary-precision complex numbers

Debian/Ubuntu:

sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev

Arch Linux:

sudo pacman -S gmp mpfr libmpc

Termux:

pkg install perl make clang libgmp libmpfr libmpc

Installation

Via CPAN:

cpan Sidef
# or (skip tests for faster install):
cpan -T Sidef
# or with cpanminus:
cpanm Sidef

Build from source:

git clone https://github.com/trizen/sidef.git
cd sidef
perl Makefile.PL
make
make test
make install

Via AUR:

trizen -S sidef

Platform packages:

Hello World

say "Hello, World!"
sidef hello.sf
sidef -E 'say "Hello, World!"'
sidef -i # start the REPL

Try It Online

Experiment with Sidef instantly at Try It Online without any installation.

🔤 Language at a Glance

Variables and Types

var name = "Sidef" # String
var num = 42 # Number (exact integer)
var ratio = 3/7 # Number (exact rational)
var arr = [1, 2, 3] # Array
var hash = Hash(a => 1, b => 2) # Hash
var block = {|n| n.is_prime } # Block

Functions and Pattern Matching

func greet(name) { "Hello, #{name}!" }
say greet("world") #=> Hello, world!
# Multi-dispatch / pattern matching
func fib({|n| n == 0 }) { 0 }
func fib({|n| n == 1 }) { 1 }
func fib(n) { fib(n-1) + fib(n-2) }
say fib(10) #=> 55

Object-Oriented Programming

class Animal(name, sound) {
 method speak { say "#{name} says #{sound}!" }
}
class Dog(name, sound="woof") < Animal {
 method fetch { say "#{name} fetches the ball!" }
}
var d = Dog("Rex")
d.speak #=> Rex says woof!
d.fetch #=> Rex fetches the ball!

Functional Programming

var nums = 1..10 # RangeNumber object
# Map, filter, reduce
var evens = nums.grep { .is_even } #=> [2, 4, 6, 8, 10]
var squares = nums.map { |n| n**2 } #=> [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
var total = nums.reduce { |a, b| a + b } #=> 55
say evens
say squares
say total

Number Theory

say primes(50, 100) # array of primes in range [50, 100]
say prime_count(10**9) # number of primes up to 10^9
say prime(100) # 100th prime => 541
say 12.divisors # [1, 2, 3, 4, 6, 12]
say euler_phi(100) # Euler's totient => 40
say gcd(48, 18) # => 6
say is_prime(2**521 - 1) # Mersenne prime check => true

Lazy Evaluation

# Infinite lazy list of primes
var lazy_primes = (2..Inf -> lazy.grep { .is_prime })
say lazy_primes.first(10) #=> [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

⌨️ Command-Line Reference

sidef [options] [script.sf] [script-arguments]
Flag Description
-E 'code' Execute a one-line program
-e 'code' Alias for -E
-i [file] Start the interactive REPL (optionally loading a file)
-c Compile script to a stand-alone Perl program
-C Check syntax only (parse without execution)
-r Deparse program back to Sidef code
-R lang Deparse to another language (perl, sidef)
-P int Set floating-point precision in bits (default: 192)
-O level Optimization level: 0 (none), 1 (recommended), 2 (max)
-s Enable precompilation (cache compiled code)
-t Test mode: treat all arguments as script files
-D Dump the Abstract Syntax Tree (AST)
-H Interactive help mode for exploring documentation

Examples:

sidef -E 'say 10.of { |i| i**2 }' # one-liner
sidef -i # start REPL
sidef -i script.sf # run script in REPL
sidef -C script.sf # syntax check
sidef -c -o output.pl script.sf # compile to Perl
sidef -P 400 -E 'say sqrt(2)' # 400-bit precision
sidef -O1 script.sf # with optimization
sidef -r script.sf # deparse to Sidef
sidef -t tests/*.sf # run test files

🖥️ Interactive Mode (REPL)

Start the REPL with sidef -i:

$ sidef -i
sidef> say "Hello!"
Hello!
sidef> x = 2**64
18446744073709551616
sidef> x.is_prime
false
sidef> is_prime(2**127 - 1)
true
sidef> 1..10 -> map { .square }.sum
385
sidef> quit

Use -H to open interactive documentation help:

sidef -H

🎯 Code Examples

Classes and Inheritance

class Shape {
 method area { die "Not implemented" }
 method describe { say "I am a #{self.class} with area #{self.area}" }
}
class Circle(r) < Shape {
 method area { Num.pi * r**2 }
}
class Rectangle(w, h) < Shape {
 method area { w * h }
}
Circle(5).describe #=> I am a Circle with area 78.539...
Rectangle(4, 6).describe #=> I am a Rectangle with area 24

Functional Array Processing

# FizzBuzz in one line
say (1..20 -> map { |n|
 n%%15 ? "FizzBuzz" : (n%%3 ? "Fizz" : (n%%5 ? "Buzz" : n))
})
# Pipeline style
(1..50).grep { .is_prime } \
 .map { .square } \
 .first(5) \
 .say #=> [4, 9, 25, 49, 121]

Number Theory One-Liners

say 100.by { .is_prime } # first 100 primes
say sum(1..100) #=> 5050
say prod(1..10) #=> 3628800 (10!)
say { .euler_phi }.map(1..10) #=> [1, 1, 2, 2, 4, 2, 6, 4, 6, 4]

The Y Combinator

Demonstrating functional programming with the Y combinator:

var y = ->(f) {->(g) {g(g)}(->(g) { f(->(*args) {g(g)(args...)})})}
var fac = ->(f) { ->(n) { n < 2 ? 1 : (n * f(n-1)) } }
say 10.of { |i| y(fac)(i) } #=> [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
var fib = ->(f) { ->(n) { n < 2 ? n : (f(n-2) + f(n-1)) } }
say 10.of { |i| y(fib)(i) } #=> [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

Sierpinski Triangle

ASCII generation of the Sierpinski triangle:

func sierpinski_triangle(n) {
 var triangle = ['*']
 { |i|
 var sp = (' ' * 2**i)
 triangle = (triangle.map {|x| sp + x + sp} +
 triangle.map {|x| x + ' ' + x})
 } * n
 triangle.join("\n")
}
say sierpinski_triangle(4)
Show Output
 *
 * *
 * *
 * * * *
 * *
 * * * *
 * * * *
 * * * * * * * *
 * *
 * * * *
 * * * *
 * * * * * * * *
 * * * *
 * * * * * * * *
 * * * * * * * *
* * * * * * * * * * * * * * * *

Mandelbrot Set

ASCII visualization of the Mandelbrot set:

func mandelbrot(z, r=20) {
 var c = z
 r.times {
 z = (z*z + c)
 return true if (z.abs > 2)
 }
 return false
}
for y in (1 `downto` -1 `by` 0.05) {
 for x in (-2 `upto` 0.5 `by` 0.0315) {
 print(mandelbrot(Complex(x, y)) ? ' ' : '#')
 }
 print "\n"
}
Show Output

 #
 # ### #
 ########
 #########
 ######
 ## ## ############ #
 ### ################### #
 #############################
 ############################
 ################################
 ################################
 #################################### #
 # # ###################################
 ########### ###################################
 ########### #####################################
 ############## ####################################
 ####################################################
 ######################################################
#########################################################################
 ######################################################
 ####################################################
 ############## ####################################
 ########### #####################################
 ########### ###################################
 # # ###################################
 #################################### #
 ################################
 ################################
 ############################
 #############################
 ### ################### #
 ## ## ############ #
 ######
 #########
 ########
 # ### #
 #

📚 Documentation & Learning Resources

Resource Description
📘 Sidef GitBook The complete language reference — covers everything
📄 Beginner's Guide Start here if you're new to Sidef
📝 Advanced Guide Comprehensive language tutorial
🔢 Number Theory Guide Deep dive into Sidef's mathematical superpowers
🔢 Number Theory Reference Complete function reference for number theory

Example Code

Resource Description
📂 sidef-scripts Hundreds of real Sidef programs — the best way to learn by reading
🌹 RosettaCode — Sidef Classic programming tasks solved in Sidef, side-by-side with other languages

💬 Community & Support

Have questions or need help? Join the conversation:

📦 Distribution Availability

Platform Package Link
CPAN Sidef metacpan.org
Package Search Multiple distributions pkgs.org
Arch Linux sidef (AUR) AUR Package
Slackware perl-Sidef SlackBuilds.org

🤝 Contributing

Contributions of all kinds are welcome — bug reports, feature suggestions, documentation improvements, and pull requests. Please read CONTRIBUTING.md for guidelines on:

  • Reporting bugs and suggesting features
  • Setting up a development environment
  • Code style and commit message conventions
  • The pull request review process

Copyright © 2013-2026 Daniel Șuteu, Ioana Fălcușan

This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License (2.0).

Full license: perlfoundation.org/artistic-license-20.html


Made with ❤️ by the Sidef community

Star us on GitHub📖 Read the docs💬 Join discussions