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/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...
#Forth
Forth
CREATE BUF 0 , \ single-character look-ahead buffer CREATE COLUMN# 0 , CREATE LINE# 1 ,   : NEWLINE? ( c -- t|f) DUP 10 = SWAP 13 = OR ; : +IN ( c --) 1 SWAP NEWLINE? IF 0 COLUMN# ! LINE# ELSE COLUMN# THEN +! 0 BUF ! ; : PEEK BUF @ 0= IF STDIN KEY-FILE BUF ! THEN BUF @ ; : GETC PEEK DUP ...
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.C3.A9j.C3.A0_Vu
Déjà Vu
for i range 0 -- len !args: print\( "Argument #" i " is " ) . get-from !args i   if has !opts :c: !print "Ah, the -c option."   if has !opts :four: !. get-from !opts :four
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"
#Draco
Draco
\util.g   proc nonrec main() void: *char par; word i; i := 0; while par := GetPar(); par ~= nil do i := i + 1; writeln(i:3, ": '", par, "'") od corp
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"
#E
E
interp.getArgs()
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.)
#BBC_BASIC
BBC BASIC
REM This is a comment which is ignored by the compiler *| This is a comment which is compiled but ignored at run time
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.)
#bc
bc
/* This is a comment. */   2 + /* Comment between tokens. */ 3   "This is a string, /* NOT a comment */."   /* * A comment can have multiple lines. These asterisks in the middle * of the comment are only for style. You must not nest a comment * inside another comment; the first asterisk-slash ends the 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...
#Scala
Scala
  package xyz.hyperreal.rosettacodeCompiler   import java.io.{BufferedReader, FileReader, Reader, StringReader}   import scala.collection.mutable import scala.collection.mutable.ArrayBuffer   object VirtualMachine {   private object Opcodes { val FETCH: Byte = 0 val STORE: Byte = 1 val PUSH: Byte = 2 ...
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...
#Wren
Wren
import "/dynamic" for Enum, Struct, Tuple import "/crypto" for Bytes import "/fmt" for Fmt import "/ioutil" for FileUtil   var nodes = [ "Ident", "String", "Integer", "Sequence", "If", "Prtc", "Prts", "Prti", "While", "Assign", "Negate", "Not", "Mul", "Div", "...
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 |...
#Vlang
Vlang
// Compare lenth of two strings, in V // Tectonics: v run compare-length-of-two-strings.v module main   // starts here pub fn main() { mut strs := ["abcd","123456789"] println("Given: $strs") strs.sort_by_len() for i := strs.len-1; i >= 0; i-- { println("${strs[i]}: with length ${strs[i].len}") ...
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 |...
#Wren
Wren
import "./upc" for Graphemes   var printCounts = Fn.new { |s1, s2, c1, c2| var l1 = (c1 > c2) ? [s1, c1] : [s2, c2] var l2 = (c1 > c2) ? [s2, c2] : [s1, c1] System.print( "%(l1[0]) : length %(l1[1])") System.print( "%(l2[0]) : length %(l2[1])\n") }   var codepointCounts = Fn.new { |s1, s2| var c1 = s1....
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...
#ERRE
ERRE
  PROGRAM LIFE   !$INTEGER   !$KEY !for C-64 compatibility   CONST Xmax=38,Ymax=20   DIM x,y,N DIM WORLD[39,21],NextWORLD[39,21]   BEGIN   ! Glider test !------------------------------------------ WORLD[1,1]=1 WORLD[1,2]=0 WORLD[1,3]=0 WORLD[2,1]=0 WORLD[2,2]=1 WORLD[2,3]=1 WORLD[3,1]=1 WORLD[3,2]=1 WORLD[3,3]=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...
#VBA
VBA
Type point x As Integer y As Integer 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...
#Vim_Script
Vim Script
function MakePoint(x, y) " 'Constructor' return {"x": a:x, "y": a:y} endfunction   let p1 = MakePoint(3, 2) let p2 = MakePoint(-1, -4)   echon "Point 1: x = " p1.x ", y = " p1.y "\n" echon "Point 2: x = " p2.x ", y = " p2.y "\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 ...
#Brainf.2A.2A.2A
Brainf***
[.]
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...
#J
J
allEq =: 1 = +/@~: NB. or 1 = #@:~. or -: 1&|. or }.-:}:
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...
#Java
Java
import java.util.Arrays;   public class CompareListOfStrings {   public static void main(String[] args) { String[][] arr = {{"AA", "AA", "AA", "AA"}, {"AA", "ACB", "BB", "CC"}}; for (String[] a : arr) { System.out.println(Arrays.toString(a)); System.out.println(Arrays.stream(...
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...
#CLU
CLU
quibble = proc (words: array[string]) returns (string) out: string := "{" last: int := array[string]$high(words)   for i: int in array[string]$indexes(words) do out := out || words[i] if i < last-1 then out := out || ", " elseif i = last-1 then out := out || "...
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...
#COBOL
COBOL
>>SOURCE FORMAT IS FREE IDENTIFICATION DIVISION. PROGRAM-ID. comma-quibbling-test.   ENVIRONMENT DIVISION. CONFIGURATION SECTION. REPOSITORY. FUNCTION comma-quibbling . DATA DIVISION. WORKING-STORAGE SECTION. 01 strs-area. 03 strs-len PIC 9. 03 strs PIC X(...
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...
#Egison
Egison
  (define $comb/rep (lambda [$n $xs] (match-all xs (list something) [(loop $i [1 ,n] <join _ (& <cons $a_i _> ...)> _) a])))   (test (comb/rep 2 {"iced" "jam" "plain"}))  
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...
#Elixir
Elixir
defmodule RC do def comb_rep(0, _), do: [[]] def comb_rep(_, []), do: [] def comb_rep(n, [h|t]=s) do (for l <- comb_rep(n-1, s), do: [h|l]) ++ comb_rep(n, t) end end   s = [:iced, :jam, :plain] Enum.each(RC.comb_rep(2, s), fn x -> IO.inspect x end)   IO.puts "\nExtra credit: #{length(RC.comb_rep(3, Enum.to...
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...
#Kotlin
Kotlin
// version 1.1.2   import java.math.BigInteger   fun perm(n: Int, k: Int): BigInteger { require(n > 0 && k >= 0) return (n - k + 1 .. n).fold(BigInteger.ONE) { acc, i -> acc * BigInteger.valueOf(i.toLong()) } }   fun comb(n: Int, k: Int): BigInteger { require(n > 0 && k >= 0) val fact = (2..k).fold(BigI...
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...
#Fortran
Fortran
!!! !!! An implementation of the Rosetta Code lexical analyzer task: !!! https://rosettacode.org/wiki/Compiler/lexical_analyzer !!! !!! The C implementation was used as a reference on behavior, but was !!! not adhered to for the implementation. !!!   module string_buffers use, intrinsic :: iso_fortran_env, only: erro...
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"
#Eiffel
Eiffel
class APPLICATION inherit ARGUMENTS create make feature {NONE} -- Initialization make -- Print values for arguments with options 'c' and 'h'. do print ("Command line argument value for option 'c' is: ") print (separate_character_option_value ('c') + "%N") ...
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"
#Elena
Elena
import system'routines; import extensions;   public program() { program_arguments.forEvery:(int i) { console.printLine("Argument ",i," is ",program_arguments[i]) } }
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.)
#Befunge
Befunge
& read a number 2+ add two .@ display result and exit ^- inline comments -^ <-^- other comments
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.)
#Blast
Blast
# A hash symbol at the beginning of a line marks the line as a 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...
#Scheme
Scheme
  (import (scheme base) (scheme char) (scheme file) (scheme process-context) (scheme write) (only (srfi 13) string-contains string-delete string-filter string-replace string-tokenize))   (define *word-size* 4)   ;; Mappings from operation symbols to internal proced...
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...
#Zig
Zig
  const std = @import("std");   pub const CodeGeneratorError = error{OutOfMemory};   pub const CodeGenerator = struct { allocator: std.mem.Allocator, string_pool: std.ArrayList([]const u8), globals: std.ArrayList([]const u8), bytecode: std.ArrayList(u8),   const Self = @This(); const word_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 |...
#XPL0
XPL0
string 0; \use zero-terminated string convention   func StrLen(A); \Return number of characters in an ASCIIZ string char A; int I; for I:= 0 to -1>>1 do if A(I) = 0 then return I;   char List; int M, N, SN, Len, Max; [List:= ["abcd","123456789","abcdef","1234567"]; for M:= 0 ...
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 |...
#Z80_Assembly
Z80 Assembly
Terminator equ 0 ;null terminator PrintChar equ &BB5A ;Amstrad CPC BIOS call, prints accumulator to screen as an ASCII character.   org &8000   ld hl,String1 ld de,String2 call CompareStringLengths   jp nc, Print_HL_First ex de,hl Print_HL_First: push bc push hl call PrintString pop hl pu...
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...
#F.23
F#
let count (a: _ [,]) x y = let m, n = a.GetLength 0, a.GetLength 1 let mutable c = 0 for x in x-1..x+1 do for y in y-1..y+1 do if x>=0 && x<m && y>=0 && y<n && a.[x, y] then c <- c + 1 if a.[x, y] then c-1 else c   let rule (a: _ [,]) x y = match a.[x, y], count a x y with | true, (2 | 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...
#Visual_Basic_.NET
Visual Basic .NET
Structure Point Public X, Y As Integer End Structure
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...
#Wren
Wren
class Point { construct new(x, y) { _x = x _y = y } x { _x } y { _y }   // for illustration allow Points to be mutated x=(value) { _x = value } y=(value) { _y = value }   toString { "(%(_x), %(_y))" } }   var p = Point.new(1, 2) System.print(p.toString)   // mutate Point ...
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 ...
#Burlesque
Burlesque
  blsq ) 9 2.%{"Odd""Even"}ch "Odd"  
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...
#JavaScript
JavaScript
function allEqual(a) { var out = true, i = 0; while (++i<a.length) { out = out && (a[i-1] === a[i]); } return out; }   function azSorted(a) { var out = true, i = 0; while (++i<a.length) { out = out && (a[i-1] < a[i]); } return out; }   var e = ['AA', 'AA', 'AA', 'AA'], s = ['AA', 'ACB', 'BB', 'CC'],...
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...
#CoffeeScript
CoffeeScript
quibble = ([most..., last]) -> '{' + (most.join ', ') + (if most.length then ' and ' else '') + (last or '') + '}'   console.log quibble(s) for s in [ [], ["ABC"], ["ABC", "DEF"], ["ABC", "DEF", "G", "H" ] ]  
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...
#Erlang
Erlang
  -module(comb). -compile(export_all).   comb_rep(0,_) -> [[]]; comb_rep(_,[]) -> []; comb_rep(N,[H|T]=S) -> [[H|L] || L <- comb_rep(N-1,S)]++comb_rep(N,T).  
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...
#Fortran
Fortran
  program main integer :: chosen(4) integer :: ssize   character(len=50) :: donuts(4) = [ "iced", "jam", "plain", "something completely different" ]   ssize = choose( chosen, 2, 3 ) write(*,*) "Total = ", ssize   contains   recursive function choose( got, len, maxTypes, nChosen, at ) result ( output ) integer ...
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...
#M2000_Interpreter
M2000 Interpreter
  Module PermComb { Form 80, 50 perm=lambda (x,y) ->{ def i,z z=1 For i=x-y+1 to x :z*=i:next i =z } fact=lambda (x) ->{ def i,z z=1 For i=2 to x :z*=i:next i =z } comb=lambda (x as decima...
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...
#Maple
Maple
  comb := proc (n::integer, k::integer) return factorial(n)/(factorial(k)*factorial(n-k)); end proc; perm := proc (n::integer, k::integer) return factorial(n)/factorial(n-k); end proc;  
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...
#FreeBASIC
FreeBASIC
enum Token_type 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_Lparen tk_Rparen tk_Lbrace tk_Rbra...
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"
#Elixir
Elixir
#!/usr/bin/env elixir IO.puts 'Arguments:' Enum.map(System.argv(),&IO.puts(&1))
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"
#Emacs_Lisp
Emacs Lisp
(while argv (message "Argument: %S" (pop argv)))
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"
#Erlang
Erlang
3> init:get_arguments().
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.)
#BQN
BQN
# This is a 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.)
#Bracmat
Bracmat
This is a 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...
#Wren
Wren
import "/dynamic" for Enum import "/crypto" for Bytes import "/fmt" for Conv import "/ioutil" for FileUtil   var codes = [ "fetch", "store", "push", "add", "sub", "mul", "div", "mod", "lt", "gt", "le", "ge", "eq", "ne", "and", "or", "neg", "not", ...
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...
#zkl
zkl
// This is a little endian machine   const WORD_SIZE=4; const{ var _n=-1; var[proxy]N=fcn{ _n+=1 }; } // enumerator const FETCH=N, STORE=N, PUSH=N, ADD=N, SUB=N, MUL=N, DIV=N, MOD=N, LT=N, GT=N, LE=N, GE=N, EQ=N, NE=N, AND=N, OR=N, NEG=N, NOT=N, JMP=N, JZ=N, PRTC=N, PRTS=N,...
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...
#Fermat
Fermat
;{Conway's Game of Life in Fermat} ;{square grid with wrap-around boundaries}   size:=50; {how big a grid do you want? This fits my screen OK, change this for your own screen}   Array w1[size,size], w2[size,size]; {set up an active world and a 'scratchpad' world} act:=1; buf:=2; %[1]:=[w1];...
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...
#XSLT
XSLT
<point x="20" y="30"/>   <!-- context is a point node. The '@' prefix selects named attributes of the current node. --> <fo:block>Point = <xsl:value-of select="@x"/>, <xsl:value-of select="@y"/></fo:block>
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...
#zkl
zkl
class Point{ var x,y; fcn init(x,y){self.x=x.toFloat(); self.y=y.toFloat(); } fcn toString{ "P(%f,%f)".fmt(x,y) } fcn __opADD(P){} //+: add Point, constant or whatever //... __opEQ == etc } Point(1,2).println() //-->P(1.000000,2.000000)
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 ...
#C
C
if (condition) { // Some Task }   if (condition) { // Some Task } else if (condition2) { // Some Task } else { // Some Task }
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...
#jq
jq
# Are the strings all equal? def lexically_equal: . as $in | reduce range(0;length-1) as $i (true; if . then $in[$i] == $in[$i + 1] else false end);   # Are the strings in strictly ascending order? def lexically_ascending: . as $in | reduce range(0;length-1) as $i (true; if . then $in[$i] < $in[$i +...
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...
#Jsish
Jsish
/* Compare list of strings, in Jsish */ function allEqual(a) { var out = true, i = 0; while (++i<a.length) { out = out && (a[i-1] === a[i]); } return out; }   function allAscending(a) { var out = true, i = 0; while (++i<a.length) { out = out && (a[i-1] < a[i]); } return out; }   if (allEqual(strings...
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...
#Common_Lisp
Common Lisp
  (defun quibble (&rest args) (format t "{~{~a~#[~; and ~:;, ~]~}}" args))   (quibble) (quibble "ABC") (quibble "ABC" "DEF") (quibble "ABC" "DEF" "G" "H")  
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...
#Cowgol
Cowgol
include "cowgol.coh";   sub quibble(words: [[uint8]], length: intptr, buf: [uint8]): (out: [uint8]) is sub append(s: [uint8]) is while [s] != 0 loop [buf] := [s]; buf := @next buf; s := @next s; end loop; end sub;   out...
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...
#FreeBASIC
FreeBASIC
sub iterate( byval curr as string, byval start as uinteger,_ byval stp as uinteger, byval depth as uinteger,_ names() as string ) dim as uinteger i for i = start to stp if depth = 0 then print curr + " " + names(i) else iterate curr+" "+names(i...
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...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
ClearAll[Combination,Permutation] Combination[n_,k_]:=Binomial[n,k] Permutation[n_,k_]:=Binomial[n,k]k!   TableForm[Array[Permutation,{12,12}],TableHeadings->{Range[12],Range[12]}] TableForm[Array[Combination,{6,6},{{10,60},{10,60}}],TableHeadings->{Range[10,60,10],Range[10,60,10]}] {Row[{#,"P",#-2}," "],N@Permutation...
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...
#.D0.9C.D0.9A-61.2F52
МК-61/52
П2 <-> П1 -> <-> П7 КПП7 С/П ИП1 ИП2 - ПП 53 П3 ИП1 ПП 53 ИП3 / В/О 1 ИП1 * L2 21 В/О ИП1 ИП2 - ПП 53 П3 ИП2 ПП 53 ИП3 * П3 ИП1 ПП 53 ИП3 / В/О ИП1 ИП2 + 1 - П1 ПП 26 В/О ВП П0 1 ИП0 * L0 56 В/О
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...
#Go
Go
package main   import ( "bufio" "fmt" "log" "os" )   type TokenType int   const ( tkEOI TokenType = iota tkMul tkDiv tkMod tkAdd tkSub tkNegate tkNot tkLss tkLeq tkGtr tkGeq tkEq tkNeq tkAssign tkAnd tkOr tkIf tkElse tkWhile...
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"
#Euphoria
Euphoria
constant cmd = command_line() printf(1,"Interpreter/executable name: %s\n",{cmd[1]}) printf(1,"Program file name: %s\n",{cmd[2]}) if length(cmd)>2 then puts(1,"Command line arguments:\n") for i = 3 to length(cmd) do printf(1,"#%d : %s\n",{i,cmd[i]}) end for end if
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"
#F.23
F#
#light [<EntryPoint>] let main args = Array.iter (fun x -> printfn "%s" x) args 0
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.)
#Brainf.2A.2A.2A
Brainf***
This is a 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.)
#Brat
Brat
# Single line comment   #* 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...
#Zig
Zig
  const std = @import("std");   pub const VirtualMachineError = error{OutOfMemory};   pub const VirtualMachine = struct { allocator: std.mem.Allocator, stack: [stack_size]i32, program: std.ArrayList(u8), sp: usize, // stack pointer pc: usize, // program counter string_pool: std.ArrayList([]const...
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...
#Forth
Forth
\ The fast wrapping requires dimensions that are powers of 2. 1 6 lshift constant w \ 64 1 4 lshift constant h \ 16    : rows w * 2* ; 1 rows constant row h rows constant size   create world size allot world value old old w + value new   variable gens  : clear world size erase 0 gens ! ;  : age new ...
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...
#zonnon
zonnon
  {ref,public} (* class *) Point = object(ord,abs: integer) var (* instance variables *) {public,immutable} x,y: integer;   (* method *) procedure {public} Ord():integer; begin return y end Ord;   (* method *) procedure {public} Abs():integer; begin return x end Abs;   (* constructor *) begin self...
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 ...
#C.23
C#
if (condition) { // Some Task }   if (condition) { // Some Task } else if (condition2) { // Some Task } else { // Some Task }
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...
#Julia
Julia
allequal(arr::AbstractArray) = isempty(arr) || all(x -> x == first(arr), arr)   test = [["RC", "RC", "RC"], ["RC", "RC", "Rc"], ["RA", "RB", "RC"], ["RC"], String[], ones(Int64, 4), 1:4]   for v in test println("\n# Testing $v:") println("The elements are $("not " ^ !allequal(v))all equal.") println(...
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...
#Klong
Klong
  {:[2>#x;1;&/=:'x]}:(["test" "test" "test"]) 1 {:[2>#x;1;&/<:'x]}:(["bar" "baz" "foo"]) 1  
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...
#D
D
import std.stdio, std.string;   string quibbler(in string[] seq) pure /*nothrow*/ { if (seq.length <= 1) return format("{%-(%s, %)}", seq); else return format("{%-(%s, %) and %s}", seq[0 .. $-1], seq[$-1]); }   void main() { //foreach (immutable test; [[], foreach (const test; [[], ...
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...
#GAP
GAP
# Built-in UnorderedTuples(["iced", "jam", "plain"], 2);
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...
#Go
Go
package main   import "fmt"   func combrep(n int, lst []string) [][]string { if n == 0 { return [][]string{nil} } if len(lst) == 0 { return nil } r := combrep(n, lst[1:]) for _, x := range combrep(n-1, lst) { r = append(r, append(x, lst[0])) } return r }   func ma...
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...
#Nim
Nim
import bigints   proc perm(n, k: int32): BigInt = result = initBigInt 1 var k = n - k n = n while n > k: result *= n dec n   proc comb(n, k: int32): BigInt = result = perm(n, k) var k = k while k > 0: result = result div k dec k   echo "P(1000, 969) = ", perm(1000, 969) echo "C(1000,...
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...
#PARI.2FGP
PARI/GP
sample(f,a,b)=for(i=1,4, my(n1=random(b-a)+a,n2=random(b-a)+a); [n1,n2]=[max(n1,n2),min(n1,n2)]; print(n1", "n2": "f(n1,n2))) permExact(m,n)=factorback([m-n+1..m]); combExact=binomial; permApprox(m,n)=exp(lngamma(m+1)-lngamma(m-n+1)); combApprox(m,n)=exp(lngamma(m+1)-lngamma(n+1)-lngamma(m-n+1));   sample(permExact, 1,...
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...
#Haskell
Haskell
import Control.Applicative hiding (many, some) import Control.Monad.State.Lazy import Control.Monad.Trans.Maybe (MaybeT, runMaybeT) import Data.Char (isAsciiLower, isAsciiUpper, isDigit, ord) import Data.Foldable (asum) import Data.Functor (($>)) import Data.Text (Text) import qualified Data.Text as T import Prelude hi...
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"
#Factor
Factor
USING: io sequences command-line ; (command-line) [ print ] each
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"
#Fancy
Fancy
ARGV each: |a| { a println # print each given command line argument }
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"
#Fantom
Fantom
  class Main { public static Void main (Str[] args) { echo ("command-line args are: " + args) } }  
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.)
#Brlcad
Brlcad
  # Comments in mget scripts are prefixed with a hash symbol ls # comments may appear at the end of a line  
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.)
#Burlesque
Burlesque
  "I'm sort of a comment"vv  
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...
#zkl
zkl
// This is a little endian machine const WORD_SIZE=4; const{ var _n=-1; var[proxy]N=fcn{ _n+=1 } } // enumerator const FETCH=N, STORE=N, PUSH=N, ADD=N, SUB=N, MUL=N, DIV=N, MOD=N, LT=N, GT=N, LE=N, GE=N, EQ=N, NE=N, AND=N, OR=N, NEG=N, NOT=N, JMP=N, JZ=N, PRTC=N, PRTS=N, PRTI=N, HALT=N;   var [const] bops=D...
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...
#Fortran
Fortran
PROGRAM LIFE_2D IMPLICIT NONE   INTEGER, PARAMETER :: gridsize = 10 LOGICAL :: cells(0:gridsize+1,0:gridsize+1) = .FALSE. INTEGER :: i, j, generation=0 REAL :: rnums(gridsize,gridsize)   ! Start patterns ! ************** ! cells(2,1:3) = .TRUE.  ! Bl...
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 ...
#C.2B.2B
C++
template<bool Condition, typename ThenType, typename Elsetype> struct ifthenelse;   template<typename ThenType, typename ElseType> struct ifthenelse<true, ThenType, ElseType> { typedef ThenType type; };   template<typename ThenType, typename ElseType> struct ifthenelse<false, ThenType, ElseType> { typedef ElseType ...
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...
#Kotlin
Kotlin
// version 1.0.6   fun areEqual(strings: Array<String>): Boolean { if (strings.size < 2) return true return (1 until strings.size).all { strings[it] == strings[it - 1] } }   fun areAscending(strings: Array<String>): Boolean { if (strings.size < 2) return true return (1 until strings.size).all { 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...
#Lambdatalk
Lambdatalk
  {def allsame {def allsame.r {lambda {:s :n :i} {if {= :i :n} then true else {if {not {W.equal? {A.get :i :s} {A.get 0 :s}}} then false else {allsame.r :s :n {+ :i 1}} }}}} {lambda {:s} {allsame.r :s {- {A.length :s} 1} 0} }} -> allsame   {def strict_order {def strict_order.r {lambda {:s :n...
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...
#DCL
DCL
$ list = "[]" $ gosub comma_quibbling $ write sys$output return_string $ $ list = "[""ABC""]" $ gosub comma_quibbling $ write sys$output return_string $ $ list = "[""ABC"", ""DEF""]" $ gosub comma_quibbling $ write sys$output return_string $ $ list = "[""ABC"", ""DEF"", ""G"", ""H""]" $ gosub comma_quibbling $ write sy...
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...
#Haskell
Haskell
-- Return the combinations, with replacement, of k items from the -- list. We ignore the case where k is greater than the length of -- the list. combsWithRep :: Int -> [a] -> [[a]] combsWithRep 0 _ = [[]] combsWithRep _ [] = [] combsWithRep k xxs@(x:xs) = (x :) <$> combsWithRep (k - 1) xxs ++ combsWithRep k xs   bi...
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...
#Perl
Perl
use strict; use warnings;   showoff( "Permutations", \&P, "P", 1 .. 12 ); showoff( "Combinations", \&C, "C", map $_*10, 1..6 ); showoff( "Permutations", \&P_big, "P", 5, 50, 500, 1000, 5000, 15000 ); showoff( "Combinations", \&C_big, "C", map $_*100, 1..10 );   sub showoff { my ($text, $code, $fname, @n) = @_; print ...
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...
#Icon
Icon
# # The Rosetta Code lexical analyzer in Icon with co-expressions. Based # upon the ATS implementation. # # Usage: lex [INPUTFILE [OUTPUTFILE]] # If INPUTFILE or OUTPUTFILE is "-" or missing, then standard input # or standard output is used, respectively. *) #   $define EOF -1   $define TOKEN_ELSE 0 $defin...
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"
#Forth
Forth
\ args.f: print each command line argument on a separate line : main argc @ 0 do i arg type cr loop ;   main bye
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"
#Fortran
Fortran
program command_line_arguments   implicit none integer, parameter :: len_max = 256 integer :: i , nargs character (len_max) :: arg   nargs = command_argument_count() !nargs = iargc() do i = 0, nargs call get_command_argument (i, arg) !call getarg (i, arg) write (*, '(a)') trim (arg) end do  ...
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.)
#C
C
/* This is a comment. */ /* So is this multiline 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.)
#C.23
C#
//This is a comment. //This is other comment.   /* This is a comment too. */   /* This is a multi-line comment */
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...
#Frink
Frink
  start = now[] // Generate a random 10x10 grid with "1" being on and "0" being off instructions = ["1000100110","0001100010","1000111101","1001111110","0000110011","1111000001","0100001110","1011101001","1001011000","1101110111"]   // Create dictionary of starting positions. rowCounter = 0 display = new dict for instr...
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 ...
#Clean
Clean
bool2int b = if b 1 0
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...
#Lua
Lua
function identical(t_str) _, fst = next(t_str) if fst then for _, i in pairs(t_str) do if i ~= fst then return false end end end return true end   function ascending(t_str) prev = false for _, i in ipairs(t_str) do if prev and prev >= i then return false end ...
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...
#Delphi
Delphi
comma-quibble lst: "}" ) if lst: pop-from lst if lst: " and " pop-from lst for item in lst: item ", " concat( "{"   !. comma-quibble [] !. comma-quibble [ "ABC" ] !. comma-quibble [ "ABC" "DEF" ] !. comma-quibble [ "ABC" "DEF" "G" "H" ]
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...
#D.C3.A9j.C3.A0_Vu
Déjà Vu
comma-quibble lst: "}" ) if lst: pop-from lst if lst: " and " pop-from lst for item in lst: item ", " concat( "{"   !. comma-quibble [] !. comma-quibble [ "ABC" ] !. comma-quibble [ "ABC" "DEF" ] !. comma-quibble [ "ABC" "DEF" "G" "H" ]
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...
#Icon_and_Unicon
Icon and Unicon
  # generate all combinations of length n from list L, # including repetitions procedure combinations_repetitions (L, n) if n = 0 then suspend [] # if reach 0, then return an empty list else if *L > 0 then { # keep the first element item := L[1] ...