A modern object-oriented programming language implemented in Perl. https://tio.run/#sidef

trizen 2f6a1f8aae - Parse 'ZERO WIDTH SPACE' (U+200B) as whitespace. 1 month ago
.github 7946ae034c Update FUNDING.yml 4 years ago
bin 2f78041420 Version 24.01 2 months ago
lib 2f6a1f8aae - Parse 'ZERO WIDTH SPACE' (U+200B) as whitespace. 1 month ago
scripts 2f6a1f8aae - Parse 'ZERO WIDTH SPACE' (U+200B) as whitespace. 1 month ago
t 7233bfc096 Code tidy the test files. 6 months ago
utils 07dd6edec3 modified: README.md 2 months ago
.gitignore cf33132dfd modified: .gitignore 3 years ago
Build.PL 76c87b23e9 Recommend the `forks` module and return a `Sidef::Module::OO` object from Block.thread(). 6 months ago
Changes 71ba3ae3cf Changed file permissions 8 years ago
LICENSE 805fbc1e8d - Fixed the interactive help when Sidef is installed. 7 years ago
MANIFEST ef17845c2c Added a few more RosettaCode scripts. 2 months ago
MANIFEST.SKIP efdddd2f90 - Added the Number `all_prime(...)` and `all_composite(...)` methods. 4 years ago
Makefile.PL 8e2910fefc Bump the mininum required version of `List::Util` to 1.45. 7 months ago
NUMBER_THEORY_TUTORIAL.md 07dd6edec3 modified: README.md 2 months ago
README.md 07dd6edec3 modified: README.md 2 months ago
TODO fe8303dc15 - Added the `PolyMod([...], m)` built-in class. 5 months ago
TUTORIAL.md 07dd6edec3 modified: README.md 2 months ago
_config.yml c28e099130 Set theme jekyll-theme-hacker 5 years ago

README.md

The Sidef Programming Language

Sidef is a modern, high-level programming language designed for versatile general-purpose applications, drawing inspiration from the principles of Ruby, Raku, and Julia.

            **   **         ****   *           *********   *********
          * * ** * *        ****   **          ** ** **    ** ** **
           **   **          ****   ***         *********   *  *  *
  **        **        **    ****   *  *        ******      ******
* * *     * * *     * * *   ****   ** **       ** **       ** **
 **        **        **     ****   ******      ******      *  *
       **   **              ****   *  *  *     *********   ***
     * * ** * *             ****   ** ** **    ** ** **    **
      **   **               ****   *********   *********   *
  • Key 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
    • Seamless integration with Perl modules
    • Optional dynamic type checking
    • Robust support for big integers, rationals, floats, and complex numbers

Resources

Questions & Answers

For assistance or inquiries regarding Sidef, please visit the dedicated discussion forum.

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]

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:


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

Additional Examples

INTERACTIVE MODE

sidef

TRY IT ONLINE

AVAILABILITY

LICENSE AND COPYRIGHT

  • Copyright (C) 2013-2024 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.