1
0
Fork
You've already forked sidef
0
forked from trizen/sidef
Modern object-oriented programming language implemented in Perl
  • Perl 60%
  • Ruby 39.6%
  • Shell 0.1%
  • Julia 0.1%
  • Raku 0.1%
Find a file
trizen 9b796c6d29
- Slightly better performance in Number all_prime(...) for native inputs.
- Also better performance in Number `is_plumb_pseudoprime(n)`, `is_perrin_pseudoprime(n)`, `is_frobenius_underwood_pseudoprime(n)` and `is_frobenius_khashin_pseudoprime(n)` for native integers `n`, when `Math::Prime::Util` is installed.
2023年03月31日 18:29:11 +03:00
.github Update FUNDING.yml 2019年11月04日 22:40:56 +02:00
bin bin/sidef: support for the --help and --version command-line arguments. 2023年03月17日 19:55:16 +02:00
lib - Slightly better performance in Number all_prime(...) for native inputs. 2023年03月31日 18:29:11 +03:00
scripts - Better performance in Number n.jordan_totient(k) for large n. 2023年03月28日 00:14:38 +03:00
share/sidef modified: share/sidef/Memoize.sm 2017年01月27日 13:53:47 +02:00
t Minor optimization in Number shift_left() for native unsigned integers for which the result is also a native integer. 2022年11月25日 00:02:41 +02:00
utils utils/pod_generator.pl: extract the name of the parameters of each method. 2022年11月07日 15:19:14 +02:00
.gitignore modified: .gitignore 2020年12月09日 16:22:52 +02:00
_config.yml Set theme jekyll-theme-hacker 2018年11月17日 00:31:23 +02:00
Build.PL Minor optimization in Number all_prime(...) when one of the terms is not prime. 2022年04月06日 15:55:29 +03:00
Changes Changed file permissions 2015年07月31日 12:34:55 +03:00
LICENSE - Fixed the interactive help when Sidef is installed. 2016年12月07日 02:15:12 +02:00
Makefile.PL Implmented basic support for using Kim Walisch's primecount tool for large n in Number _prime_count. (disabled by default) 2023年01月11日 01:03:43 +02:00
MANIFEST - Better performance in Number n.jordan_totient(k) for large n. 2023年03月28日 00:14:38 +03:00
MANIFEST.SKIP - Added the Number all_prime(...) and all_composite(...) methods. 2019年11月05日 11:43:16 +02:00
README.md 2023 2023年01月01日 22:04:14 +02:00
TODO - Added the Polynomial() built-in class. 2021年07月27日 15:00:13 +03:00
TUTORIAL.md - Optimized Number is_lucas(n) for better performance with n <= 10^1000. 2022年08月07日 13:37:19 +03:00

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 e = Num.e
define τ = Num.tau
func Γ(x, r=50) {
 x < r ? (__FUNC__(x+1, r) / x)
 : (sqrt(τ*x) * pow(x/e + 1/(12*e*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

  • 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.