task_url
stringlengths
30
116
task_name
stringlengths
2
86
task_description
stringlengths
0
14.4k
language_url
stringlengths
2
53
language_name
stringlengths
1
52
code
stringlengths
0
61.9k
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Liberty_BASIC
Liberty BASIC
  drive1$ = left$(Drives$,1) run "cmd.exe /";drive1$;" dir & pause"  
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Limbo
Limbo
implement Runls;   include "sys.m"; sys: Sys; include "draw.m"; include "sh.m";   Runls: module { init: fn(ctxt: ref Draw->Context, args: list of string); };   init(ctxt: ref Draw->Context, args: list of string) { sys = load Sys Sys->PATH; ls := load Command "/dis/ls.dis"; if(ls == nil) die("Couldn't load /dis/ls...
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Batch_File
Batch File
@echo off set /p x= set /a fs=%x%-1 set y=%x% FOR /L %%a IN (%fs%, -1, 1) DO SET /a y*=%%a if %x% EQU 0 set y=1 echo %y% pause exit
http://rosettacode.org/wiki/Exponentiation_operator
Exponentiation operator
Most programming languages have a built-in implementation of exponentiation. Task Re-implement integer exponentiation for both   intint   and   floatint   as both a procedure,   and an operator (if your language supports operator definition). If the language supports operator (or procedure) overloading, then an ov...
#Prolog
Prolog
:- arithmetic_function((^^)/2). :- op(200, xfy, user:(^^)).
http://rosettacode.org/wiki/Exponentiation_operator
Exponentiation operator
Most programming languages have a built-in implementation of exponentiation. Task Re-implement integer exponentiation for both   intint   and   floatint   as both a procedure,   and an operator (if your language supports operator definition). If the language supports operator (or procedure) overloading, then an ov...
#PureBasic
PureBasic
Procedure powI(base, exponent) Protected i, result.d If exponent < 0 If base = 1 result = 1 EndIf ProcedureReturn result EndIf result = 1 For i = 1 To exponent result * base Next ProcedureReturn result EndProcedure   Procedure.f powF(base.f, exponent) Protected i, magExponent = Abs...
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#SNOBOL4
SNOBOL4
I = 1 LOOP FIZZBUZZ = "" EQ(REMDR(I, 3), 0)  :F(TRY_5) FIZZBUZZ = FIZZBUZZ "FIZZ" TRY_5 EQ(REMDR(I, 5), 0)  :F(DO_NUM) FIZZBUZZ = FIZZBUZZ "BUZZ" DO_NUM IDENT(FIZZBUZZ, "")  :F(SHOW) FIZZBUZZ = I SHOW OUTPUT = FIZZBUZZ I =...
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#Delphi
Delphi
  program Execute_Brain;   {$APPTYPE CONSOLE}   uses Winapi.Windows, System.SysUtils;   const DataSize = 1024; // Size of Data segment MaxNest = 1000; // Maximum nesting depth of []   function Readkey: Char; var InputRec: TInputRecord; NumRead: Cardinal; ...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#Erlang
Erlang
-module(evolution). -export([run/0]).   -define(MUTATE, 0.05). -define(POPULATION, 100). -define(TARGET, "METHINKS IT IS LIKE A WEASEL"). -define(MAX_GENERATIONS, 1000).   run() -> evolve_gens().   evolve_gens() -> Initial = random_string(length(?TARGET)), evolve_gens(Initial,0,fitness(Initial)). evolve_gens(Pa...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#Luck
Luck
function fib(x: int): int = ( let cache = {} in let fibc x = if x<=1 then x else ( if x not in cache then cache[x] = fibc(x-1) + fibc(x-2); cache[x] ) in fibc(x) );; for x in range(10) do print(fib(x))
http://rosettacode.org/wiki/Execute_HQ9%2B
Execute HQ9+
Task Implement a   HQ9+   interpreter or compiler.
#Tcl
Tcl
import "os" for Process   var hq9plus = Fn.new { |code| var acc = 0 var sb = "" for (c in code) { if (c == "h" || c == "H") { sb = sb + "Hello, world!\n" } else if (c == "q" || c == "Q") { sb = sb + code + "\n" } else if (c == "9") { for (i in 99.....
http://rosettacode.org/wiki/Execute_a_Markov_algorithm
Execute a Markov algorithm
Execute a Markov algorithm You are encouraged to solve this task according to the task description, using any language you may know. Task Create an interpreter for a Markov Algorithm. Rules have the syntax: <ruleset> ::= ((<comment> | <rule>) <newline>+)* <comment> ::= # {<any character>} <rule> ::= <pattern> <wh...
#Scheme
Scheme
  (define split-into-lines (lambda (str) (let loop ((index 0) (result '())) (let ((next-index (string-index str #\newline index))) (if next-index (loop (+ next-index 1) (cons (substring str index next-index) result)) (reverse (cons (substring ...
http://rosettacode.org/wiki/Exceptions
Exceptions
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops This task is to give an example of an exception handling routine and to "throw" a new exception. Related task   Exceptions Through Nested Calls
#Pascal
Pascal
# throw an exception die "Danger, danger, Will Robinson!";   # catch an exception and show it eval { die "this could go wrong mightily"; }; print $@ if $@;   # rethrow die $@;
http://rosettacode.org/wiki/Exceptions
Exceptions
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops This task is to give an example of an exception handling routine and to "throw" a new exception. Related task   Exceptions Through Nested Calls
#Perl
Perl
# throw an exception die "Danger, danger, Will Robinson!";   # catch an exception and show it eval { die "this could go wrong mightily"; }; print $@ if $@;   # rethrow die $@;
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Lingo
Lingo
sx = xtra("Shell").new() if the platform contains "win" then put sx.shell_cmd("dir") else put sx.shell_cmd("ls") end if
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Locomotive_Basic
Locomotive Basic
LIST
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Logo
Logo
print first butfirst shell [ls -a]  ; ..
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#BBC_BASIC
BBC BASIC
*FLOAT64 @% = &1010   PRINT FNfactorial(18) END   DEF FNfactorial(n) IF n <= 1 THEN = 1 ELSE = n * FNfactorial(n-1)
http://rosettacode.org/wiki/Exponentiation_operator
Exponentiation operator
Most programming languages have a built-in implementation of exponentiation. Task Re-implement integer exponentiation for both   intint   and   floatint   as both a procedure,   and an operator (if your language supports operator definition). If the language supports operator (or procedure) overloading, then an ov...
#Python
Python
MULTIPLY = lambda x, y: x*y   class num(float): # the following method has complexity O(b) # rather than O(log b) via the rapid exponentiation def __pow__(self, b): return reduce(MULTIPLY, [self]*b, 1)   # works with ints as function or operator print num(2).__pow__(3) print num(2) ** 3   # works wi...
http://rosettacode.org/wiki/Exponentiation_operator
Exponentiation operator
Most programming languages have a built-in implementation of exponentiation. Task Re-implement integer exponentiation for both   intint   and   floatint   as both a procedure,   and an operator (if your language supports operator definition). If the language supports operator (or procedure) overloading, then an ov...
#Quackery
Quackery
[ $ "bigrat.qky" loadfile ] now!   forward is ** ( n n --> n )   [ dup 1 < iff [ 2drop 1 ] done dup 1 & iff [ 1 - dip dup ** * ] else [ 1 >> dip [ dup * ] ** ] ] resolves ** ( n n --> n )   forward is...
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#SNUSP
SNUSP
SELECT CASE WHEN MOD(level,15)=0 THEN 'FizzBuzz' WHEN MOD(level,3)=0 THEN 'Fizz' WHEN MOD(level,5)=0 THEN 'Buzz' ELSE TO_CHAR(level) END FizzBuzz FROM dual CONNECT BY LEVEL <= 100;
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#dodo0
dodo0
#Import some functions clojure('count', 1) -> size clojure('nth', 2) -> charAt clojure('inc', 1) -> inc clojure('dec', 1) -> dec clojure('char', 1) -> char clojure('int', 1) -> int clojure('read-line', 0) -> readLine   #The characters we will need charAt("\n", 0) -> newLine charAt("@", 0) -> exitCommand charAt("+", 0) ...
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#Euphoria
Euphoria
constant table = "ABCDEFGHIJKLMNOPQRSTUVWXYZ " function random_generation(integer len) sequence s s = rand(repeat(length(table),len)) for i = 1 to len do s[i] = table[s[i]] end for return s end function   function mutate(sequence s, integer n) for i = 1 to length(s) do if rand(n)...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#Lush
Lush
(de fib-rec (n) (if (< n 2) n (+ (fib-rec (- n 2)) (fib-rec (- n 1)))))
http://rosettacode.org/wiki/Execute_HQ9%2B
Execute HQ9+
Task Implement a   HQ9+   interpreter or compiler.
#Ursa
Ursa
import "os" for Process   var hq9plus = Fn.new { |code| var acc = 0 var sb = "" for (c in code) { if (c == "h" || c == "H") { sb = sb + "Hello, world!\n" } else if (c == "q" || c == "Q") { sb = sb + code + "\n" } else if (c == "9") { for (i in 99.....
http://rosettacode.org/wiki/Execute_a_Markov_algorithm
Execute a Markov algorithm
Execute a Markov algorithm You are encouraged to solve this task according to the task description, using any language you may know. Task Create an interpreter for a Markov Algorithm. Rules have the syntax: <ruleset> ::= ((<comment> | <rule>) <newline>+)* <comment> ::= # {<any character>} <rule> ::= <pattern> <wh...
#SequenceL
SequenceL
  import <Utilities/Sequence.sl>;   Rule ::= ( pattern : char(1), replacement : char(1), terminal : bool);   ReplaceResult ::= (newString : char(1), wasReplaced : bool);   main(args(2)) := markov(createRule(split(args[1], '\n')), 1, args[2]);   createRule(line(1)) := let containsComme...
http://rosettacode.org/wiki/Execute_a_Markov_algorithm
Execute a Markov algorithm
Execute a Markov algorithm You are encouraged to solve this task according to the task description, using any language you may know. Task Create an interpreter for a Markov Algorithm. Rules have the syntax: <ruleset> ::= ((<comment> | <rule>) <newline>+)* <comment> ::= # {<any character>} <rule> ::= <pattern> <wh...
#SNOBOL4
SNOBOL4
  #!/bin/sh exec "snobol4" "-r" "$0" "$@" * * http://rosettacode.org/wiki/Execute_a_Markov_algorithm * define('repl(s1,s2,s3)c,t,findc') :(repl_end) repl s2 len(1) . c = :f(freturn) findc = break(c) . t len(1) s2 = pos(0) s2 repl_1 s1 findc = :f(repl_2) s1 s2 = :f(repl...
http://rosettacode.org/wiki/Exceptions
Exceptions
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops This task is to give an example of an exception handling routine and to "throw" a new exception. Related task   Exceptions Through Nested Calls
#Phix
Phix
throw("oh no") throw(1) throw(501,{"she",made[me],Do(it)})
http://rosettacode.org/wiki/Exceptions
Exceptions
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops This task is to give an example of an exception handling routine and to "throw" a new exception. Related task   Exceptions Through Nested Calls
#PHL
PHL
module exceptions;   extern printf;   struct @MyException : @Exception {   };   @Void func throws ex [ throw new @MyException; ]   @Integer main [ try func(); catch (e) { if (e::getType == "MyException") { printf("MyException thrown!\n"); } else { printf("Unhandled exception!\n"); } } return 0; ]
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Logtalk
Logtalk
os::shell('ls -a').
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Lua
Lua
-- just executing the command os.execute("ls")   -- to execute and capture the output, use io.popen local f = io.popen("ls") -- store the output in a "file" print( f:read("*a") ) -- print out the "file"'s content
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#M4
M4
syscmd(ifdef(`__windows__',`dir',`ls'))
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#bc
bc
#! /usr/bin/bc -q   define f(x) { if (x <= 1) return (1); return (f(x-1) * x) } f(1000) quit
http://rosettacode.org/wiki/Exponentiation_operator
Exponentiation operator
Most programming languages have a built-in implementation of exponentiation. Task Re-implement integer exponentiation for both   intint   and   floatint   as both a procedure,   and an operator (if your language supports operator definition). If the language supports operator (or procedure) overloading, then an ov...
#R
R
# Method pow <- function(x, y) { x <- as.numeric(x) y <- as.integer(y) prod(rep(x, y)) } #Operator "%pow%" <- function(x,y) pow(x,y)   pow(3, 4) # 81 2.5 %pow% 2 # 6.25
http://rosettacode.org/wiki/Exponentiation_operator
Exponentiation operator
Most programming languages have a built-in implementation of exponentiation. Task Re-implement integer exponentiation for both   intint   and   floatint   as both a procedure,   and an operator (if your language supports operator definition). If the language supports operator (or procedure) overloading, then an ov...
#Racket
Racket
#lang racket (define (^ base expt) (for/fold ((acum 1)) ((i (in-range expt))) (* acum base)))   (^ 5 2) ; 25 (^ 5.0 2) ; 25.0
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#SQL
SQL
SELECT CASE WHEN MOD(level,15)=0 THEN 'FizzBuzz' WHEN MOD(level,3)=0 THEN 'Fizz' WHEN MOD(level,5)=0 THEN 'Buzz' ELSE TO_CHAR(level) END FizzBuzz FROM dual CONNECT BY LEVEL <= 100;
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#E
E
USE: brainf***   "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++." run-brainf***
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#F.23
F#
  //A functional implementation of Evolutionary algorithm //Nigel Galloway February 7th., 2018 let G=System.Random 23 let fitness n=Array.fold2(fun a n g->if n=g then a else a+1) 0 n ("METHINKS IT IS LIKE A WEASEL".ToCharArray()) let alphabet="QWERTYUIOPASDFGHJKLZXCVBNM ".ToCharArray() let mutate (n:char[]) g=Array.ite...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#M2000_Interpreter
M2000 Interpreter
  Inventory K=0:=0,1:=1 fib=Lambda K (x as decimal)-> { If Exist(K, x) Then =Eval(K) :Exit Def Ret as Decimal Ret=If(x>1->Lambda(x-1)+Lambda(x-2), x) Append K, x:=Ret =Ret } \\ maximum 139 For i=1 to 139 { Print Fib(i) }  
http://rosettacode.org/wiki/Execute_HQ9%2B
Execute HQ9+
Task Implement a   HQ9+   interpreter or compiler.
#Ursala
Ursala
import "os" for Process   var hq9plus = Fn.new { |code| var acc = 0 var sb = "" for (c in code) { if (c == "h" || c == "H") { sb = sb + "Hello, world!\n" } else if (c == "q" || c == "Q") { sb = sb + code + "\n" } else if (c == "9") { for (i in 99.....
http://rosettacode.org/wiki/Execute_a_Markov_algorithm
Execute a Markov algorithm
Execute a Markov algorithm You are encouraged to solve this task according to the task description, using any language you may know. Task Create an interpreter for a Markov Algorithm. Rules have the syntax: <ruleset> ::= ((<comment> | <rule>) <newline>+)* <comment> ::= # {<any character>} <rule> ::= <pattern> <wh...
#Swift
Swift
import Foundation   func setup(ruleset: String) -> [(String, String, Bool)] { return ruleset.componentsSeparatedByCharactersInSet(NSCharacterSet.newlineCharacterSet()) .filter { $0.rangeOfString("^s*#", options: .RegularExpressionSearch) == nil } .reduce([(String, String, Bool)]()) { rules, line in ...
http://rosettacode.org/wiki/Exceptions
Exceptions
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops This task is to give an example of an exception handling routine and to "throw" a new exception. Related task   Exceptions Through Nested Calls
#PHP
PHP
class MyException extends Exception { // Custom exception attributes & methods }
http://rosettacode.org/wiki/Exceptions
Exceptions
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops This task is to give an example of an exception handling routine and to "throw" a new exception. Related task   Exceptions Through Nested Calls
#PicoLisp
PicoLisp
(catch 'thisLabel # Catch this label (println 1) # Do some processing (print '1') (throw 'thisLabel 2) # Abort processing and return '2' (println 3) ) # This is never reached
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Make
Make
contents=$(shell cat foo) curdir=`pwd`
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Maple
Maple
ssystem("dir");
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Beads
Beads
beads 1 program Factorial // only works for cardinal numbers 0..N calc main_init log to_str(Iterative(4)) // 24 log to_str(Recursive(5)) // 120   calc Iterative( n:num -- number of iterations ):num -- result var total = 1 loop from:2 to:n index:ix total = ix * total return total   calc Recursive ditt...
http://rosettacode.org/wiki/Exponentiation_operator
Exponentiation operator
Most programming languages have a built-in implementation of exponentiation. Task Re-implement integer exponentiation for both   intint   and   floatint   as both a procedure,   and an operator (if your language supports operator definition). If the language supports operator (or procedure) overloading, then an ov...
#Raku
Raku
subset Natural of Int where { $^n >= 0 }   multi pow (0, 0) { fail '0**0 is undefined' } multi pow ($base, Natural $exp) { [*] $base xx $exp } multi pow ($base, Int $exp) { 1 / pow $base, -$exp }   sub infix:<***> ($a, $b) { pow $a, $b }   # Testing   say pow .75, -5; say .75 *** -5;
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Squirrel
Squirrel
function Fizzbuzz(n) { for (local i = 1; i <= n; i += 1) { if (i % 15 == 0) print ("FizzBuzz\n") else if (i % 5 == 0) print ("Buzz\n") else if (i % 3 == 0) print ("Fizz\n") else { print (i + "\n") } } } Fizzbuzz(100);
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#Elena
Elena
USE: brainf***   "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++." run-brainf***
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#Factor
Factor
USING: arrays formatting io kernel literals math prettyprint random sequences strings ; FROM: math.extras => ... ; IN: rosetta-code.evolutionary-algorithm   CONSTANT: target "METHINKS IT IS LIKE A WEASEL" CONSTANT: mutation-rate 0.1 CONSTANT: num-children 25 CONSTANT: valid-chars $[ CHAR: A ... CHAR: Z >array { 32 ...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#M4
M4
define(`fibo',`ifelse(0,$1,0,`ifelse(1,$1,1, `eval(fibo(decr($1)) + fibo(decr(decr($1))))')')')dnl define(`loop',`ifelse($1,$2,,`$3($1) loop(incr($1),$2,`$3')')')dnl loop(0,15,`fibo')
http://rosettacode.org/wiki/Execute_HQ9%2B
Execute HQ9+
Task Implement a   HQ9+   interpreter or compiler.
#Wren
Wren
import "os" for Process   var hq9plus = Fn.new { |code| var acc = 0 var sb = "" for (c in code) { if (c == "h" || c == "H") { sb = sb + "Hello, world!\n" } else if (c == "q" || c == "Q") { sb = sb + code + "\n" } else if (c == "9") { for (i in 99.....
http://rosettacode.org/wiki/Execute_a_Markov_algorithm
Execute a Markov algorithm
Execute a Markov algorithm You are encouraged to solve this task according to the task description, using any language you may know. Task Create an interpreter for a Markov Algorithm. Rules have the syntax: <ruleset> ::= ((<comment> | <rule>) <newline>+)* <comment> ::= # {<any character>} <rule> ::= <pattern> <wh...
#Tcl
Tcl
package require Tcl 8.5 if {$argc < 3} {error "usage: $argv0 ruleFile inputFile outputFile"} lassign $argv ruleFile inputFile outputFile   # Read the file of rules set rules {} set f [open $ruleFile] foreach line [split [read $f] \n[close $f]] { if {[string match "#*" $line] || $line eq ""} continue if {[regexp...
http://rosettacode.org/wiki/Exceptions
Exceptions
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops This task is to give an example of an exception handling routine and to "throw" a new exception. Related task   Exceptions Through Nested Calls
#PL.2FI
PL/I
  /* Define a new exception, called "my_condition". */ on condition (my_condition) snap begin; put skip list ('My condition raised.'); end;   /* Raise that exception */ signal condition (my_condition);   /* Raising that exception causes the message "My condition raised" */ /* to be printed, and execution then resume...
http://rosettacode.org/wiki/Exceptions
Exceptions
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops This task is to give an example of an exception handling routine and to "throw" a new exception. Related task   Exceptions Through Nested Calls
#PL.2FpgSQL
PL/pgSQL
  BEGIN raise exception 'this is a generic user exception'; raise exception division_by_zero; END;  
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
Run["ls"]
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#MATLAB
MATLAB
>> system('PAUSE')   Press any key to continue . . .     ans =   0  
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Maxima
Maxima
system("dir > list.txt")$
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#beeswax
beeswax
p < _>1FT"pF>M"p~.~d >Pd >~{Np d <
http://rosettacode.org/wiki/Exponentiation_operator
Exponentiation operator
Most programming languages have a built-in implementation of exponentiation. Task Re-implement integer exponentiation for both   intint   and   floatint   as both a procedure,   and an operator (if your language supports operator definition). If the language supports operator (or procedure) overloading, then an ov...
#Retro
Retro
: pow ( bp-n ) 1 swap [ over * ] times nip ;
http://rosettacode.org/wiki/Exponentiation_operator
Exponentiation operator
Most programming languages have a built-in implementation of exponentiation. Task Re-implement integer exponentiation for both   intint   and   floatint   as both a procedure,   and an operator (if your language supports operator definition). If the language supports operator (or procedure) overloading, then an ov...
#REXX
REXX
/*REXX program computes and displays various (integer) exponentiations. */ say center('digits='digits(), 79, "─") say 'iPow(17, 65) is:' say iPow(17, 65) say   say 'iPow(0, -3) is:' say iPow(0, -3) say   say 'iPow(8, 0) is:' say iPow(8, 0) say   num...
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Stata
Stata
program define fizzbuzz args n forvalues i = 1/`n' { if mod(`i',15) == 0 { display "FizzBuzz" } else if mod(`i',5) == 0 { display "Buzz" } else if mod(`i',3) == 0 { display "Fizz" } else { display `i' } } end
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#Erlang
Erlang
USE: brainf***   "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++." run-brainf***
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#Fantom
Fantom
  class Main { static const Str target := "METHINKS IT IS LIKE A WEASEL" static const Int C := 100 // size of population static const Float p := 0.1f // chance any char is mutated   // compute distance of str from target static Int fitness (Str str) { Int sum := 0 str.each |Int c, Int index| ...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#MAD
MAD
NORMAL MODE IS INTEGER   INTERNAL FUNCTION(N) ENTRY TO FIB. A = 0 B = 1 THROUGH LOOP, FOR N=N, -1, N.E.0 C = A + B A = B LOOP B = C FUNCTION RETURN A END OF FUNCTION   THROUGH SHOW,...
http://rosettacode.org/wiki/Execute_HQ9%2B
Execute HQ9+
Task Implement a   HQ9+   interpreter or compiler.
#x86_Assembly
x86 Assembly
    ;ds:si: pointer to asciiz string containing HQ9++ source code ExecuteHQ9: push ax push dx push si push di push es push bx mov bx, si .interpret: lodsb cmp al, 'H' je .doHelloWorld cmp al, 'Q' je .doPrintCode cmp al, '9' je .doDrinkBeer cmp al, '+' je .doCounter pop bx pop es pop di ...
http://rosettacode.org/wiki/Execute_HQ9%2B
Execute HQ9+
Task Implement a   HQ9+   interpreter or compiler.
#XSLT
XSLT
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <!-- bottles.xsl defines $entire-bottles-song --> <xsl:import href="bottles.xsl"/>   <xsl:output method="text" encoding="utf-8"/>   <xsl:variable name="hello-world"> <xsl:text>Hello, world!&#10;</xsl:text> </xsl...
http://rosettacode.org/wiki/Execute_a_Markov_algorithm
Execute a Markov algorithm
Execute a Markov algorithm You are encouraged to solve this task according to the task description, using any language you may know. Task Create an interpreter for a Markov Algorithm. Rules have the syntax: <ruleset> ::= ((<comment> | <rule>) <newline>+)* <comment> ::= # {<any character>} <rule> ::= <pattern> <wh...
#VBScript
VBScript
  class markovparser   dim aRules public property let ruleset( sBlock ) dim i aRules = split( sBlock, vbNewLine ) '~ remove blank lines from end of array do while aRules( ubound( aRules ) ) = vbnullstring redim preserve aRules( ubound( aRules ) - 1 ) loop ...
http://rosettacode.org/wiki/Exceptions
Exceptions
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops This task is to give an example of an exception handling routine and to "throw" a new exception. Related task   Exceptions Through Nested Calls
#Pop11
Pop11
define throw_exception(); throw([my_exception my_data]); enddefine;
http://rosettacode.org/wiki/Exceptions
Exceptions
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops This task is to give an example of an exception handling routine and to "throw" a new exception. Related task   Exceptions Through Nested Calls
#PowerShell
PowerShell
  throw "Any error message."  
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#MAXScript
MAXScript
dosCommand "pause"
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Mercury
Mercury
  :- module execute_sys_cmd. :- interface. :- import_module io.   :- pred main(io::di, io::uo) is det.   :- implementation.   main(!IO) :- io.call_system("ls", _Result, !IO).  
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#min
min
!dir
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Befunge
Befunge
&1\>  :v v *< ^-1:_$>\:| @.$<
http://rosettacode.org/wiki/Exponentiation_operator
Exponentiation operator
Most programming languages have a built-in implementation of exponentiation. Task Re-implement integer exponentiation for both   intint   and   floatint   as both a procedure,   and an operator (if your language supports operator definition). If the language supports operator (or procedure) overloading, then an ov...
#Ring
Ring
  see "11^5 = " + ipow(11, 5) + nl see "pi^3 = " + fpow(3.14, 3) + nl   func ipow a, b p2 = 1 for i = 1 to 32 p2 *= p2 if b < 0 p2 *= a ok b = b << 1 next return p2   func fpow a, b p = 1 for i = 1 to 32 p *= p if b < 0 p *= a ok b = ...
http://rosettacode.org/wiki/Exponentiation_operator
Exponentiation operator
Most programming languages have a built-in implementation of exponentiation. Task Re-implement integer exponentiation for both   intint   and   floatint   as both a procedure,   and an operator (if your language supports operator definition). If the language supports operator (or procedure) overloading, then an ov...
#Ruby
Ruby
class Numeric def pow(m) raise TypeError, "exponent must be an integer: #{m}" unless m.is_a? Integer puts "pow!!" Array.new(m, self).reduce(1, :*) end end   p 5.pow(3) p 5.5.pow(3) p 5.pow(3.1)
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Swahili
Swahili
  shughuli fizzBuzz() { kwa i = 1 mpaka 100 { kama (i % 15 == 0) { andika("FizzBuzz") } au (i % 5 == 0) { andika("Buzz") } au (i % 3 == 0) { andika("Fizz") } sivyo { andika(i) } } }  
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#F.23
F#
USE: brainf***   "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++." run-brainf***
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#Forth
Forth
include lib/choose.4th \ target string s" METHINKS IT IS LIKE A WEASEL" sconstant target   27 constant /charset \ size of characterset 29 constant /target \ size of target string 32 constant #copies \ number of offspring   /t...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#Maple
Maple
  > f := n -> ifelse(n<3,1,f(n-1)+f(n-2)); > f(2); 1 > f(3); 2  
http://rosettacode.org/wiki/Execute_HQ9%2B
Execute HQ9+
Task Implement a   HQ9+   interpreter or compiler.
#zkl
zkl
fcn runHQ9(code){ acc:=0; foreach c in (code){ switch(c){ case("H"){ println("hello, world"); } case("Q"){ print(code); } case("+"){ acc+=1; } case("9"){ wall_O_beer(); } } } } fcn wall_O_beer(){ [99..0,-1].pump(fcn(n){ println(beers(n), " on the wall, ", beers(n).toLower(), ".\n",...
http://rosettacode.org/wiki/Execute_a_Markov_algorithm
Execute a Markov algorithm
Execute a Markov algorithm You are encouraged to solve this task according to the task description, using any language you may know. Task Create an interpreter for a Markov Algorithm. Rules have the syntax: <ruleset> ::= ((<comment> | <rule>) <newline>+)* <comment> ::= # {<any character>} <rule> ::= <pattern> <wh...
#Wren
Wren
import "/ioutil" for FileUtil, File import "/pattern" for Pattern   var lb = FileUtil.lineBreak   /* rulesets assumed to be separated by a blank line in file */ var readRules = Fn.new { |path| return File.read(path).trimEnd().split("%(lb)%(lb)").map { |rs| rs.split(lb) }.toList }   /* tests assumed to be on consecu...
http://rosettacode.org/wiki/Exceptions
Exceptions
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops This task is to give an example of an exception handling routine and to "throw" a new exception. Related task   Exceptions Through Nested Calls
#Prolog
Prolog
foo(X) :- \+ integer(X), throw(b('not even an int')). foo(X) :- \+ between(1,10,X), throw(a('must be between 1 & 10')). foo(X) :- format('~p is a valid number~n', X).   go(X) :- catch( foo(X), E, handle(E)).   handle(a(Msg)) :- format('~w~n', Msg), !. handle(X) :-...
http://rosettacode.org/wiki/Exceptions
Exceptions
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops This task is to give an example of an exception handling routine and to "throw" a new exception. Related task   Exceptions Through Nested Calls
#PureBasic
PureBasic
Procedure ErrorHandler() MessageRequester("Exception test", "The following error happened: " + ErrorMessage()) EndProcedure   MessageRequester("Exception test", "Test start")   OnErrorCall(@ErrorHandler())   RaiseError(#PB_OnError_InvalidMemory) ;a custom error# can also be used here depending on the OS being compile...
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Modula-2
Modula-2
MODULE tri;   FROM SYSTEM IMPORT ADR; FROM SysLib IMPORT system;   IMPORT TextIO, InOut, ASCII;   VAR fd : TextIO.File; ch : CHAR;   PROCEDURE SystemCommand (VAR command : ARRAY OF CHAR) : BOOLEAN;   BEGIN IF system (ADR (command) ) = 0 THEN RE...
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Modula-3
Modula-3
UNSAFE MODULE Exec EXPORTS Main;   IMPORT Unix, M3toC;   VAR command := M3toC.CopyTtoS("ls");   BEGIN EVAL Unix.system(command); M3toC.FreeCopiedS(command); END Exec.
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#BQN
BQN
Fac ← ×´1+↕ ! 720 ≡ Fac 6
http://rosettacode.org/wiki/Exponentiation_operator
Exponentiation operator
Most programming languages have a built-in implementation of exponentiation. Task Re-implement integer exponentiation for both   intint   and   floatint   as both a procedure,   and an operator (if your language supports operator definition). If the language supports operator (or procedure) overloading, then an ov...
#Run_BASIC
Run BASIC
print " 11^5 = ";11^5 print " (-11)^5 = ";-11^5 print " 11^( -5) = ";11^-5 print " 3.1416^3 = ";3.1416^3 print " 0^2 = ";0^2 print " 2^0 = ";2^0 print " -2^0 = ";-2^0
http://rosettacode.org/wiki/Exponentiation_operator
Exponentiation operator
Most programming languages have a built-in implementation of exponentiation. Task Re-implement integer exponentiation for both   intint   and   floatint   as both a procedure,   and an operator (if your language supports operator definition). If the language supports operator (or procedure) overloading, then an ov...
#Rust
Rust
extern crate num; use num::traits::One; use std::ops::Mul;   fn pow<T>(mut base: T, mut exp: usize) -> T where T: Clone + One + Mul<T, Output=T> { if exp == 0 { return T::one() } while exp & 1 == 0 { base = base.clone() * base; exp >>= 1; } if exp == 1 { return base } let mut ac...
http://rosettacode.org/wiki/FizzBuzz
FizzBuzz
Task Write a program that prints the integers from   1   to   100   (inclusive). But:   for multiples of three,   print   Fizz     (instead of the number)   for multiples of five,   print   Buzz     (instead of the number)   for multiples of both three and five,   print   FizzBuzz     (instead of the number) ...
#Swift
Swift
for i in 1...100 { switch (i % 3, i % 5) { case (0, 0): print("FizzBuzz") case (0, _): print("Fizz") case (_, 0): print("Buzz") default: print(i) } }
http://rosettacode.org/wiki/Execute_Brain****
Execute Brain****
Execute Brain**** is an implementation of Brainf***. Other implementations of Brainf***. RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions:...
#Factor
Factor
USE: brainf***   "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++." run-brainf***
http://rosettacode.org/wiki/Evolutionary_algorithm
Evolutionary algorithm
Starting with: The target string: "METHINKS IT IS LIKE A WEASEL". An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the parent). A fitness function that computes the ‘closeness’ of its argument to the target string....
#Fortran
Fortran
  !*************************************************************************************************** module evolve_routines !*************************************************************************************************** implicit none   !the target string: character(len=*),parameter :: targ = 'METHINKS ...
http://rosettacode.org/wiki/Fibonacci_sequence
Fibonacci sequence
The Fibonacci sequence is a sequence   Fn   of natural numbers defined recursively: F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2, if n>1 Task Write a function to generate the   nth   Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow ...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
fib[0] = 0 fib[1] = 1 fib[n_Integer] := fib[n - 1] + fib[n - 2]
http://rosettacode.org/wiki/Execute_a_Markov_algorithm
Execute a Markov algorithm
Execute a Markov algorithm You are encouraged to solve this task according to the task description, using any language you may know. Task Create an interpreter for a Markov Algorithm. Rules have the syntax: <ruleset> ::= ((<comment> | <rule>) <newline>+)* <comment> ::= # {<any character>} <rule> ::= <pattern> <wh...
#zkl
zkl
fcn parseRuleSet(lines){ if(vm.numArgs>1) lines=vm.arglist; // lines or object ks:=L(); vs:=L(); foreach line in (lines){ if(line[0]=="#") continue; // nuke <comment> pattern,replacement:=line.replace("\t"," ") .split(" -> ",1).apply("strip"); ks.append(pattern); vs.append(replac...
http://rosettacode.org/wiki/Exceptions
Exceptions
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops This task is to give an example of an exception handling routine and to "throw" a new exception. Related task   Exceptions Through Nested Calls
#Python
Python
import exceptions class SillyError(exceptions.Exception): def __init__(self,args=None): self.args=args
http://rosettacode.org/wiki/Exceptions
Exceptions
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops This task is to give an example of an exception handling routine and to "throw" a new exception. Related task   Exceptions Through Nested Calls
#Quackery
Quackery
<flag on stack indicating if condition detected> if [ $ "It all went pear shaped in 'a'." message put bail ]
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#MUMPS
MUMPS
Set X=$ZF(-1,"DIR")
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#Nanoquery
Nanoquery
shell("ls")
http://rosettacode.org/wiki/Execute_a_system_command
Execute a system command
Task Run either the   ls   system command   (dir   on Windows),   or the   pause   system command. Related task Get system command output
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols binary   import java.util.Scanner   runSample(arg) return   -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method runSample(arg) private static parse arg command if command = '' then command = 'ls -oa' -- for Windo...
http://rosettacode.org/wiki/Factorial
Factorial
Definitions   The factorial of   0   (zero)   is defined as being   1   (unity).   The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence: n,   n-1,   n-2,   ...   1 Task Write a function to return the factorial of a number. Solutions can be iterat...
#Bracmat
Bracmat
( = .  !arg:0&1 |  !arg * ( ( = r .  !arg:?r & ' ( .  !arg:0&1 | !arg*(($r)$($r))$(!arg+-1) ) ...
http://rosettacode.org/wiki/Exponentiation_operator
Exponentiation operator
Most programming languages have a built-in implementation of exponentiation. Task Re-implement integer exponentiation for both   intint   and   floatint   as both a procedure,   and an operator (if your language supports operator definition). If the language supports operator (or procedure) overloading, then an ov...
#Scala
Scala
object Exponentiation { import scala.annotation.tailrec   @tailrec def powI[N](n: N, exponent: Int)(implicit num: Integral[N]): N = { import num._ exponent match { case 0 => one case _ if exponent % 2 == 0 => powI((n * n), (exponent / 2)) case _ => powI(n, (exponent - 1)) * n } }   ...