• Stars
    star
    113
  • Rank 310,115 (Top 7 %)
  • Language
    Perl
  • License
    Artistic License 2.0
  • Created over 11 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A modern object-oriented programming language implemented in Perl.

The Sidef Programming Language

Sidef is a modern, high-level, general-purpose programming language, inspired by Ruby, Raku and Julia.

            **   **         ****   *           *********   *********
          * * ** * *        ****   **          ** ** **    ** ** **
           **   **          ****   ***         *********   *  *  *
  **        **        **    ****   *  *        ******      ******
* * *     * * *     * * *   ****   ** **       ** **       ** **
 **        **        **     ****   ******      ******      *  *
       **   **              ****   *  *  *     *********   ***
     * * ** * *             ****   ** ** **    ** ** **    **
      **   **               ****   *********   *********   *
  • The main features of Sidef include:

    • object-oriented programming
    • functional programming
    • functional pattern matching
    • optional lazy evaluation
    • multiple dispatch
    • lexical scoping
    • lexical closures
    • keyword arguments
    • regular expressions
    • support for using Perl modules
    • optional dynamic type checking
    • big integers, rationals, floats and complex numbers

WWW

Q&A

Need help with Sidef? Feel free to ask questions here: https://github.com/trizen/sidef/discussions/categories/q-a

EXAMPLES

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]

Approximation of the gamma function:

define  = Num.e
define τ = Num.tau

func Γ(x, r=50) {
    x < r ? (__FUNC__(x+1, r) / x)
          : (sqrt(τ*x) * pow(x/ + 1/(12**x), x) / x)
}

for i in (1..10) {
    say ("%.14f" % Γ(i/3))
}

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)

Output:

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

ASCII generation 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"
}

Output:


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

More examples

INTERACTIVE MODE

sidef

TRY IT ONLINE

AVAILABILITY

LICENSE AND COPYRIGHT

  • Copyright (C) 2013-2023 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). You may obtain a copy of the full license at:

https://www.perlfoundation.org/artistic-license-20.html

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

More Repositories

1

youtube-viewer

Lightweight YouTube client for Linux
Perl
1,177
star
2

trizen

Lightweight AUR Package Manager
Perl
791
star
3

pipe-viewer

A lightweight YouTube client for Linux, without requiring an API key.
Perl
383
star
4

obmenu-generator

A fast menu generator for the Openbox Window Manager.
Perl
174
star
5

perl-scripts

A nice collection of day-to-day Perl scripts.
Perl
130
star
6

straw-viewer

**DEPRECATED** Use https://github.com/trizen/pipe-viewer instead.
Perl
108
star
7

menutray

An application menu through a GTK+ tray status icon.
Perl
62
star
8

clyrics

An extensible lyrics fetcher, with daemon support for cmus and mocp.
Perl
59
star
9

alsi

A command-line system information tool for Arch Linux.
Perl
34
star
10

language-benchmarks

A simple benchmark system for compiled and interpreted languages.
Perl
24
star
11

fbmenugen

Fluxbox menu generator (with support for icons)
Perl
18
star
12

lbry-viewer

Experimental Linux client for LBRY/Odysee.
Perl
14
star
13

project-euler

Personal solutions to various problems from projecteuler.net
Perl
13
star
14

oblogout-py3

Openbox Logout Menu, ported to Python 3.
Python
10
star
15

julia-scripts

Small programs written in Julia.
Julia
10
star
16

obbrowser

Recursively browse the filesystem through Openbox pipe menus (with icons).
Perl
10
star
17

experimental-projects

Highly experimental personal projects.
Perl
8
star
18

raku-rosettacode

Tasks from Rosettacode implemented in Raku
8
star
19

config-files

Configuration files.
Perl
7
star
20

smart-units

A simple command-line units converter. (written in Sidef)
6
star
21

sidef-scripts

A nice collection of Sidef scripts.
Ruby
6
star
22

cpp-learning

Simple C++ programs used in learning this complex language.
C++
5
star
23

Linux-DesktopFiles

Linux::DesktopFiles - a very fast Perl module for parsing application .desktop files.
Perl
5
star
24

raku-scripts

A small collection of Raku scripts.
Raku
4
star
25

fbrowse-tray

A file-browser through a GTK+ tray status icon.
Perl
3
star
26

sidef-book

The Sidef programming language book.
2
star
27

processing-scripts

Simple graphical scripts in Processing.
Processing
2
star
28

ruby-scripts

A small collection of Ruby scripts.
Ruby
2
star
29

corvinus2

The Corvinus Programming Language (v2)
Perl
2
star
30

Compression-Util

Implementation of various techniques used in data compression.
Perl
2
star
31

Data-Dump-Perl6

Pretty printing of data structures as Perl6 code (deprecated)
Perl
1
star
32

Math-Bacovia

Math::Bacovia - symbolic math library for Perl 5.
Perl
1
star
33

Perl-Tokenizer

Perl::Tokenizer - a tiny Perl code tokenizer.
Perl
1
star
34

rc

Rosetta Code output files
1
star
35

Math-Sidef

Perl interface to Sidef's mathematical library.
Perl
1
star
36

island

The Island programming language. (unimplemented idea)
1
star