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/Compound_data_type
Compound data type
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Task Create a compound data type: Point(x,y) A compound data type is one that holds multiple independent values. Related task   Enumeration S...
#JSON
JSON
{"x":1,"y":2}
http://rosettacode.org/wiki/Compound_data_type
Compound data type
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Task Create a compound data type: Point(x,y) A compound data type is one that holds multiple independent values. Related task   Enumeration S...
#Julia
Julia
struct Point{T<:Real} x::T y::T end
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#RLaB
RLaB
>> s1 = "A string" A string >> s2 = s1 A string
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Robotic
Robotic
  set "$string1" to "This is a string" set "$string2" to "$string1" * "&$string2&"  
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#PicoLisp
PicoLisp
(let Area (make (do 31 (link (need 31 " ")))) (use (X Y) (do 100 (until (>= 15 (sqrt (+ (* (setq X (rand -15 15)) X) (* (setq Y (rand -15 15)) Y) ) ) 10 ) ) (set (nth Area (+ 1...
http://rosettacode.org/wiki/Convex_hull
Convex hull
Find the points which form a convex hull from a set of arbitrary two dimensional points. For example, given the points (16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2) and (12,10) the convex hull would be (-...
#Tcl
Tcl
catch {namespace delete test_convex_hull} ;# Start with a clean namespace   namespace eval test_convex_hull { package require Tcl 8.5 ;# maybe earlier? interp alias {} @ {} lindex;# An essential readability helper for list indexing   proc cross {o a b} { ### 2D cross product of OA and OB vectors ###...
http://rosettacode.org/wiki/Convert_seconds_to_compound_duration
Convert seconds to compound duration
Task Write a function or program which:   takes a positive integer representing a duration in seconds as input (e.g., 100), and   returns a string which shows the same duration decomposed into:   weeks,   days,   hours,   minutes,   and   seconds. This is detailed below (e.g., "2 hr, 59 sec"). Demonstrat...
#XPL0
XPL0
char Str(80); func Duration(Sec); \Convert seconds to compound duration int Sec, Amt, Unit, DoComma, I, Quot; [Amt:= [7*24*60*60, 24*60*60, 60*60, 60, 1]; Unit:= [" wk", " d", " hr", " min", " sec"]; DoComma:= false; for I:= 0 to 4 do [Quot:= Sec/Amt(I); Sec:= rem(0); if Quot # 0 then [if DoComma t...
http://rosettacode.org/wiki/Convert_seconds_to_compound_duration
Convert seconds to compound duration
Task Write a function or program which:   takes a positive integer representing a duration in seconds as input (e.g., 100), and   returns a string which shows the same duration decomposed into:   weeks,   days,   hours,   minutes,   and   seconds. This is detailed below (e.g., "2 hr, 59 sec"). Demonstrat...
#zkl
zkl
fcn toWDHMS(sec){ //-->(wk,d,h,m,s) r,b:=List(),0; foreach u in (T(60,60,24,7)){ sec,b=sec.divr(u); // aka divmod r.append(b); } r.append(sec).reverse() }
http://rosettacode.org/wiki/Concurrent_computing
Concurrent computing
Task Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order. Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.
#Perl
Perl
use threads; use Time::HiRes qw(sleep);   $_->join for map { threads->create(sub { sleep rand; print shift, "\n"; }, $_) } qw(Enjoy Rosetta Code);
http://rosettacode.org/wiki/Concurrent_computing
Concurrent computing
Task Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order. Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.
#Phix
Phix
without js -- (threads) procedure echo(string s) sleep(rand(100)/100) enter_cs() puts(1,s) puts(1,'\n') leave_cs() end procedure constant threads = {create_thread(routine_id("echo"),{"Enjoy"}), create_thread(routine_id("echo"),{"Rosetta"}), create_thread(rou...
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Oz
Oz
functor import System Application prepare fun {Fac N} {FoldL {List.number 1 N 1} Number.'*' 1} end Fac10 = {Fac 10} define {System.showInfo "10! = "#Fac10} {Application.exit 0} end
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Pascal
Pascal
  program in out;   const   X = 10*9*8*7*6*5*4*3*2*1 ;   begin   writeln(x);   end;  
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Perl
Perl
my $tenfactorial; print "$tenfactorial\n";   BEGIN {$tenfactorial = 1; $tenfactorial *= $_ foreach 1 .. 10;}
http://rosettacode.org/wiki/Conditional_structures
Conditional structures
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Task List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions. Common conditional structures include ...
#68000_Assembly
68000 Assembly
MOVE.L #$FFFFFF00,D0 CMP.B #0,D0 ;equals zero, so zero flag is set. CMP.W #0,D0 ;doesn't equals zero, so zero flag is clear.
http://rosettacode.org/wiki/Conway%27s_Game_of_Life
Conway's Game of Life
The Game of Life is a   cellular automaton   devised by the British mathematician   John Horton Conway   in 1970.   It is the best-known example of a cellular automaton. Conway's game of life is described   here: A cell   C   is represented by a   1   when alive,   or   0   when dead,   in an   m-by-m   (or m×m)   sq...
#Ada
Ada
  WITH Ada.Text_IO; USE Ada.Text_IO;   PROCEDURE Life IS SUBTYPE Cell IS Natural RANGE 0 .. 1;   TYPE Petri_Dish IS ARRAY (Positive RANGE <>, Positive RANGE <>) OF Cell;   PROCEDURE Step (Gen : IN OUT Petri_Dish) IS Above  : ARRAY (Gen'Range (2)) OF Cell := (OTHERS => 0); Left, This  : Cell; ...
http://rosettacode.org/wiki/Compound_data_type
Compound data type
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Task Create a compound data type: Point(x,y) A compound data type is one that holds multiple independent values. Related task   Enumeration S...
#KonsolScript
KonsolScript
Var:Create( Point, Number x, Number y )
http://rosettacode.org/wiki/Compound_data_type
Compound data type
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Task Create a compound data type: Point(x,y) A compound data type is one that holds multiple independent values. Related task   Enumeration S...
#Kotlin
Kotlin
data class Point(var x: Int, var y: Int)   fun main(args: Array<String>) { val p = Point(1, 2) println(p) p.x = 3 p.y = 4 println(p) }
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Ruby
Ruby
original = "hello" reference = original # copies reference copy1 = original.dup # instance of original.class copy2 = String.new(original) # instance of String   original << " world!" # append p reference #=> "hello world!" p copy1 #=> "hello" p copy2 ...
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Run_BASIC
Run BASIC
origString$ = "Hello!" ' create original string newString$ = origString$ ' make new strig from original
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#PL.2FI
PL/I
  constrain: procedure options (main); declare 1 point (100), 2 x fixed binary, 2 y fixed binary; declare (i, j, a, b, c) fixed binary;   j = 0; do i = 1 to 100; a = 30*random()-15; b = 30*random()-15; c = sqrt(a**2 + b**2); if abs(c) >= 10 & abs(c) <= 15 then ...
http://rosettacode.org/wiki/Convex_hull
Convex hull
Find the points which form a convex hull from a set of arbitrary two dimensional points. For example, given the points (16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2) and (12,10) the convex hull would be (-...
#Visual_Basic_.NET
Visual Basic .NET
Imports ConvexHull   Module Module1   Class Point : Implements IComparable(Of Point) Public Property X As Integer Public Property Y As Integer   Public Sub New(x As Integer, y As Integer) Me.X = x Me.Y = y End Sub   Public Function CompareTo(other As P...
http://rosettacode.org/wiki/Convert_seconds_to_compound_duration
Convert seconds to compound duration
Task Write a function or program which:   takes a positive integer representing a duration in seconds as input (e.g., 100), and   returns a string which shows the same duration decomposed into:   weeks,   days,   hours,   minutes,   and   seconds. This is detailed below (e.g., "2 hr, 59 sec"). Demonstrat...
#ZX_Spectrum_Basic
ZX Spectrum Basic
10 LET m=60: LET h=60*m: LET d=h*24: LET w=d*7 20 DATA 10,7259,86400,6000000,0,1,60,3600,604799,604800,694861 30 READ n 40 FOR i=1 TO n 50 READ s 60 LET nweek=0: LET nday=0: LET nhour=0: LET nmin=0: LET nsec=0: LET s$="" 70 PRINT s;" = "; 80 IF s>=w THEN LET nweek=INT (s/w): LET s=FN m(s,w) 90 IF s>=d THEN LET nday=INT...
http://rosettacode.org/wiki/Concurrent_computing
Concurrent computing
Task Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order. Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.
#PicoLisp
PicoLisp
(for (N . Str) '("Enjoy" "Rosetta" "Code") (task (- N) (rand 1000 4000) # Random start time 1 .. 4 sec Str Str # Closure with string value (println Str) # Task body: Print the string (task @) ) ) # and st...
http://rosettacode.org/wiki/Concurrent_computing
Concurrent computing
Task Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order. Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.
#Pike
Pike
int main() { // Start threads and wait for them to finish ({ Thread.Thread(write, "Enjoy\n"), Thread.Thread(write, "Rosetta\n"), Thread.Thread(write, "Code\n") })->wait();   // Exit program exit(0); }
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Phix
Phix
integer a,b a = 10*9*8*7*6*5*4*3*2*1 b = factorial(10) ?{a,b}
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#PicoLisp
PicoLisp
(de fact (N) (apply * (range 1 N)) )   (de foo () (prinl "The value of fact(10) is " `(fact 10)) )
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#PL.2FI
PL/I
  /* Factorials using the pre-processor. */ test: procedure options (main);       %factorial: procedure (N) returns (fixed); declare N fixed; declare (i, k) fixed;   k = 1; do i = 2 to N; k = k*i; end; return (k);   %end factorial;   %activate factorial;   declare (x, y) fixed decimal; x =...
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#PowerShell
PowerShell
  function fact([BigInt]$n){ if($n -ge ([BigInt]::Zero)) { $fact = [BigInt]::One ([BigInt]::One)..$n | foreach{ $fact = [BigInt]::Multiply($fact, $_) } $fact   } else { Write-Error "$n is lower than 0" } } "$((Measure-Command {$fact = fact 10}).TotalSecond...
http://rosettacode.org/wiki/Conditional_structures
Conditional structures
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Task List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions. Common conditional structures include ...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program condstr64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly*/ .include "../includeConstantesARM6...
http://rosettacode.org/wiki/Conway%27s_Game_of_Life
Conway's Game of Life
The Game of Life is a   cellular automaton   devised by the British mathematician   John Horton Conway   in 1970.   It is the best-known example of a cellular automaton. Conway's game of life is described   here: A cell   C   is represented by a   1   when alive,   or   0   when dead,   in an   m-by-m   (or m×m)   sq...
#ALGOL_68
ALGOL 68
  ∇LIFE[⎕]∇ [0] NG←LIFE CG;W [1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG) [2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG) [3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 LIFE RP 0 0 0 0 0 0 1 1 1 0 0 1 0 0 0 0 1 ...
http://rosettacode.org/wiki/Compound_data_type
Compound data type
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Task Create a compound data type: Point(x,y) A compound data type is one that holds multiple independent values. Related task   Enumeration S...
#Lambdatalk
Lambdatalk
  1) a pair {def P {P.new 1 2}} -> P {P.left {P}} -> 1 {P.right {P}} -> 2   2) its Lispsish variant {def Q {cons 1 2}} -> Q {car {Q}} -> 1 {cdr {Q}} -> 2   3) as an array {def R {A.new 1 2}} -> R {A.first {R}} -> 1 {A.last {R}} -> 2  
http://rosettacode.org/wiki/Compound_data_type
Compound data type
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Task Create a compound data type: Point(x,y) A compound data type is one that holds multiple independent values. Related task   Enumeration S...
#Lasso
Lasso
define Point => type { parent pair   public onCreate(x,y) => { ..onCreate(#x=#y) }   public x => .first public y => .second }   local(point) = Point(33, 42) #point->x #point->y
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Rust
Rust
fn main() { let s1 = "A String"; let mut s2 = s1;   s2 = "Another String";   println!("s1 = {}, s2 = {}", s1, s2); }
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Sather
Sather
class MAIN is main is s  ::= "a string"; s1 ::= s; -- s1 is a copy end; end;
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#PowerShell
PowerShell
$MinR2 = 10 * 10 $MaxR2 = 15 * 15   $Points = @{}   While ( $Points.Count -lt 100 ) { $X = Get-Random -Minimum -16 -Maximum 17 $Y = Get-Random -Minimum -16 -Maximum 17 $R2 = $X * $X + $Y * $Y   If ( $R2 -ge $MinR2 -and $R2 -le $MaxR2 -and "$X,$Y" -notin $Points.Keys ) { $Points += @{...
http://rosettacode.org/wiki/Convex_hull
Convex hull
Find the points which form a convex hull from a set of arbitrary two dimensional points. For example, given the points (16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2) and (12,10) the convex hull would be (-...
#Wren
Wren
import "/sort" for Sort import "/trait" for Comparable, Stepped   class Point is Comparable { construct new(x, y) { _x = x _y = y }   x { _x } y { _y }   compare(other) { (_x != other.x) ? (_x - other.x).sign : (_y - other.y).sign }   toString { "(%(_x), %(_y))" } }   /* ccw retu...
http://rosettacode.org/wiki/Concurrent_computing
Concurrent computing
Task Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order. Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.
#PowerShell
PowerShell
$Strings = "Enjoy","Rosetta","Code"   $SB = {param($String)Write-Output $String}   foreach($String in $Strings) { Start-Job -ScriptBlock $SB -ArgumentList $String | Out-Null }   Get-Job | Wait-Job | Receive-Job Get-Job | Remove-Job
http://rosettacode.org/wiki/Concurrent_computing
Concurrent computing
Task Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order. Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.
#Prolog
Prolog
main :- thread_create(say("Enjoy"),A,[]), thread_create(say("Rosetta"),B,[]), thread_create(say("Code"),C,[]), thread_join(A,_), thread_join(B,_), thread_join(C,_).   say(Message) :- Delay is random_float, sleep(Delay), writeln(Message).
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Prolog
Prolog
% Taken from RosettaCode Factorial page for Prolog fact(X, 1) :- X<2. fact(X, F) :- Y is X-1, fact(Y,Z), F is Z*X.   goal_expansion((X = factorial_of(N)), (X = F)) :- fact(N,F).   test :- F = factorial_of(10), format('!10 = ~p~n', F).
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#PureBasic
PureBasic
a=1*2*3*4*5*6*7*8*9*10
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Quackery
Quackery
[ 1 10 times [ i 1+ * ] echo ] now!
http://rosettacode.org/wiki/Conditional_structures
Conditional structures
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Task List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions. Common conditional structures include ...
#Action.21
Action!
PROC Main() INT i   FOR i=-1 TO 1 DO IF i<0 THEN PrintF("%I is less than zero%E",i) ELSEIF i>0 THEN PrintF("%I is greater than zero%E",i) ELSE PrintF("%I is zero%E",i) FI OD RETURN
http://rosettacode.org/wiki/Conway%27s_Game_of_Life
Conway's Game of Life
The Game of Life is a   cellular automaton   devised by the British mathematician   John Horton Conway   in 1970.   It is the best-known example of a cellular automaton. Conway's game of life is described   here: A cell   C   is represented by a   1   when alive,   or   0   when dead,   in an   m-by-m   (or m×m)   sq...
#APL
APL
  ∇LIFE[⎕]∇ [0] NG←LIFE CG;W [1] W←CG+(¯1⊖CG)+(1⊖CG)+(¯1⌽CG)+(1⌽CG) [2] W←W+(1⊖1⌽CG)+(¯1⊖1⌽CG)+(1⊖¯1⌽CG)+(¯1⊖¯1⌽CG) [3] NG←(3=W)+(CG∧4=W) ∇ RP←5 5⍴0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 RP 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 LIFE RP 0 0 0 0 0 0 1 1 1 0 0 1 0 0 0 0 1 ...
http://rosettacode.org/wiki/Compound_data_type
Compound data type
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Task Create a compound data type: Point(x,y) A compound data type is one that holds multiple independent values. Related task   Enumeration S...
#LFE
LFE
  (defrecord point x y)  
http://rosettacode.org/wiki/Compound_data_type
Compound data type
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Task Create a compound data type: Point(x,y) A compound data type is one that holds multiple independent values. Related task   Enumeration S...
#Lingo
Lingo
-- parent script "MyPoint" property x property y on new (me, px, py) me.x = px me.y = py return me end
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Scala
Scala
val src = "Hello" // Its actually not a copy but a reference // That is not a problem because String is immutable // In fact its a feature val des = src assert(src eq des) // Proves the same reference is used. // To make a real copy makes no sense. // Actually its hard to make a copy, the compiler is t...
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Scheme
Scheme
(define dst (string-copy src))
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#Prolog
Prolog
:- use_module(library(clpfd)).   circle :- bagof([X,Y], init(X,Y), BL), length(BL, N), length(L, 100), maplist(choose(BL, N), L), draw_circle(L).     % point selection choose(BL, N, V) :- I is random(N), nth0(I, BL, V).   % to find all couples of numbers verifying % 100 <= x^2 + y^2 <= 225 init(X1, Y1) :- X in...
http://rosettacode.org/wiki/Convex_hull
Convex hull
Find the points which form a convex hull from a set of arbitrary two dimensional points. For example, given the points (16,3), (12,17), (0,6), (-4,-6), (16,6), (16,-7), (16,-3), (17,-4), (5,19), (19,-8), (3,16), (12,13), (3,-4), (17,5), (-3,15), (-3,-9), (0,11), (-9,-3), (-4,-2) and (12,10) the convex hull would be (-...
#zkl
zkl
// Use Graham Scan to sort points into a convex hull // https://en.wikipedia.org/wiki/Graham_scan, O(n log n) // http://www.geeksforgeeks.org/convex-hull-set-2-graham-scan/ // http://geomalgorithms.com/a10-_hull-1.html fcn grahamScan(points){ N:=points.len(); # find the point with the lowest y-coordinate, x is ti...
http://rosettacode.org/wiki/Concurrent_computing
Concurrent computing
Task Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order. Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.
#PureBasic
PureBasic
Global mutex = CreateMutex()   Procedure Printer(*str) LockMutex(mutex) PrintN( PeekS(*str) ) UnlockMutex(mutex) EndProcedure   If OpenConsole() LockMutex(mutex) thread1 = CreateThread(@Printer(), @"Enjoy") thread2 = CreateThread(@Printer(), @"Rosetta") thread3 = CreateThread(@Printer(), @"Code") UnlockMutex(mu...
http://rosettacode.org/wiki/Concurrent_computing
Concurrent computing
Task Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order. Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.
#Python
Python
import asyncio     async def print_(string: str) -> None: print(string)     async def main(): strings = ['Enjoy', 'Rosetta', 'Code'] coroutines = map(print_, strings) await asyncio.gather(*coroutines)     if __name__ == '__main__': asyncio.run(main())
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Racket
Racket
  #lang racket   ;; Import the math library for compile-time ;; Note: included in Racket v5.3.2 (require (for-syntax math))   ;; In versions older than v5.3.2, just define the function ;; for compile-time ;; ;; (begin-for-syntax ;; (define (factorial n) ;; (if (zero? n) ;; 1 ;; (factorial (- n 1))...
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Raku
Raku
constant $tenfact = [*] 2..10; say $tenfact;
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#REXX
REXX
/*REXX program computes 10! (ten factorial) during REXX's equivalent of "compile─time". */   say '10! ='  !(10) exit /*stick a fork in it, we're all done. */ /*──────────────────────────────────────────────────────────────────────────────────────*/ !: procedure;  !=1; ...
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Ring
Ring
  a = 10*9*8*7*6*5*4*3*2*1 b = factorial(10) see a + nl see b + nl   func factorial nr if nr = 1 return 1 else return nr * factorial(nr-1) ok  
http://rosettacode.org/wiki/Conditional_structures
Conditional structures
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Task List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions. Common conditional structures include ...
#ActionScript
ActionScript
type Restricted is range 1..10; My_Var : Restricted;   if My_Var = 5 then -- do something elsif My_Var > 5 then -- do something else -- do something end if;
http://rosettacode.org/wiki/Conway%27s_Game_of_Life
Conway's Game of Life
The Game of Life is a   cellular automaton   devised by the British mathematician   John Horton Conway   in 1970.   It is the best-known example of a cellular automaton. Conway's game of life is described   here: A cell   C   is represented by a   1   when alive,   or   0   when dead,   in an   m-by-m   (or m×m)   sq...
#AppleScript
AppleScript
use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later use framework "Foundation" -- For the regex at the top of newUniverse() use scripting additions   -- The characters to represent the live and dead cells. property live : "■" -- character id 9632 (U+25A0). property dead : space -- Infinite universes are exp...
http://rosettacode.org/wiki/Compound_data_type
Compound data type
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Task Create a compound data type: Point(x,y) A compound data type is one that holds multiple independent values. Related task   Enumeration S...
#Logo
Logo
setpos [100 100] setpos [100 0] setpos [0 0] show pos  ; [0 0]
http://rosettacode.org/wiki/Compound_data_type
Compound data type
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Task Create a compound data type: Point(x,y) A compound data type is one that holds multiple independent values. Related task   Enumeration S...
#Lua
Lua
  a = {x = 1; y = 2} b = {x = 3; y = 4} c = { x = a.x + b.x; y = a.y + b.y } print(a.x, a.y) --> 1 2 print(c.x, c.y) --> 4 6  
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Seed7
Seed7
var string: dest is "";   dest := "Hello";
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#SenseTalk
SenseTalk
(* In SenseTalk, assignments normally always make copies of values. *)   put "glorious" into myWord put myWord into yourWord   (* Assignments can also be made by reference if desired. *)   put a reference to myWord into myRef set another to refer to myRef   put "ly" after myWord put "in" before another   put "myWord: ...
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#PureBasic
PureBasic
CreateImage(0,31,31) StartDrawing(ImageOutput(0)) For i=1 To 100 Repeat x=Random(30)-15 y=Random(30)-15 R.f=Sqr(x*x+y*y) Until 10<=R And R<=15 Plot(x+15,y+15,#Red) Next StopDrawing()   Title$="PureBasic Plot" Flags=#PB_Window_SystemMenu OpenWindow(0,#PB_Ignore,#PB_Ignore,ImageWidth(0),...
http://rosettacode.org/wiki/Concurrent_computing
Concurrent computing
Task Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order. Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.
#Racket
Racket
  #lang racket (for ([str '("Enjoy" "Rosetta" "Code")]) (thread (λ () (displayln str))))  
http://rosettacode.org/wiki/Concurrent_computing
Concurrent computing
Task Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order. Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.
#Raku
Raku
my @words = <Enjoy Rosetta Code>; @words.race(:batch(1)).map: { sleep rand; say $_ };
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Rust
Rust
fn factorial(n: i64) -> i64 { let mut total = 1; for i in 1..n+1 { total *= i; } return total; }   fn main() { println!("Factorial of 10 is {}.", factorial(10)); }
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Scala
Scala
object Main extends { val tenFactorial = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2   def tenFac = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2   println(s"10! = $tenFactorial", tenFac) }
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Seed7
Seed7
$ include "seed7_05.s7i";   const proc: main is func local const integer: factorial is !10; begin writeln(factorial); end func;
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Sidef
Sidef
define n = (10!); say n;
http://rosettacode.org/wiki/Conditional_structures
Conditional structures
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Task List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions. Common conditional structures include ...
#Ada
Ada
type Restricted is range 1..10; My_Var : Restricted;   if My_Var = 5 then -- do something elsif My_Var > 5 then -- do something else -- do something end if;
http://rosettacode.org/wiki/Compiler/AST_interpreter
Compiler/AST interpreter
An AST interpreter interprets an Abstract Syntax Tree (AST) produced by a Syntax Analyzer. Task[edit] Take the AST output from the Syntax analyzer task, and interpret it as appropriate. Refer to the Syntax analyzer task for details of the AST. Loading the AST from the syntax analyzer is as simple as (pseudo code) de...
#ALGOL_W
ALGOL W
begin % AST interpreter %  % parse tree nodes % record node( integer type  ; reference(node) left, right  ; integer iValue % nString/nIndentifier number or nInteger value % ); integer nIdentifier, nString, nInteger, nSequence, nIf, nPrtc, nPrts...
http://rosettacode.org/wiki/Conway%27s_Game_of_Life
Conway's Game of Life
The Game of Life is a   cellular automaton   devised by the British mathematician   John Horton Conway   in 1970.   It is the best-known example of a cellular automaton. Conway's game of life is described   here: A cell   C   is represented by a   1   when alive,   or   0   when dead,   in an   m-by-m   (or m×m)   sq...
#ARM_Assembly
ARM Assembly
.string "PRG"   lcd_ptr .req r4 active_fb .req r5 inactive_fb .req r6 offset_r .req r7 backup_fb .req r8   @ start push {r4-r10, r12, lr}   ldr lcd_ptr, =0xC0000000 @ address of the LCD controller adr offset_r, offsets ldrh r0, [offset_r, #6] @ 0xffff is already in memory because -1 is in the offsets table ...
http://rosettacode.org/wiki/Compound_data_type
Compound data type
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Task Create a compound data type: Point(x,y) A compound data type is one that holds multiple independent values. Related task   Enumeration S...
#Maple
Maple
Point:= Record(x = 2,y = 4):   Point:-x; Point:-y;
http://rosettacode.org/wiki/Compound_data_type
Compound data type
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Task Create a compound data type: Point(x,y) A compound data type is one that holds multiple independent values. Related task   Enumeration S...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
In[1]:= a = point[2, 3]   Out[1]= point[2, 3]   In[2]:= a[[2]]   Out[2]= 3   In[3]:= a[[2]] = 4; a   Out[3]= point[2, 4]
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Shiny
Shiny
src: 'hello' cpy: src
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Sidef
Sidef
var original = "hello"; # new String object var reference = original; # points at the original object var copy1 = String.new(original); # creates a new String object var copy2 = original+''; # ==//==
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#Python
Python
>>> from collections import defaultdict >>> from random import choice >>> world = defaultdict(int) >>> possiblepoints = [(x,y) for x in range(-15,16) for y in range(-15,16) if 10 <= abs(x+y*1j) <= 15] >>> for i in range(100): world[choice(possiblepoints)] += 1   >>> for x in range(-15,16): print(''.join(str(mi...
http://rosettacode.org/wiki/Concurrent_computing
Concurrent computing
Task Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order. Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.
#Raven
Raven
[ 'Enjoy' 'Rosetta' 'Code' ] as $words   thread talker $words pop "%s\n" repeat dup print 500 choose ms   talker as a talker as b talker as c
http://rosettacode.org/wiki/Concurrent_computing
Concurrent computing
Task Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order. Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.
#Rhope
Rhope
Main(0,0) |: Print["Enjoy"] Print["Rosetta"] Print["Code"] :|
http://rosettacode.org/wiki/Concurrent_computing
Concurrent computing
Task Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order. Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.
#Ruby
Ruby
%w{Enjoy Rosetta Code}.map do |x| Thread.new do sleep rand puts x end end.each do |t| t.join end
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Tcl
Tcl
proc makeFacExpr n { set exp 1 for {set i 2} {$i <= $n} {incr i} { append exp " * $i" } return "expr \{$exp\}" } eval [makeFacExpr 10]
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Ursala
Ursala
#import nat   x = factorial 10   #executable&   comcal = ! (%nP x)--<''>
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Visual_Basic_.NET
Visual Basic .NET
Module Program Const FACTORIAL_10 = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1   Sub Main() Console.WriteLine(FACTORIAL_10) End Sub End Module
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Wren
Wren
var factorial10 = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2   System.print(factorial10)
http://rosettacode.org/wiki/Conditional_structures
Conditional structures
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Task List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions. Common conditional structures include ...
#Aikido
Aikido
  var x = loggedin ? sessionid : -1    
http://rosettacode.org/wiki/Compiler/AST_interpreter
Compiler/AST interpreter
An AST interpreter interprets an Abstract Syntax Tree (AST) produced by a Syntax Analyzer. Task[edit] Take the AST output from the Syntax analyzer task, and interpret it as appropriate. Refer to the Syntax analyzer task for details of the AST. Loading the AST from the syntax analyzer is as simple as (pseudo code) de...
#C
C
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <stdarg.h> #include <ctype.h>   #define da_dim(name, type) type *name = NULL; \ int _qy_ ## name ## _p = 0; \ int _qy_ ## name ## _max = 0 #define da_rewind(name) _qy_ ## name ## _p...
http://rosettacode.org/wiki/Compiler/syntax_analyzer
Compiler/syntax analyzer
A Syntax analyzer transforms a token stream (from the Lexical analyzer) into a Syntax tree, based on a grammar. Task[edit] Take the output from the Lexical analyzer task, and convert it to an Abstract Syntax Tree (AST), based on the grammar below. The output should be in a flattened format. The program should read in...
#ALGOL_W
ALGOL W
begin % syntax analyser %  % parse tree nodes % record node( integer type  ; reference(node) left, right  ; integer iValue % nString/nIndentifier number or nInteger value % ); integer nIdentifier, nString, nInteger, nSequence, nIf, nPrtc, nPrts...
http://rosettacode.org/wiki/Conway%27s_Game_of_Life
Conway's Game of Life
The Game of Life is a   cellular automaton   devised by the British mathematician   John Horton Conway   in 1970.   It is the best-known example of a cellular automaton. Conway's game of life is described   here: A cell   C   is represented by a   1   when alive,   or   0   when dead,   in an   m-by-m   (or m×m)   sq...
#AutoHotkey
AutoHotkey
rows := cols := 10 ; set grid dimensions i = -1,0,1, -1,1, -1,0,1 ; neighbors' x-offsets j = -1,-1,-1, 0,0, 1,1,1 ; neighbors' y-offsets StringSplit i, i, `, ; make arrays StringSplit j, j, `,   Loop % rows { ...
http://rosettacode.org/wiki/Compound_data_type
Compound data type
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Task Create a compound data type: Point(x,y) A compound data type is one that holds multiple independent values. Related task   Enumeration S...
#MATLAB_.2F_Octave
MATLAB / Octave
point.x=3; point.y=4;
http://rosettacode.org/wiki/Compound_data_type
Compound data type
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. Task Create a compound data type: Point(x,y) A compound data type is one that holds multiple independent values. Related task   Enumeration S...
#Maxima
Maxima
defstruct(point(x, y))$   p: new(point)$   q: point(1, 2)$   p@x: 5$
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Simula
Simula
BEGIN TEXT ORIGINAL, REFERENCE, COPY1;   ORIGINAL :- "THIS IS CONSTANT TEXT"; ORIGINAL.SETPOS(1); REFERENCE :- ORIGINAL;   ! RUN TIME ERROR: ! ORIGINAL.PUTCHAR('X'); ! "copy-a-string.sim", line 9: ./copy-a-string: Putchar: Constant text object ;   OUTTEXT(ORIGINAL); OUTIMAGE;    ! CONTENT...
http://rosettacode.org/wiki/Copy_a_string
Copy a string
This task is about copying a string. Task Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string. Other tasks related to string operations: Metrics Array length String length Copy a string Empty string  (assignment) Counting W...
#Slate
Slate
[ | :s | s == s copy] applyTo: {'hello'}. "returns False"
http://rosettacode.org/wiki/Constrained_random_points_on_a_circle
Constrained random points on a circle
Task Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that 10 ≤ x 2 + y 2 ≤ 15 {\displaystyle 10\leq {\sqrt {x^{2}+y^{2}}}\leq 15} . Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of point...
#R
R
  RMin <- 10 RMax <- 15 NPts <- 100   # instead of a for loop, we generate what should be enough points # also take care to have enough range to avoid rounding inaccuracies nBlock <- NPts * ((RMax/RMin) ^ 2) nValid <- 0 while (nValid < NPts) { X <- round(runif(nBlock, -RMax - 1, RMax + 1)) Y <- round(runif(nBlock, -R...
http://rosettacode.org/wiki/Concurrent_computing
Concurrent computing
Task Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order. Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.
#Rust
Rust
extern crate rand; use std::thread; use rand::thread_rng; use rand::distributions::{Range, IndependentSample};   fn main() { let mut rng = thread_rng(); let rng_range = Range::new(0u32, 100); for word in "Enjoy Rosetta Code".split_whitespace() { let snooze_time = rng_range.ind_sample(&mut rng); ...
http://rosettacode.org/wiki/Concurrent_computing
Concurrent computing
Task Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order. Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.
#Scala
Scala
import scala.actors.Futures List("Enjoy", "Rosetta", "Code").map { x => Futures.future { Thread.sleep((Math.random * 1000).toInt) println(x) } }.foreach(_())
http://rosettacode.org/wiki/Concurrent_computing
Concurrent computing
Task Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order. Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.
#Scheme
Scheme
(parallel-execute (lambda () (print "Enjoy")) (lambda () (print "Rosetta")) (lambda () (print "Code")))
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#XLISP
XLISP
(defmacro f10-at-compile-time () (* 2 3 4 5 6 7 8 9 10))
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#XPL0
XPL0
code IntOut=11; IntOut(0, 10*9*8*7*6*5*4*3*2);  
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#zkl
zkl
const { [1..10].reduce('*).println(" parse time") }   #fcn fact(N) { [1..N].reduce('*).println(" tokenize time"); ""} // paste output of fact into source #tokenize fact(10)   println("compiled program running.");
http://rosettacode.org/wiki/Compile-time_calculation
Compile-time calculation
Some programming languages allow calculation of values at compile time. Task Calculate   10!   (ten factorial)   at compile time. Print the result when the program is run. Discuss what limitations apply to compile-time calculations in your language.
#Zig
Zig
const std = @import("std"); fn factorial(n: u64) u64 { var total: u64 = 1; var i: u64 = 1; while (i < n + 1) : (i += 1) { total *= i; } return total; } pub fn main() void { @setEvalBranchQuota(1000); // minimum loop quota for backwards branches const res = comptime factorial(10); // ...
http://rosettacode.org/wiki/Conditional_structures
Conditional structures
Control Structures These are examples of control structures. You may also be interested in: Conditional structures Exceptions Flow-control structures Loops Task List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions. Common conditional structures include ...
#Aime
Aime
if (c1) { // first condition is true... } elif (c2) { // second condition is true... } elif (c3) { // third condition is true... } else { // none was true... }