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/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#langur
langur
val .sieve = f(.limit) { if .limit < 2 { return [] }   var .composite = arr .limit, false .composite[1] = true   for .n in 2 to truncate(.limit ^/ 2) + 1 { if not .composite[.n] { for .k = .n^2; .k < .limit; .k += .n { .composite[.k] = true } ...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#COBOL
COBOL
;; *bug* shall have a dynamic binding. (declaim (special *bug*))   (let ((shape "triangle") (*bug* "ant")) (flet ((speak () (format t "~% There is some ~A in my ~A!" *bug* shape))) (format t "~%Put ~A in your ~A..." *bug* shape) (speak)   (let ((shape "circle") (*bug* "cockroach")) (form...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Common_Lisp
Common Lisp
;; *bug* shall have a dynamic binding. (declaim (special *bug*))   (let ((shape "triangle") (*bug* "ant")) (flet ((speak () (format t "~% There is some ~A in my ~A!" *bug* shape))) (format t "~%Put ~A in your ~A..." *bug* shape) (speak)   (let ((shape "circle") (*bug* "cockroach")) (form...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Icon_and_Unicon
Icon and Unicon
procedure main() write("Creating: ",fName := !open("mktemp","rp")) write(f := open(fName,"w"),"Hello, world") close(f) end
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Java
Java
import java.io.File; import java.io.IOException;   public class CreateTempFile { public static void main(String[] args) { try { //create a temp file File temp = File.createTempFile("temp-file-name", ".tmp"); System.out.println("Temp file : " + temp.getAbsolutePath()); ...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Liberty_BASIC
Liberty BASIC
'Notice that arrays are globally visible to functions. 'The sieve() function uses the flags() array. 'This is a Sieve benchmark adapted from BYTE 1985 ' May, page 286   size = 7000 dim flags(7001) start = time$("ms") print sieve(size); " primes found." print "End of iteration. Elaps...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Delphi
Delphi
private
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#D.C3.A9j.C3.A0_Vu
Déjà Vu
set :a "global" if true:  !print a local :a "local"  !print a  !print getglobal :a !print a  
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#E
E
feature some_procedure(int: INTEGER; char: CHARACTER) local r: REAL i: INTEGER do -- r, i and s have scope here -- as well as int and char -- some_procedure and some_function additionally have scope here end   s: STRING   some_function(int: INTEGER): INTEGER do -- s and Result have scope...
http://rosettacode.org/wiki/Sailors,_coconuts_and_a_monkey_problem
Sailors, coconuts and a monkey problem
Five sailors are shipwrecked on an island and collect a large pile of coconuts during the day. That night the first sailor wakes up and decides to take his first share early so tries to divide the pile of coconuts equally into five piles but finds that there is one coconut left over, so he tosses it to a monkey and th...
#11l
11l
F monkey_coconuts(sailors = 5) V nuts = sailors L V n0 = nuts [(Int, Int, Int)] wakes L(sailor) 0..sailors V (portion, remainder) = divmod(n0, sailors) wakes.append((n0, portion, remainder)) I portion <= 0 | remainder != (I sailor != sailors {1} E 0) nuts++...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Julia
Julia
  msg = "Rosetta Code, Secure temporary file, implemented with Julia."   (fname, tio) = mktemp() println(fname, " created as a temporary file.") println(tio, msg) close(tio) println("\"", msg, "\" written to ", fname)  
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Kotlin
Kotlin
// version 1.1.2   import java.io.File   fun main(args: Array<String>) { try { val tf = File.createTempFile("temp", ".tmp") println(tf.absolutePath) tf.delete() } catch (ex: Exception) { println(ex.message) } }
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Lua
Lua
fp = io.tmpfile()   -- do some file operations   fp:close()
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Limbo
Limbo
implement Sieve;   include "sys.m"; sys: Sys; print: import sys; include "draw.m"; draw: Draw;   Sieve : module { init : fn(ctxt : ref Draw->Context, args : list of string); };   init (ctxt: ref Draw->Context, args: list of string) { sys = load Sys Sys->PATH;   limit := 201; sieve : array of int; sieve = array ...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Eiffel
Eiffel
feature some_procedure(int: INTEGER; char: CHARACTER) local r: REAL i: INTEGER do -- r, i and s have scope here -- as well as int and char -- some_procedure and some_function additionally have scope here end   s: STRING   some_function(int: INTEGER): INTEGER do -- s and Result have scope...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Ela
Ela
pi # private pi = 3.14159   sum # private sum x y = x + y
http://rosettacode.org/wiki/Sailors,_coconuts_and_a_monkey_problem
Sailors, coconuts and a monkey problem
Five sailors are shipwrecked on an island and collect a large pile of coconuts during the day. That night the first sailor wakes up and decides to take his first share early so tries to divide the pile of coconuts equally into five piles but finds that there is one coconut left over, so he tosses it to a monkey and th...
#AutoHotkey
AutoHotkey
loop, 2 { sailor := A_Index+4 while !result := Coco(sailor, A_Index) continue ; format output remain := result["Coconuts"] output := sailor " Sailors, Number of coconuts = " result["Coconuts"] "`n" loop % sailor { x := result["Sailor_" A_Index] output .= "Monkey gets 1, Sailor# " A_Index " hides (" remain ...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#M2000_Interpreter
M2000 Interpreter
  Module Checkit { \\ we get a tempname$ choosed from Windows a$=tempname$ Try ok { \\ we can use wide to export in utf-16le \\ without wide we export as Ansi (set Local to desired language) Rem Locale 1033 ' when no use of wide Open a$ for wide output...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
tmp = OpenWrite[] Close[tmp]
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Nanoquery
Nanoquery
import Nanoquery.IO   def guaranteedTempFile() // create a file object to generate temp file names $namegen = new(File)   // generate a temp filename $tempname = $namegen.tempFileName()   // file names are generated with uuids so they shouldn't repeat // in the case that they do, generate new ones until the gener...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols binary   runSample(arg) return   -- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . method makeTempFile(prefix = String, suffix = String null, startDir = String null) - public static signals IOException returns File if...
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#6502_Assembly
6502 Assembly
IF PROC x = ...; ... THEN # can call x here # PROC y = ...; ... GO TO l1 # invalid!! # ELSE # can call x here, but not y # ... l1: ... FI
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Lingo
Lingo
-- parent script "sieve" property _sieve   ---------------------------------------- -- @constructor ---------------------------------------- on new (me) me._sieve = [] return me end   ---------------------------------------- -- Returns list of primes <= n ---------------------------------------- on getPrimes (m...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Erlang
Erlang
  -module( a_module ).   -export( [double/1] ).   double( N ) -> add( N, N ).       add( N, N ) -> N + N.  
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#FreeBASIC
FreeBASIC
'Declares a integer variable and reserves memory to accommodate it Dim As Integer baseAge = 10 'Define a variable that has static storage Static As String person person = "Amy" 'Declare variables that are both accessible inside and outside procedures Dim Shared As String friend friend = "Susan" Dim Shared As Integer ag...
http://rosettacode.org/wiki/Sailors,_coconuts_and_a_monkey_problem
Sailors, coconuts and a monkey problem
Five sailors are shipwrecked on an island and collect a large pile of coconuts during the day. That night the first sailor wakes up and decides to take his first share early so tries to divide the pile of coconuts equally into five piles but finds that there is one coconut left over, so he tosses it to a monkey and th...
#AWK
AWK
  # syntax: GAWK -f SAILORS_COCONUTS_AND_A_MONKEY_PROBLEM.AWK # converted from LUA BEGIN { for (n=2; n<=9; n++) { x = 0 while (!valid(n,x)) { x++ } printf("%d %d\n",n,x) } exit(0) } function valid(n,nuts, k) { k = n while (k != 0) { if ((nuts % n) != 1) { ...
http://rosettacode.org/wiki/Sailors,_coconuts_and_a_monkey_problem
Sailors, coconuts and a monkey problem
Five sailors are shipwrecked on an island and collect a large pile of coconuts during the day. That night the first sailor wakes up and decides to take his first share early so tries to divide the pile of coconuts equally into five piles but finds that there is one coconut left over, so he tosses it to a monkey and th...
#Bc
Bc
define coconuts(sailors, monkeys) { print "coconuts(", sailors, ", ", monkeys, ") = " if (sailors < 2 || monkeys < 1 || sailors <= monkeys) { return 0 } blue_cocos = sailors-1 pow_bc = blue_cocos^sailors x_cocos = pow_bc while ((x_cocos-blue_cocos)%sailors || (x_cocos-blue_cocos)/sailors < 1) { x_cocos += po...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Nim
Nim
import std/[os, tempfiles]   let (file, path) = createTempFile(prefix = "", suffix = "") echo path, " created." file.writeLine("This is a secure temporary file.") file.close() for line in path.lines: echo line removeFile(path)
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#OCaml
OCaml
# Filename.temp_file "prefix." ".suffix" ;; - : string = "/home/blue_prawn/tmp/prefix.301f82.suffix"
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Octave
Octave
[FID, MSG] = tmpfile(); % Return the file ID corresponding to a new temporary filename = tmpnam (...); % generates temporary file name, but does not open file [FID, NAME, MSG] = mkstemp (TEMPLATE, DELETE); % Return the file ID corresponding to a new temporary file with a unique name created from TEMPLATE...
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#ALGOL_68
ALGOL 68
IF PROC x = ...; ... THEN # can call x here # PROC y = ...; ... GO TO l1 # invalid!! # ELSE # can call x here, but not y # ... l1: ... FI
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#ALGOL_W
ALGOL W
# This program outputs a greeting BEGIN { sayhello() # Call the function defined below exit }   function sayhello { print "Hello World!" # Outputs a message to the terminal }
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#AWK
AWK
# This program outputs a greeting BEGIN { sayhello() # Call the function defined below exit }   function sayhello { print "Hello World!" # Outputs a message to the terminal }
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#Axe
Axe
GOTO 50: REM THIS WILL WORK IMMEDIATELY
http://rosettacode.org/wiki/Search_a_list_of_records
Search a list of records
Many programming languages provide convenient ways to look for a known value in a simple list of strings or numbers. But what if the elements of the list are themselves compound records/objects/data-structures, and the search condition is more complex than a simple equality test? Task[edit] Write a function/method/et...
#11l
11l
T City String name Float population   F (name, population) .name = name .population = population   V cities = [ City(‘Lagos’, 21), City(‘Cairo’, 15.2), City(‘Kinshasa-Brazzaville’, 11.3), City(‘Greater Johannesburg’, 7.55), City(‘Mogadishu’, 5.85), Ci...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#LiveCode
LiveCode
function sieveE int set itemdel to comma local sieve repeat with i = 2 to int put i into sieve[i] end repeat put 2 into n repeat while n < int repeat with p = n to int step n if p = n then next repeat else put empty into si...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Free_Pascal
Free Pascal
global var1 # used outside of procedures   procedure one() # a global procedure (the only kind) local var2 # used inside of procedures static var3 # also used inside of procedures end
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Go
Go
global var1 # used outside of procedures   procedure one() # a global procedure (the only kind) local var2 # used inside of procedures static var3 # also used inside of procedures end
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Haskell
Haskell
global var1 # used outside of procedures   procedure one() # a global procedure (the only kind) local var2 # used inside of procedures static var3 # also used inside of procedures end
http://rosettacode.org/wiki/Sailors,_coconuts_and_a_monkey_problem
Sailors, coconuts and a monkey problem
Five sailors are shipwrecked on an island and collect a large pile of coconuts during the day. That night the first sailor wakes up and decides to take his first share early so tries to divide the pile of coconuts equally into five piles but finds that there is one coconut left over, so he tosses it to a monkey and th...
#Befunge
Befunge
>2+:01p9>`#@_00v nvg10*g10:+>#1$< #>\:01g1-%#^_:0v -|:-1\+1<+/-1g1< 1>$01g.">-",,48v ^g10,+55<.,9.,*<
http://rosettacode.org/wiki/Sailors,_coconuts_and_a_monkey_problem
Sailors, coconuts and a monkey problem
Five sailors are shipwrecked on an island and collect a large pile of coconuts during the day. That night the first sailor wakes up and decides to take his first share early so tries to divide the pile of coconuts equally into five piles but finds that there is one coconut left over, so he tosses it to a monkey and th...
#Bracmat
Bracmat
( ( divmod = a b . !arg:(?a.?b)&(div$(!a.!b).mod$(!a.!b)) ) & ( overnight = ns nn result s q r .  !arg:(?ns.?nn) & :?result & 0:?s & whl ' ( !s+1:?s:~>!ns & divmod$(!nn.!ns):(?q.?r) & !r:1 & !q*(!ns+-1):?nn & !result (!s.!q.!r.!nn):?...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Pascal
Pascal
Program TempFileDemo;   uses SysUtils;   var tempFile: text;   begin assign (Tempfile, GetTempFileName); rewrite (tempFile); writeln (tempFile, 5); close (tempFile); end.
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Perl
Perl
use File::Temp qw(tempfile); $fh = tempfile(); ($fh2, $filename) = tempfile(); # this file stays around by default print "$filename\n"; close $fh; close $fh2;
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Phix
Phix
without js -- (file i/o) pp(temp_file()) {integer fn, string name} = temp_file("myapp/tmp","data","log","wb") pp({fn,name}) close(fn) {} = delete_file(name)
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#BASIC
BASIC
GOTO 50: REM THIS WILL WORK IMMEDIATELY
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#bc
bc
f(1) /* First output line */ define f(x) { return(x) } f(3) /* Second output line */   define f(x) { return(x - 1) } f(3) /* Third output line */
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#C
C
  #include <stdio.h>   #define sqr(x) ((x) * (x)) #define greet printf("Hello There!\n")   int twice(int x) { return 2 * x; }   int main(void) { int x;   printf("This will demonstrate function and label scopes.\n"); printf("All output is happening through printf(), a function declared in the header stdio.h, which i...
http://rosettacode.org/wiki/Search_a_list_of_records
Search a list of records
Many programming languages provide convenient ways to look for a known value in a simple list of strings or numbers. But what if the elements of the list are themselves compound records/objects/data-structures, and the search condition is more complex than a simple equality test? Task[edit] Write a function/method/et...
#8086_Assembly
8086 Assembly
.model small .stack 1024   .data Africa WORD LAGOS ;"jagged" arrays are the bane of assembly programming, so store the string's pointer here instead. WORD 2100H ;this is a bit cheaty but it's easier to store these as BCD whole numbers WORD CAIRO WORD 1520H WORD KB WORD 1130H WORD GJ ...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Logo
Logo
to sieve :limit make "a (array :limit 2)  ; initialized to empty lists make "p [] for [i 2 :limit] [ if empty? item :i :a [ queue "p :i for [j [:i * :i] :limit :i] [setitem :j :a :i] ] ] output :p end print sieve 100  ; 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 8...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Icon_and_Unicon
Icon and Unicon
global var1 # used outside of procedures   procedure one() # a global procedure (the only kind) local var2 # used inside of procedures static var3 # also used inside of procedures end
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#J
J
A=: 1 B=: 2 C=: 3 F=: verb define A=:4 B=.5 D=.6 A+B+C+D ) F '' 18 A 4 B 2 D |value error
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Java
Java
public //any class may access this member directly   protected //only this class, subclasses of this class, //and classes in the same package may access this member directly   private //only this class may access this member directly   static //for use with other modifiers //limits this member to one reference for the ...
http://rosettacode.org/wiki/Sailors,_coconuts_and_a_monkey_problem
Sailors, coconuts and a monkey problem
Five sailors are shipwrecked on an island and collect a large pile of coconuts during the day. That night the first sailor wakes up and decides to take his first share early so tries to divide the pile of coconuts equally into five piles but finds that there is one coconut left over, so he tosses it to a monkey and th...
#C
C
#include <stdio.h>   int valid(int n, int nuts) { int k; for (k = n; k; k--, nuts -= 1 + nuts/n) if (nuts%n != 1) return 0; return nuts && !(nuts%n); }   int main(void) { int n, x; for (n = 2; n < 10; n++) { for (x = 0; !valid(n, x); x++); printf("%d: %d\n", n, x); } return 0; }
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#PHP
PHP
$fh = tmpfile(); // do stuff with $fh fclose($fh); // file removed when closed   // or: $filename = tempnam('/tmp', 'prefix'); echo "$filename\n"; // open $filename and do stuff with it
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#PicoLisp
PicoLisp
: (out (tmp "foo") (println 123)) # Write tempfile -> 123   : (in (tmp "foo") (read)) # Read tempfile -> 123   : (let F (tmp "foo") (ctl F # Get exclusive lock (in F (let N (read) # Atomic increment (out F (println...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#PowerShell
PowerShell
  $tempFile = [System.IO.Path]::GetTempFileName() Set-Content -Path $tempFile -Value "FileName = $tempFile" Get-Content -Path $tempFile Remove-Item -Path $tempFile  
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#Eiffel
Eiffel
--assume A, B and C to be valid classes class X feature -- alias for "feature {ANY}" -- ANY is the class at the top of the class hierarchy and all classes inherit from it -- features following this clause are given "global" scope: these features are visible to every class   feature {A, B, C, X} -- features following th...
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#Erlang
Erlang
  -module( a_module ).   -export( [exported_function/0] ).   exported_function() -> 1 + local_function().   local_function() -> 2.  
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#Factor
Factor
USE: math 2 2 +
http://rosettacode.org/wiki/Search_a_list_of_records
Search a list of records
Many programming languages provide convenient ways to look for a known value in a simple list of strings or numbers. But what if the elements of the list are themselves compound records/objects/data-structures, and the search condition is more complex than a simple equality test? Task[edit] Write a function/method/et...
#8th
8th
[ { "name": "Lagos", "population": 21.0 }, { "name": "Cairo", "population": 15.2 }, { "name": "Kinshasa-Brazzaville", "population": 11.3 }, { "name": "Greater Johannesburg", "population": 7.55 }, { "name": "Mogadishu", "population": 5.85 }, { "name": "Khartoum-O...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Logtalk
Logtalk
due to the use of mod (modulo = division) in the filter function.
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#JavaScript
JavaScript
  julia> function foo(n) x = 0 for i = 1:n local x # introduce a loop-local x x = i end x end foo (generic function with 1 method)   julia> foo(10) 0  
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Julia
Julia
  julia> function foo(n) x = 0 for i = 1:n local x # introduce a loop-local x x = i end x end foo (generic function with 1 method)   julia> foo(10) 0  
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Kotlin
Kotlin
// version 1.1.2   class SomeClass { val id: Int   companion object { private var lastId = 0 val objectsCreated get() = lastId }   init { id = ++lastId } }   fun main(args: Array<String>) { val sc1 = SomeClass() val sc2 = SomeClass() println(sc1.id) println(...
http://rosettacode.org/wiki/Sailors,_coconuts_and_a_monkey_problem
Sailors, coconuts and a monkey problem
Five sailors are shipwrecked on an island and collect a large pile of coconuts during the day. That night the first sailor wakes up and decides to take his first share early so tries to divide the pile of coconuts equally into five piles but finds that there is one coconut left over, so he tosses it to a monkey and th...
#C.23
C#
class Test { static bool valid(int n, int nuts) { for (int k = n; k != 0; k--, nuts -= 1 + nuts / n) { if (nuts % n != 1) { return false; } }   return nuts != 0 && (nuts % n == 0); }   static void Main(st...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#PureBasic
PureBasic
Procedure.s TempFile() Protected a, Result$   For a = 0 To 9999 Result$ = GetTemporaryDirectory() + StringField(GetFilePart(ProgramFilename()),1,".") Result$ + "_" + Str(ElapsedMilliseconds()) + "_(" + RSet(Str(a),4,"0") + ").tmp" If FileSize(Result$) = -1 ; -1 = Fi...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Python
Python
>>> import tempfile >>> invisible = tempfile.TemporaryFile() >>> invisible.name '<fdopen>' >>> visible = tempfile.NamedTemporaryFile() >>> visible.name '/tmp/tmpZNfc_s' >>> visible.close() >>> invisible.close()
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#FreeBASIC
FreeBASIC
package main   import ( "fmt" "runtime"   "ex" )   func main() { // func nested() { ... not allowed here   // this is okay, variable f declared and assigned a function literal. f := func() { // this mess prints the name of the function to show that it's an // anonymous function d...
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#Go
Go
package main   import ( "fmt" "runtime"   "ex" )   func main() { // func nested() { ... not allowed here   // this is okay, variable f declared and assigned a function literal. f := func() { // this mess prints the name of the function to show that it's an // anonymous function d...
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#haskell
haskell
  add3 :: Int -> Int-> Int-> Int add3 x y z = add2 x y + z   add2 :: Int -> Int -> Int add2 x y = x + y   main :: putStrLn(show (add3 5 6 5))  
http://rosettacode.org/wiki/Search_a_list_of_records
Search a list of records
Many programming languages provide convenient ways to look for a known value in a simple list of strings or numbers. But what if the elements of the list are themselves compound records/objects/data-structures, and the search condition is more complex than a simple equality test? Task[edit] Write a function/method/et...
#Action.21
Action!
INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit   DEFINE PTR="CARD" DEFINE ENTRY_SIZE="4" DEFINE STX="$8E" DEFINE STA="$8D" DEFINE JSR="$20" DEFINE RTS="$60"   TYPE City=[ CARD name, ;CHAR ARRAY population] ;REAL POINTER   BYTE ARRAY cities(100) BYTE count=[0]   CHAR ARRAY nameParam ;param for name predicate...
http://rosettacode.org/wiki/Search_a_list_of_records
Search a list of records
Many programming languages provide convenient ways to look for a known value in a simple list of strings or numbers. But what if the elements of the list are themselves compound records/objects/data-structures, and the search condition is more complex than a simple equality test? Task[edit] Write a function/method/et...
#Ada
Ada
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Text_IO;   procedure Search_A_List_Of_Records is function "+"(input : in String) return Unbounded_String renames To_Unbounded_String; function "+"(input : in Unbounded_String) return String renames To_String;   type City is record name : Unb...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#LOLCODE
LOLCODE
HAI 1.2 CAN HAS STDIO?   HOW IZ I Eratosumthin YR Max I HAS A Siv ITZ A BUKKIT Siv HAS A SRS 1 ITZ 0 I HAS A Index ITZ 2 IM IN YR Inishul UPPIN YR Dummy WILE DIFFRINT Index AN SUM OF Max AN 1 Siv HAS A SRS Index ITZ 1 Index R SUM OF Index AN 1 IM OUTTA YR Inishul   I HAS A Prime ITZ 2 IM IN YR Mai...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Liberty_BASIC
Liberty BASIC
  make "g 5  ; global   to proc :p make "h 4  ; also global local "l  ; local, no initial value localmake "m 3   sub 7 end   to sub :s  ; can see :g, :h, and :s  ; if called from proc, can also see :l and :m localmake "h 5  ; hides global :h within this procedure and those it calls end  
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Logo
Logo
  make "g 5  ; global   to proc :p make "h 4  ; also global local "l  ; local, no initial value localmake "m 3   sub 7 end   to sub :s  ; can see :g, :h, and :s  ; if called from proc, can also see :l and :m localmake "h 5  ; hides global :h within this procedure and those it calls end  
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Logtalk
Logtalk
  :- public(foo/1). % predicate can be called from anywhere   :- protected(bar/2). % predicate can be called from the declaring entity and its descendants   :- private(baz/3). % predicate can only be called from the declaring entity   :- object(object, % predicates declared in the protocol become private fo...
http://rosettacode.org/wiki/Sailors,_coconuts_and_a_monkey_problem
Sailors, coconuts and a monkey problem
Five sailors are shipwrecked on an island and collect a large pile of coconuts during the day. That night the first sailor wakes up and decides to take his first share early so tries to divide the pile of coconuts equally into five piles but finds that there is one coconut left over, so he tosses it to a monkey and th...
#C.2B.2B
C++
#include <iostream>   bool valid(int n, int nuts) { for (int k = n; k != 0; k--, nuts -= 1 + nuts / n) { if (nuts % n != 1) { return false; } }   return nuts != 0 && (nuts % n == 0); }   int main() { int x = 0; for (int n = 2; n < 10; n++) { while (!valid(n, x)) {...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Racket
Racket
  #lang racket (make-temporary-file)  
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Raku
Raku
use File::Temp;   # Generate a temp file in a temp dir my ($filename0,$filehandle0) = tempfile;   # specify a template for the filename # * are replaced with random characters my ($filename1,$filehandle1) = tempfile("******");   # Automatically unlink files at DESTROY (this is the default) my ($filename2,$filehandle2)...
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#Icon_and_Unicon
Icon and Unicon
a=. 1
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#J
J
a=. 1
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#jq
jq
def NAME: def NAME: 2; 1, NAME; # this calls the inner function, not the outer function   NAME # => 1, 2
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#Julia
Julia
Type of scope | block/construct introducing this kind of scope ---------------------------------------------------------------- Global Scope | module, baremodule, at interactive prompt (REPL) Local Scope | Soft Local Scope: for, while, comprehensions, try-catch-finally, let Local Scope | Hard Local Scope: functi...
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#Kotlin
Kotlin
// version 1.1.2   // top level function visible anywhere within the current module internal fun a() = println("calling a")   object B { // object level function visible everywhere, by default fun f() = println("calling f") }   open class C { // class level function visible everywhere, by default fun g(...
http://rosettacode.org/wiki/Search_a_list_of_records
Search a list of records
Many programming languages provide convenient ways to look for a known value in a simple list of strings or numbers. But what if the elements of the list are themselves compound records/objects/data-structures, and the search condition is more complex than a simple equality test? Task[edit] Write a function/method/et...
#ALGOL_68
ALGOL 68
# Algol 68 doesn't have generic array searches but we can easily provide # # type specific ones #   # mode to hold the city/population info # MODE CITYINFO = STRUCT( STRING name, REAL population in millions );   # array of cities and populations # [ 1 : 10 ]CITYINFO c...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Lua
Lua
function erato(n) if n < 2 then return {} end local t = {0} -- clears '1' local sqrtlmt = math.sqrt(n) for i = 2, n do t[i] = 1 end for i = 2, sqrtlmt do if t[i] ~= 0 then for j = i*i, n, i do t[j] = 0 end end end local primes = {} for i = 2, n do if t[i] ~= 0 then table.insert(primes, i) end end return...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Lua
Lua
foo = "global" -- global scope print(foo) local foo = "local module" -- local to the current block (which is the module) print(foo) -- local obscures the global print(_G.foo) -- but global still exists do -- create a new block print(foo) -- outer module-level scope still visible local foo = "local block" -- local t...
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#M2000_Interpreter
M2000 Interpreter
  Module Checkit { M=1000 Function Global xz { =9999 } Module TopModule { \\ clear vars and static vars Clear M=500 Function Global xz { =10000 } Module Kappa { Static N=1 ...
http://rosettacode.org/wiki/Sailors,_coconuts_and_a_monkey_problem
Sailors, coconuts and a monkey problem
Five sailors are shipwrecked on an island and collect a large pile of coconuts during the day. That night the first sailor wakes up and decides to take his first share early so tries to divide the pile of coconuts equally into five piles but finds that there is one coconut left over, so he tosses it to a monkey and th...
#Clojure
Clojure
(defn solves-for? [sailors initial-coconut-count] (with-local-vars [coconuts initial-coconut-count, hidings 0] (while (and (> @coconuts sailors) (= (mod @coconuts sailors) 1) (var-set coconuts (/ (* (dec @coconuts) (dec sailors)) sailors)) (var-set hidings (inc @hidings))) (and (zero? (mod @coconu...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#REXX
REXX
/*REXX pgm secures (a temporary file), writes to it, displays the file, then deletes it.*/ parse arg tFID # . /*obtain optional argument from the CL.*/ if tFID=='' | tFID=="," then tFID= 'TEMP.FILE' /*Not specified? Then use the default.*/ if #=='' | #=="," then #= 6 ...
http://rosettacode.org/wiki/Secure_temporary_file
Secure temporary file
Task Create a temporary file, securely and exclusively (opening it such that there are no possible race conditions). It's fine assuming local filesystem semantics (NFS or other networking filesystems can have signficantly more complicated semantics for satisfying the "no race conditions" criteria). The function shou...
#Ruby
Ruby
irb(main):001:0> require 'tempfile' => true irb(main):002:0> f = Tempfile.new('foo') => #<File:/tmp/foo20081226-307-10p746n-0> irb(main):003:0> f.path => "/tmp/foo20081226-307-10p746n-0" irb(main):004:0> f.close => nil irb(main):005:0> f.unlink => #<Tempfile: (closed)>
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#Lua
Lua
function foo() print("global") end -- global scope by default foo() local function foo() print("local module") end -- local to the current block (which is the module) foo() -- local obscures the global _G.foo() -- bug global still exists do -- create a new block foo() -- outer module-level scope still visible local...
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#M2000_Interpreter
M2000 Interpreter
  Function Master { Module Alfa { Gosub 100 Global M=1000 \\ delta print 1000 delta End 100 Print Module(Beta)=False Print Module(Delta)=True Return } Group Object1 { Function Master { =M } Module Final Beta { \\ delta print 500 delta alfa() Sub alfa() Local N=@Kappa(3) Gl...
http://rosettacode.org/wiki/Scope/Function_names_and_labels
Scope/Function names and labels
Task Explain or demonstrate the levels of visibility of function names and labels within the language. See also Variables for levels of scope relating to visibility of program variables Scope modifiers for general scope modification facilities
#Nim
Nim
const C = block useless: 3
http://rosettacode.org/wiki/Search_a_list_of_records
Search a list of records
Many programming languages provide convenient ways to look for a known value in a simple list of strings or numbers. But what if the elements of the list are themselves compound records/objects/data-structures, and the search condition is more complex than a simple equality test? Task[edit] Write a function/method/et...
#AppleScript
AppleScript
-- RECORDS   property lstCities : [¬ {|name|:"Lagos", population:21.0}, ¬ {|name|:"Cairo", population:15.2}, ¬ {|name|:"Kinshasa-Brazzaville", population:11.3}, ¬ {|name|:"Greater Johannesburg", population:7.55}, ¬ {|name|:"Mogadishu", population:5.85}, ¬ {|name|:"Khartoum-Omdurman", population:...
http://rosettacode.org/wiki/Same_fringe
Same fringe
Write a routine that will compare the leaves ("fringe") of two binary trees to determine whether they are the same list of leaves when visited left-to-right. The structure or balance of the trees does not matter; only the number, order, and value of the leaves is important. Any solution is allowed here, but many compu...
#Ada
Ada
generic type Data is private; package Bin_Trees is   type Tree_Type is private;   function Empty(Tree: Tree_Type) return Boolean; function Left (Tree: Tree_Type) return Tree_Type; function Right(Tree: Tree_Type) return Tree_Type; function Item (Tree: Tree_Type) return Data; function Empty return Tr...
http://rosettacode.org/wiki/Sieve_of_Eratosthenes
Sieve of Eratosthenes
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. The Sieve of Eratosthenes is a simple algorithm that finds the prime numbers up to a given integer. Task Implement the   Sieve of Eratosthenes   algorithm, with the only allowed...
#Lucid
Lucid
prime where prime = 2 fby (n whenever isprime(n)); n = 3 fby n+2; isprime(n) = not(divs) asa divs or prime*prime > N where N is current n; divs = N mod prime eq 0; end; end
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
Module -> localize names of variables (lexical scoping) Block -> localize values of variables (dynamic scoping) Module creates new symbols: Module[{x}, Print[x]; Module[{x}, Print[x]] ] ->x$119 ->x$120 Block localizes values only; it does not create new symbols: x = 7; Block[{x=0}, Print[x]] Print[x] ->0 ->7
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#MUMPS
MUMPS
OUTER SET OUT=1,IN=0 WRITE "OUT = ",OUT,! WRITE "IN = ",IN,! DO INNER WRITE:$DATA(OUT)=0 "OUT was destroyed",! QUIT INNER WRITE "OUT (inner scope) = ",OUT,! WRITE "IN (outer scope) = ",IN,! NEW IN SET IN=3.14 WRITE "IN (inner scope) = ",IN,! KILL OUT QUIT
http://rosettacode.org/wiki/Scope_modifiers
Scope modifiers
Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("static scoping" or "lexical scoping"). T...
#Nim
Nim
proc foo = echo "foo" # hidden proc bar* = echo "bar" # acessible   type MyObject = object name*: string # accessible secretAge: int # hidden