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/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Clean
Clean
import ArgEnv   Start = getCommandLine
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Clojure
Clojure
(dorun (map println *command-line-args*))
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#CLU
CLU
% This program needs to be merged with PCLU's "useful.lib", % where get_argv lives. % % pclu -merge $CLUHOME/lib/useful.lib -compile cmdline.clu   start_up = proc () po: stream := stream$primary_output()   args: sequence[string] := get_argv()   for arg: string in sequence[string]$elements(args) do s...
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI comment one line */ /* comment line 1 comment line 2 */   mov r0,#0 @ this comment on end of line mov r1,#0 // authorized comment    
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#Arturo
Arturo
; This is a simple single-line comment   a: 10 ; another single-line comment   ; Now, this is a ; multi-line comment
http://rosettacode.org/wiki/Compiler/virtual_machine_interpreter
Compiler/virtual machine interpreter
A virtual machine implements a computer in software. Task[edit] Write a virtual machine interpreter. This interpreter should be able to run virtual assembly language programs created via the task. This is a byte-coded, 32-bit word stack based virtual machine. The program should read input from a file and/or stdin, an...
#Prolog
Prolog
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% %%% The Rosetta Code Virtual Machine, for GNU Prolog. %%% %%% The following code uses GNU Prolog's extensions for global %%% variables. %%% %%% Usage: vm [INPUTFILE [OUTPUTFILE]] %%% The notation "-" means to use standard input or standard outpu...
http://rosettacode.org/wiki/Compiler/code_generator
Compiler/code generator
A code generator translates the output of the syntax analyzer and/or semantic analyzer into lower level code, either assembly, object, or virtual. Task[edit] Take the output of the Syntax analyzer task - which is a flattened Abstract Syntax Tree (AST) - and convert it to virtual machine code, that can be run by the Vi...
#Python
Python
from __future__ import print_function import sys, struct, shlex, operator   nd_Ident, nd_String, nd_Integer, nd_Sequence, nd_If, nd_Prtc, nd_Prts, nd_Prti, nd_While, \ nd_Assign, nd_Negate, nd_Not, nd_Mul, nd_Div, nd_Mod, nd_Add, nd_Sub, nd_Lss, nd_Leq, \ nd_Gtr, nd_Geq, nd_Eql, nd_Neq, nd_And, nd_Or = range(25)   ...
http://rosettacode.org/wiki/Compare_length_of_two_strings
Compare length of two strings
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#PHP
PHP
  <?php     function retrieveStrings() { if (isset($_POST['input'])) { $strings = explode("\n", $_POST['input']); } else { $strings = ['abcd', '123456789', 'abcdef', '1234567']; } return $strings; }     function setInput() { echo join("\n", retrieveStrings()); }     function setOutpu...
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...
#Wren
Wren
import "/dynamic" for Enum, Struct, Tuple import "/fmt" for Fmt import "/ioutil" for FileUtil   var tokens = [ "EOI", "Mul", "Div", "Mod", "Add", "Sub", "Negate", "Not", "Lss", "Leq", "Gtr", "Geq", "Eql", "Neq", "Assign", "And", "Or", "If", "El...
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...
#Egel
Egel
import "prelude.eg" import "io.ego"   using System using List using IO   def boardsize = 5   def empty = [ X Y -> 0 ]   def insert = [ X Y BOARD -> [ X0 Y0 -> if and (X0 == X) (Y0 == Y) then 1 else BOARD X0 Y0 ] ]   def coords = let R = fromto 0 (boardsize - 1) in [ XX YY ->...
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...
#SIMPOL
SIMPOL
type mypoint embed integer x integer y end type
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...
#SNOBOL4
SNOBOL4
data('point(x,y)') p1 = point(10,20) p2 = point(10,40) output = "Point 1 (" x(p1) "," y(p1) ")" output = "Point 2 (" x(p2) "," y(p2) ")" end
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 ...
#Befunge
Befunge
v > "X",@ non-zero > & | > "0",@ zero
http://rosettacode.org/wiki/Commatizing_numbers
Commatizing numbers
Commatizing   numbers (as used here, is a handy expedient made-up word) is the act of adding commas to a number (or string), or to the numeric part of a larger string. Task Write a function that takes a string as an argument with optional arguments or parameters (the format of parameters/options is left to the prog...
#VBA
VBA
Public Sub commatize(s As String, Optional sep As String = ",", Optional start As Integer = 1, Optional step As Integer = 3) Dim l As Integer: l = Len(s) For i = start To l If Asc(Mid(s, i, 1)) >= Asc("1") And Asc(Mid(s, i, 1)) <= Asc("9") Then For j = i + 1 To l + 1 ...
http://rosettacode.org/wiki/Commatizing_numbers
Commatizing numbers
Commatizing   numbers (as used here, is a handy expedient made-up word) is the act of adding commas to a number (or string), or to the numeric part of a larger string. Task Write a function that takes a string as an argument with optional arguments or parameters (the format of parameters/options is left to the prog...
#Wren
Wren
var commatize = Fn.new { |s, start, step, sep| var addSeps = Fn.new { |n, dp| var lz = "" if (!dp && n.startsWith("0") && n != "0") { var k = n.trimStart("0") if (k == "") k = "0" lz = "0" * (n.count - k.count) n = k } if (dp) n = n[-1....
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#F.23
F#
let allEqual strings = Seq.isEmpty strings || Seq.forall (fun x -> x = Seq.head strings) (Seq.tail strings) let ascending strings = Seq.isEmpty strings || Seq.forall2 (fun x y -> x < y) strings (Seq.tail strings)
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#Factor
Factor
USE: grouping all-equal?
http://rosettacode.org/wiki/Comma_quibbling
Comma quibbling
Comma quibbling is a task originally set by Eric Lippert in his blog. Task Write a function to generate a string output which is the concatenation of input words from a list/sequence where: An input of no words produces the output string of just the two brace characters "{}". An input of just one word, e.g. ["AB...
#BCPL
BCPL
get "libhdr"   // Add a character to the end of a string let addch(s, ch) be $( s%0 := s%0 + 1 s%(s%0) := ch $) // Add s2 to the end of s1 and adds(s1, s2) be for i = 1 to s2%0 do addch(s1, s2%i)   // Comma quibbling on strs, which should be a 0-terminated // vector of string pointers. let quibble(strs...
http://rosettacode.org/wiki/Comma_quibbling
Comma quibbling
Comma quibbling is a task originally set by Eric Lippert in his blog. Task Write a function to generate a string output which is the concatenation of input words from a list/sequence where: An input of no words produces the output string of just the two brace characters "{}". An input of just one word, e.g. ["AB...
#Bracmat
Bracmat
( :?L1 & ABC:?L2 & ABC DEF:?L3 & ABC DEF G H:?L4 & L1 L2 L3 L4:?names & ( quibble = w .  !arg:%?w (% %:?arg) & !w ", " quibble$!arg | !arg:%?w %?arg&!w " and " quibble$!arg | !arg ) & (concat=.str$("{" quibble$!arg "}")) & whl ' (!names:%?name ?names&out$(!name concat$!!name)) );
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#C.2B.2B
C++
  #include <iostream> #include <string> #include <vector>   void print_vector(const std::vector<int> &pos, const std::vector<std::string> &str) { for (size_t i = 1; i < pos.size(); ++i) // offset: i:1..N printf("%s\t", str[pos[i]].c_str()); // str: 0..N-1 printf("\n"); }   // idea: custo...
http://rosettacode.org/wiki/Combinations_and_permutations
Combinations and permutations
This page uses content from Wikipedia. The original article was at Combination. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) This page uses content from Wikipedia. The original article was at P...
#Go
Go
  package main   import ( "fmt" "math/big" )   func main() { var n, p int64 fmt.Printf("A sample of permutations from 1 to 12:\n") for n = 1; n < 13; n++ { p = n / 3 fmt.Printf("P(%d,%d) = %d\n", n, p, perm(big.NewInt(n), big.NewInt(p))) } fmt.Printf("\nA sample of combinations from 10 to 60:\n") for n = 10...
http://rosettacode.org/wiki/Compiler/lexical_analyzer
Compiler/lexical analyzer
Definition from Wikipedia: Lexical analysis is the process of converting a sequence of characters (such as in a computer program or web page) into a sequence of tokens (strings with an identified "meaning"). A program that performs lexical analysis may be called a lexer, tokenizer, or scanner (though "scanner" is als...
#Emacs_Lisp
Emacs Lisp
#!/usr/bin/emacs --script ;; ;; The Rosetta Code lexical analyzer in GNU Emacs Lisp. ;; ;; Migrated from the ATS. However, Emacs Lisp is not friendly to the ;; functional style of the ATS implementation; therefore the ;; differences are vast. ;; ;; (A Scheme migration could easily, on the other hand, have been ;; almos...
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#COBOL
COBOL
IDENTIFICATION DIVISION. PROGRAM-ID. accept-all-args.   DATA DIVISION. WORKING-STORAGE SECTION. 01 args PIC X(50).   PROCEDURE DIVISION. main-line. ACCEPT args FROM COMMAND-LINE DISPLAY args   GOBACK .
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#CoffeeScript
CoffeeScript
  console.log arg for arg in process.argv  
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#Asymptote
Asymptote
// double slash to newline
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#AutoHotkey
AutoHotkey
Msgbox, comments demo ; end of line comment /* multiline comment1 multiline comment2 */
http://rosettacode.org/wiki/Compiler/virtual_machine_interpreter
Compiler/virtual machine interpreter
A virtual machine implements a computer in software. Task[edit] Write a virtual machine interpreter. This interpreter should be able to run virtual assembly language programs created via the task. This is a byte-coded, 32-bit word stack based virtual machine. The program should read input from a file and/or stdin, an...
#Python
Python
from __future__ import print_function import sys, struct   FETCH, STORE, PUSH, ADD, SUB, MUL, DIV, MOD, LT, GT, LE, GE, EQ, NE, AND, OR, NEG, NOT, \ JMP, JZ, PRTC, PRTS, PRTI, HALT = range(24)   code_map = { "fetch": FETCH, "store": STORE, "push": PUSH, "add": ADD, "sub": SUB, "mul": MUL,...
http://rosettacode.org/wiki/Compiler/code_generator
Compiler/code generator
A code generator translates the output of the syntax analyzer and/or semantic analyzer into lower level code, either assembly, object, or virtual. Task[edit] Take the output of the Syntax analyzer task - which is a flattened Abstract Syntax Tree (AST) - and convert it to virtual machine code, that can be run by the Vi...
#Raku
Raku
my %opnames = < Less lt LessEqual le Multiply mul Subtract sub NotEqual ne Divide div GreaterEqual ge Equal eq Greater gt Negate neg >;   my (@AST, %strings, %names); my $string-count = my $name-count = my $pairsym = my $pc = 0;   sub tree { my ($A, $B) = ( '_' ~ ++$p...
http://rosettacode.org/wiki/Compare_length_of_two_strings
Compare length of two strings
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Python
Python
A = 'I am string' B = 'I am string too'   if len(A) > len(B): print('"' + A + '"', 'has length', len(A), 'and is the longest of the two strings') print('"' + B + '"', 'has length', len(B), 'and is the shortest of the two strings') elif len(A) < len(B): print('"' + B + '"', 'has length', len(B), 'and is the ...
http://rosettacode.org/wiki/Compare_length_of_two_strings
Compare length of two strings
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#QB64
QB64
  Dim Words(1 To 4) As String Dim Lengths As Integer, Index As Integer, Position As Integer, Done As String, Index2 As Integer ' inititialization Words(1) = "abcd" Words(2) = "123456789" Words(3) = "abcdef" Words(4) = "1234567"   Print " Word Length" For Index2 = 1 To 4 Step 1 Lengths = 0 Position = 0 ...
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...
#Zig
Zig
  const std = @import("std");   pub const NodeValue = union(enum) { integer: i32, string: []const u8,   fn fromToken(token: Token) ?NodeValue { if (token.value) |value| { switch (value) { .integer => |int| return NodeValue{ .integer = int }, .string => |st...
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...
#Elena
Elena
import extensions; import system'threading; import cellular;   const int maxX = 48; const int maxY = 28;   const int DELAY = 50;   sealed class Model { Space theSpace; RuleSet theRuleSet; bool started;   event Func<Space, object> OnUpdate;   constructor newRandomset(RuleSet transformSet) { ...
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...
#Standard_ML
Standard ML
datatype tree = Empty | Leaf of int | Node of tree * tree   val t1 = Node (Leaf 1, Node (Leaf 2, Leaf 3))
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...
#Stata
Stata
mata struct Point { real scalar x, y }   // dumb example function test() { struct Point scalar a a.x = 10 a.y = 20 printf("%f\n",a.x+a.y) }   test() 30 end
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...
#Swift
Swift
// Structure struct Point { var x:Int var y:Int }   // Tuple typealias PointTuple = (Int, Int)   // Class class PointClass { var x:Int! var y:Int!   init(x:Int, y:Int) { self.x = x self.y = y } }
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 ...
#blz
blz
  if i % 2 == 0 print("even") else print("odd") end  
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#Forth
Forth
\ linked list of strings creators : ," ( -- ) [CHAR] " WORD c@ 1+ ALLOT  ; \ Parse input stream until " and write into next available memory : [[ ( -- ) 0 C, ; \ begin a list. write a 0 into next memory byte (null string) : ]] ( -- ) [[ ; ...
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#Fortran
Fortran
  INTEGER MANY,LONG PARAMETER (LONG = 6,MANY = 4) !Adjust to suit. CHARACTER*(LONG) STRINGS(MANY) !A list of text strings. STRINGS(1) = "Fee" STRINGS(2) = "Fie" STRINGS(3) = "Foe" STRINGS(4) = "Fum" IF (ALL(STRINGS(1:MANY - 1) .LT. STRINGS(2:MANY))) THEN WRITE (6,...
http://rosettacode.org/wiki/Comma_quibbling
Comma quibbling
Comma quibbling is a task originally set by Eric Lippert in his blog. Task Write a function to generate a string output which is the concatenation of input words from a list/sequence where: An input of no words produces the output string of just the two brace characters "{}". An input of just one word, e.g. ["AB...
#C
C
#include <stdio.h> #include <string.h> #include <stdlib.h>   char *quib(const char **strs, size_t size) {   size_t len = 3 + ((size > 1) ? (2 * size + 1) : 0); size_t i;   for (i = 0; i < size; i++) len += strlen(strs[i]);   char *s = malloc(len * sizeof(*s)); if (!s) { perror("C...
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#Clojure
Clojure
  (defn combinations [coll k] (when-let [[x & xs] coll] (if (= k 1) (map list coll) (concat (map (partial cons x) (combinations coll (dec k))) (combinations xs k)))))  
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#CoffeeScript
CoffeeScript
  combos = (arr, k) -> return [ [] ] if k == 0 return [] if arr.length == 0   combos_with_head = ([arr[0]].concat combo for combo in combos arr, k-1) combos_sans_head = combos arr[1...], k combos_with_head.concat combos_sans_head   arr = ['iced', 'jam', 'plain'] console.log "valid pairs from #{arr.join ','}:"...
http://rosettacode.org/wiki/Combinations_and_permutations
Combinations and permutations
This page uses content from Wikipedia. The original article was at Combination. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) This page uses content from Wikipedia. The original article was at P...
#Haskell
Haskell
perm :: Integer -> Integer -> Integer perm n k = product [n-k+1..n]   comb :: Integer -> Integer -> Integer comb n k = perm n k `div` product [1..k]   main :: IO () main = do let showBig maxlen b = let st = show b stlen = length st in if stlen < maxlen then st...
http://rosettacode.org/wiki/Compiler/lexical_analyzer
Compiler/lexical analyzer
Definition from Wikipedia: Lexical analysis is the process of converting a sequence of characters (such as in a computer program or web page) into a sequence of tokens (strings with an identified "meaning"). A program that performs lexical analysis may be called a lexer, tokenizer, or scanner (though "scanner" is als...
#Erlang
Erlang
#!/bin/env escript %%%-------------------------------------------------------------------   -record (inp_t, {inpf, pushback, line_no, column_no}).   main (Args) -> main_program (Args).   main_program ([]) -> scan_from_inpf_to_outf ("-", "-"), halt (0); main_program ([Inpf_filename]) -> scan_from_inpf_to_out...
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Common_Lisp
Common Lisp
(defun argv () (or #+clisp (ext:argv) #+sbcl sb-ext:*posix-argv* #+abcl ext:*command-line-argument-list* #+clozure (ccl::command-line-arguments) #+gcl si:*command-args* #+ecl (loop for i from 0 below (si:argc) collect (si:argv i)) #+cmu extensions:*command-line-strings* #+allegro (sys:command-...
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Cowgol
Cowgol
include "cowgol.coh"; include "argv.coh";   ArgvInit(); var i: uint8 := 0;   loop var arg := ArgvNext(); if arg == 0 as [uint8] then break; end if; i := i + 1; print_i8(i); print(": '"); print(arg); print("'\n"); end loop;
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#AutoIt
AutoIt
  #cs Everything between the cs and and the ce is commented. Commented code is not used by the computer. #ce ;individual lines after a semicolon are commented.  
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#AWK
AWK
BEGIN { # this code does something # do something }
http://rosettacode.org/wiki/Compiler/virtual_machine_interpreter
Compiler/virtual machine interpreter
A virtual machine implements a computer in software. Task[edit] Write a virtual machine interpreter. This interpreter should be able to run virtual assembly language programs created via the task. This is a byte-coded, 32-bit word stack based virtual machine. The program should read input from a file and/or stdin, an...
#Racket
Racket
#lang typed/racket ;;; ;;; The Rosetta Code Virtual Machine, in Typed Racket. ;;; ;;; Migrated from the Common Lisp. ;;;   ;;; Yes, I could compute how much memory is needed, or I could assume ;;; that the instructions are in address order. However, for *this* ;;; implementation I am going to use a large fixed-size mem...
http://rosettacode.org/wiki/Compiler/code_generator
Compiler/code generator
A code generator translates the output of the syntax analyzer and/or semantic analyzer into lower level code, either assembly, object, or virtual. Task[edit] Take the output of the Syntax analyzer task - which is a flattened Abstract Syntax Tree (AST) - and convert it to virtual machine code, that can be run by the Vi...
#RATFOR
RATFOR
###################################################################### # # The Rosetta Code code generator in Ratfor 77. # # # In FORTRAN 77 and therefore in Ratfor 77, there is no way to specify # that a value should be put on a call stack. Therefore there is no # way to implement recursive algorithms in Ratfor 77 (al...
http://rosettacode.org/wiki/Compare_length_of_two_strings
Compare length of two strings
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Quackery
Quackery
$ "A short string of" $ "A slightly longer string of"   2dup size dip size > if swap dup echo$ sp size echo say " characters." cr dup echo$ sp size echo say " characters." cr cr   ' [ $ "From troubles of the world I turn to ducks," $ "Beautiful comical things" $ "Sleeping or curled" $...
http://rosettacode.org/wiki/Compare_length_of_two_strings
Compare length of two strings
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Raku
Raku
say 'Strings (👨‍👩‍👧‍👦, 🤔🇺🇸, BOGUS!) sorted: "longest" first:'; say "$_: characters:{.chars}, Unicode code points:{.codes}, UTF-8 bytes:{.encode('UTF8').bytes}, UTF-16 bytes:{.encode('UTF16').bytes}" for <👨‍👩‍👧‍👦 BOGUS! 🤔🇺🇸>.sort: -*.chars;
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...
#Elixir
Elixir
defmodule Conway do def game_of_life(name, size, generations, initial_life\\nil) do board = seed(size, initial_life) print_board(board, name, size, 0) reason = generate(name, size, generations, board, 1) case reason do  :all_dead -> "no more life."  :static -> "no movement" _ ...
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...
#Tcl
Tcl
array set point {x 4 y 5} set point(y) 7 puts "Point is {$point(x),$point(y)}" # => Point is {4,7}
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...
#TI-89_BASIC
TI-89 BASIC
(defstruct point nil (x 0) (y 0))
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 ...
#Bori
Bori
  if (i == 0) return "zero"; elif (i % 2) return "odd"; else return "even";  
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#FreeBASIC
FreeBASIC
  ' FB 1.05.0 Win64   Function AllEqual(strings() As String) As Boolean Dim length As Integer = UBound(strings) - LBound(strings) + 1 If length < 2 Then Return False For i As Integer = LBound(strings) + 1 To UBound(strings) If strings(i - 1) <> strings(i) Then Return False Next Return True End Funct...
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#F.C5.8Drmul.C3.A6
Fōrmulæ
package cmp   func AllEqual(strings []string) bool { for _, s := range strings { if s != strings[0] { return false } } return true }   func AllLessThan(strings []string) bool { for i := 1; i < len(strings); i++ { if !(strings[i - 1] < s) { return false } } return true }
http://rosettacode.org/wiki/Comma_quibbling
Comma quibbling
Comma quibbling is a task originally set by Eric Lippert in his blog. Task Write a function to generate a string output which is the concatenation of input words from a list/sequence where: An input of no words produces the output string of just the two brace characters "{}". An input of just one word, e.g. ["AB...
#C.23
C#
using System; using System.Linq;   namespace CommaQuibbling { internal static class Program { #region Static Members private static string Quibble(string[] input) { return String.Format("{{{0}}}", String.Join("", input.Reverse().Z...
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#Common_Lisp
Common Lisp
(defun combinations (xs k) (let ((x (car xs))) (cond ((null xs) nil) ((= k 1) (mapcar #'list xs)) (t (append (mapcar (lambda (ys) (cons x ys)) (combinations xs (1- k))) (combinations (cdr xs) k))))))  
http://rosettacode.org/wiki/Combinations_and_permutations
Combinations and permutations
This page uses content from Wikipedia. The original article was at Combination. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) This page uses content from Wikipedia. The original article was at P...
#Icon_and_Unicon
Icon and Unicon
procedure main() write("P(4,2) = ",P(4,2)) write("P(8,2) = ",P(8,2)) write("P(10,8) = ",P(10,8)) write("C(10,8) = ",C(10,8)) write("C(20,8) = ",C(20,8)) write("C(60,58) = ",C(60,58)) write("P(1000,10) = ",P(1000,10)) write("P(1000,20) = ",P(1000,20)) write("P(15000,2) = ",P(15000,2))...
http://rosettacode.org/wiki/Compiler/lexical_analyzer
Compiler/lexical analyzer
Definition from Wikipedia: Lexical analysis is the process of converting a sequence of characters (such as in a computer program or web page) into a sequence of tokens (strings with an identified "meaning"). A program that performs lexical analysis may be called a lexer, tokenizer, or scanner (though "scanner" is als...
#Euphoria
Euphoria
include std/io.e include std/map.e include std/types.e include std/convert.e   constant true = 1, false = 0, EOF = -1   enum tk_EOI, tk_Mul, tk_Div, tk_Mod, tk_Add, tk_Sub, tk_Negate, tk_Not, tk_Lss, tk_Leq, tk_Gtr, tk_Geq, tk_Eq, tk_Neq, tk_Assign, tk_And, tk_Or, tk_If, tk_Else, tk_While, tk_Print, tk_Putc, tk...
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#D
D
void main(in string[] args) { import std.stdio;   foreach (immutable i, arg; args[1 .. $]) writefln("#%2d : %s", i + 1, arg); }
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Dart
Dart
main(List<String> args) { for(var arg in args) print(arg); }
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#Axe
Axe
.This is a single-line comment
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#Babel
Babel
  -- This is a line-comment   # This is a block-comment It goes until de-dent   dedent: 0x42 -- The comment block above is now closed  
http://rosettacode.org/wiki/Compiler/virtual_machine_interpreter
Compiler/virtual machine interpreter
A virtual machine implements a computer in software. Task[edit] Write a virtual machine interpreter. This interpreter should be able to run virtual assembly language programs created via the task. This is a byte-coded, 32-bit word stack based virtual machine. The program should read input from a file and/or stdin, an...
#Raku
Raku
my @CODE = q:to/END/.lines; Datasize: 3 Strings: 2 "count is: " "\n" 0 push 1 5 store [0] 10 fetch [0] 15 push 10 20 lt 21 jz (68) 65 # jump value adjusted 26 push 0 31 prts 32 fetch [0] 37 prti 38 push 1 43 prts 44 fetch [0] 49 push 1 54 add 55 store [0] ...
http://rosettacode.org/wiki/Compiler/code_generator
Compiler/code generator
A code generator translates the output of the syntax analyzer and/or semantic analyzer into lower level code, either assembly, object, or virtual. Task[edit] Take the output of the Syntax analyzer task - which is a flattened Abstract Syntax Tree (AST) - and convert it to virtual machine code, that can be run by the Vi...
#Scala
Scala
  package xyz.hyperreal.rosettacodeCompiler   import scala.collection.mutable.{ArrayBuffer, HashMap} import scala.io.Source   object CodeGenerator {   def fromStdin = fromSource(Source.stdin)   def fromString(src: String) = fromSource(Source.fromString(src))   def fromSource(ast: Source) = { val vars ...
http://rosettacode.org/wiki/Compare_length_of_two_strings
Compare length of two strings
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#REXX
REXX
/* REXX */ list = '"abcd","123456789","abcdef","1234567"' Do i=1 By 1 While list>'' Parse Var list s.i ',' list s.i=strip(s.i,,'"') End n=i-1 Do While n>1 max=0 Do i=1 To n If length(s.i)>max Then Do k=i max=length(s.i) End End Call o s.k If k<n Then s.k=s.n n=n-1 End Cal...
http://rosettacode.org/wiki/Compare_length_of_two_strings
Compare length of two strings
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Ring
Ring
  see "working..." + nl   list = ["abcd","123456789"] if len(list[1]) > len(list[2]) first = list[1] second = list[2] else first = list[2] second = list[1] ok   see "Compare length of two strings:" + nl see "" + first + " len = " + len(first) + nl + second + " len = " + len(second) + nl see "done..." + nl  
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...
#Emacs_Lisp
Emacs Lisp
#!/usr/bin/env emacs -script ;; -*- lexical-binding: t -*- ;; run: ./conways-life conways-life.config (require 'cl-lib)   (defconst blinker '("***")) (defconst toad '(".***" "***.")) (defconst pentomino-p '(".**" ".**" ".*.")) (defconst pi-heptomino '("***" "*.*" "*.*")) (defconst glider '(".*." "..*" "***")) (defconst...
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...
#TXR
TXR
(defstruct point nil (x 0) (y 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...
#UNIX_Shell
UNIX Shell
typeset -T Point=( typeset x typeset y ) Point p p.x=1 p.y=2 echo $p echo ${p.x} ${p.y} Point q=(x=3 y=4) echo ${q.x} ${q.y}
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 ...
#BQN
BQN
If ← {𝕏⍟𝕎@}´ # Also Repeat IfElse ← {c‿T‿F: c◶F‿T@} While ← {𝕩{𝔽⍟𝔾∘𝔽_𝕣_𝔾∘𝔽⍟𝔾𝕩}𝕨@}´ # While 1‿{... to run forever DoWhile ← {𝕏@ ⋄ While 𝕨‿𝕩}´ For ← {I‿C‿P‿A: I@ ⋄ While⟨C,P∘A⟩}   # Switch/case statements have many variations; these are a few Match ← {𝕏𝕨}´ Select ← {(⊑𝕩)◶...
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#Go
Go
package cmp   func AllEqual(strings []string) bool { for _, s := range strings { if s != strings[0] { return false } } return true }   func AllLessThan(strings []string) bool { for i := 1; i < len(strings); i++ { if !(strings[i - 1] < s) { return false } } return true }
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#Gosu
Gosu
var list = {"a", "b", "c", "d"}   var isHomogeneous = list.toSet().Count < 2 var isOrderedSet = list.toSet().order().toList() == list
http://rosettacode.org/wiki/Comma_quibbling
Comma quibbling
Comma quibbling is a task originally set by Eric Lippert in his blog. Task Write a function to generate a string output which is the concatenation of input words from a list/sequence where: An input of no words produces the output string of just the two brace characters "{}". An input of just one word, e.g. ["AB...
#C.2B.2B
C++
#include <iostream>   template<class T> void quibble(std::ostream& o, T i, T e) { o << "{"; if (e != i) { T n = i++; const char* more = ""; while (e != i) { o << more << *n; more = ", "; n = i++; } o << (*more?" and ":"") << *n; } o << "}"; }   int main(int argc, char** arg...
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#Crystal
Crystal
possible_doughnuts = ["iced", "jam", "plain"].repeated_combinations(2) puts "There are #{possible_doughnuts.size} possible doughnuts:" possible_doughnuts.each{|doughnut_combi| puts doughnut_combi.join(" and ")}   # Extra credit possible_doughnuts = (1..10).to_a.repeated_combinations(3) # size returns the size of the en...
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#D
D
import std.stdio, std.range;   const struct CombRep { immutable uint nt, nc; private const ulong[] combVal;   this(in uint numType, in uint numChoice) pure nothrow @safe in { assert(0 < numType && numType + numChoice <= 64, "Valid only for nt + nc <= 64 (ulong bit size)"); } b...
http://rosettacode.org/wiki/Combinations_and_permutations
Combinations and permutations
This page uses content from Wikipedia. The original article was at Combination. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) This page uses content from Wikipedia. The original article was at P...
#J
J
C=: ! P=: (%&!&x:~ * <:)"0
http://rosettacode.org/wiki/Combinations_and_permutations
Combinations and permutations
This page uses content from Wikipedia. The original article was at Combination. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) This page uses content from Wikipedia. The original article was at P...
#Java
Java
  import java.math.BigInteger;   public class CombinationsAndPermutations {   public static void main(String[] args) { System.out.println(Double.MAX_VALUE); System.out.println("A sample of permutations from 1 to 12 with exact Integer arithmetic:"); for ( int n = 1 ; n <= 12 ; n++ ) { ...
http://rosettacode.org/wiki/Compiler/lexical_analyzer
Compiler/lexical analyzer
Definition from Wikipedia: Lexical analysis is the process of converting a sequence of characters (such as in a computer program or web page) into a sequence of tokens (strings with an identified "meaning"). A program that performs lexical analysis may be called a lexer, tokenizer, or scanner (though "scanner" is als...
#Flex
Flex
%{ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <limits.h>   #define NELEMS(arr) (sizeof(arr) / sizeof(arr[0]))   typedef enum { tk_EOI, tk_Mul, tk_Div, tk_Mod, tk_Add, tk_Sub, tk_Negate, tk_Not, tk_Lss, tk_Leq, tk_Gtr, tk_Geq, tk_Eq, tk_Neq, tk_Assign, tk_And, tk_Or, t...
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#DCL
DCL
$ i = 1 $ loop: $ write sys$output "the value of P''i' is ", p'i $ i = i + 1 $ if i .le. 8 then $ goto loop
http://rosettacode.org/wiki/Command-line_arguments
Command-line arguments
Command-line arguments is part of Short Circuit's Console Program Basics selection. Scripted main See also Program name. For parsing command line arguments intelligently, see Parsing command-line arguments. Example command line: myprogram -c "alpha beta" -h "gamma"
#Delphi
Delphi
// The program name and the directory it was called from are in // param[0] , so given the axample of myprogram -c "alpha beta" -h "gamma"   for x := 0 to paramcount do writeln('param[',x,'] = ',param[x]);   // will yield ( assuming windows and the c drive as the only drive) :   // param[0] = c:\myprogram // ...
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#BASIC
BASIC
100 REM Standard BASIC comments begin with "REM" (remark) and extend to the end of the line 110 PRINT "this is code": REM comment after statement
http://rosettacode.org/wiki/Comments
Comments
Task Show all ways to include text in a language source file that's completely ignored by the compiler or interpreter. Related tasks   Documentation   Here_document See also   Wikipedia   xkcd (Humor: hand gesture denoting // for "commenting out" people.)
#Batch_File
Batch File
rem Single-line comment.
http://rosettacode.org/wiki/Compiler/virtual_machine_interpreter
Compiler/virtual machine interpreter
A virtual machine implements a computer in software. Task[edit] Write a virtual machine interpreter. This interpreter should be able to run virtual assembly language programs created via the task. This is a byte-coded, 32-bit word stack based virtual machine. The program should read input from a file and/or stdin, an...
#RATFOR
RATFOR
###################################################################### # # The Rosetta Code code virtual machine in Ratfor 77. # # The implementation assumes your FORTRAN compiler supports 1-byte # INTEGER*1 and 4-byte INTEGER*4. Integer storage will be # native-endian, achieved via EQUIVALENCE. (GNU Fortran and f2c bo...
http://rosettacode.org/wiki/Compiler/code_generator
Compiler/code generator
A code generator translates the output of the syntax analyzer and/or semantic analyzer into lower level code, either assembly, object, or virtual. Task[edit] Take the output of the Syntax analyzer task - which is a flattened Abstract Syntax Tree (AST) - and convert it to virtual machine code, that can be run by the Vi...
#Scheme
Scheme
  (import (scheme base) (scheme file) (scheme process-context) (scheme write) (only (srfi 1) delete-duplicates list-index) (only (srfi 13) string-delete string-index string-trim))   (define *names* '((Add add) (Subtract sub) (Multiply mul) (Divide div) (Mod mod) ...
http://rosettacode.org/wiki/Compare_length_of_two_strings
Compare length of two strings
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Ruby
Ruby
  a, b = "Given two strings", "of different length" [a,b].sort_by{|s| - s.size }.each{|s| puts s + " (size: #{s.size})"}   list = ["abcd","123456789","abcdef","1234567"] puts list.sort_by{|s|- s.size}  
http://rosettacode.org/wiki/Compare_length_of_two_strings
Compare length of two strings
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Rust
Rust
  fn compare_and_report<T: ToString>(string1: T, string2: T) -> String { let strings = [string1.to_string(), string2.to_string()]; let difference = strings[0].len() as i32 - strings[1].len() as i32; if difference == 0 { // equal format!("\"{}\" and \"{}\" are of equal length, {}", strings[0], string...
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...
#Erlang
Erlang
    -module(life).   -export([bang/1]).     -define(CHAR_DEAD, 32). % " " -define(CHAR_ALIVE, 111). % "o" -define(CHAR_BAR, 45). % "-"   -define(GEN_INTERVAL, 100).     -record(state, {x  :: non_neg_integer() ,y  :: non_neg_integer() ,n  :: pos_integer...
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...
#Ursala
Ursala
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...
#Vala
Vala
struct Point { int x; int y; }
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 ...
#Bracmat
Bracmat
2+2:5 & put$"Strange, must check that Bracmat interpreter." & 0 | put$"That's what I thought." & Right
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#Haskell
Haskell
allEqual :: Eq a => [a] -> Bool allEqual xs = and $ zipWith (==) xs (tail xs)   allIncr :: Ord a => [a] -> Bool allIncr xs = and $ zipWith (<) xs (tail xs)
http://rosettacode.org/wiki/Compare_a_list_of_strings
Compare a list of strings
Task Given a   list   of arbitrarily many strings, show how to:   test if they are all lexically equal   test if every string is lexically less than the one after it (i.e. whether the list is in strict ascending order) Each of those two tests should result in a single true or false value, which could be used as t...
#Icon_and_Unicon
Icon and Unicon
# # list-compare.icn # link fullimag   procedure main() L1 := ["aa"] L2 := ["aa", "aa", "aa"] L3 := ["", "aa", "ab", "ac"] L4 := ["aa", "bb", "cc"] L5 := ["cc", "bb", "aa"]   every L := (L1 | L2 | L3 | L4 | L5) do { writes(fullimage(L)) writes(": equal ") writes(if allequal(L) then "...
http://rosettacode.org/wiki/Comma_quibbling
Comma quibbling
Comma quibbling is a task originally set by Eric Lippert in his blog. Task Write a function to generate a string output which is the concatenation of input words from a list/sequence where: An input of no words produces the output string of just the two brace characters "{}". An input of just one word, e.g. ["AB...
#Clojure
Clojure
(defn quibble [sq] (let [sep (if (pos? (count sq)) " and " "")] (apply str (concat "{" (interpose ", " (butlast sq)) [sep (last sq)] "}"))))   ; Or, using clojure.pprint's cl-format, which implements common lisp's format: (defn quibble-f [& args] (clojure.pprint/cl-format nil "{~{~a~#[~; and ~:;, ~]~}}" a...
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#EasyLang
EasyLang
items$[] = [ "iced" "jam" "plain" ] n = len items$[] k = 2 len result[] k n_results = 0 # func output . . n_results += 1 if len items$[] > 0 for r in result[] write items$[r] & " " . print "" . . func combine pos val . . if pos = k call output else for i = val to n - 1 result[...
http://rosettacode.org/wiki/Combinations_with_repetitions
Combinations with repetitions
The set of combinations with repetitions is computed from a set, S {\displaystyle S} (of cardinality n {\displaystyle n} ), and a size of resulting selection, k {\displaystyle k} , by reporting the sets of cardinality k {\displaystyle k} where each member of those sets is chosen from S...
#EchoLisp
EchoLisp
  ;; ;; native function : combinations/rep in list.lib ;; (lib 'list)   (combinations/rep '(iced jam plain) 2) → ((iced iced) (iced jam) (iced plain) (jam jam) (jam plain) (plain plain))   ;; ;; using a combinator iterator ;; (lib 'sequences)   (take (combinator/rep '(iced jam plain) 2) 8) → ((iced iced) (iced ...
http://rosettacode.org/wiki/Combinations_and_permutations
Combinations and permutations
This page uses content from Wikipedia. The original article was at Combination. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) This page uses content from Wikipedia. The original article was at P...
#jq
jq
def permutation(k): . as $n | reduce range($n-k+1; 1+$n) as $i (1; . * $i);   def combination(k): . as $n | if k > ($n/2) then combination($n-k) else reduce range(0; k) as $i (1; (. * ($n - $i)) / ($i + 1)) end;   # natural log of n! def log_factorial: (1+.) | tgamma | log;   def log_permutation(k): (log_...
http://rosettacode.org/wiki/Combinations_and_permutations
Combinations and permutations
This page uses content from Wikipedia. The original article was at Combination. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) This page uses content from Wikipedia. The original article was at P...
#Julia
Julia
  function Base.binomial{T<:FloatingPoint}(n::T, k::T) exp(lfact(n) - lfact(n - k) - lfact(k)) end   function Base.factorial{T<:FloatingPoint}(n::T, k::T) exp(lfact(n) - lfact(k)) end   ⊞{T<:Real}(n::T, k::T) = binomial(n, k) ⊠{T<:Real}(n::T, k::T) = factorial(n, n-k)