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/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would represent a point in the region,   and a vector from the origin to the point. Given the vectors: A = (a1, a2, a3) B = (b1, b2, b3) C = (c1, c2, c3) then the following common vector products are defined: The dot product       (a scalar quantity) A • B = a1b1   +   a2b2   +   a3b3 The cross product       (a vector quantity) A x B = (a2b3  -   a3b2,     a3b1   -   a1b3,     a1b2   -   a2b1) The scalar triple product       (a scalar quantity) A • (B x C) The vector triple product       (a vector quantity) A x (B x C) Task Given the three vectors: a = ( 3, 4, 5) b = ( 4, 3, 5) c = (-5, -12, -13) Create a named function/subroutine/method to compute the dot product of two vectors. Create a function to compute the cross product of two vectors. Optionally create a function to compute the scalar triple product of three vectors. Optionally create a function to compute the vector triple product of three vectors. Compute and display: a • b Compute and display: a x b Compute and display: a • (b x c), the scalar triple product. Compute and display: a x (b x c), the vector triple product. References   A starting page on Wolfram MathWorld is   Vector Multiplication .   Wikipedia   dot product.   Wikipedia   cross product.   Wikipedia   triple product. Related tasks   Dot product   Quaternion type
#OCaml
OCaml
let a = (3.0, 4.0, 5.0) let b = (4.0, 3.0, 5.0) let c = (-5.0, -12.0, -13.0)   let string_of_vector (x,y,z) = Printf.sprintf "(%g, %g, %g)" x y z   let dot (a1, a2, a3) (b1, b2, b3) = (a1 *. b1) +. (a2 *. b2) +. (a3 *. b3)   let cross (a1, a2, a3) (b1, b2, b3) = (a2 *. b3 -. a3 *. b2, a3 *. b1 -. a1 *. b3, a1 *. b2 -. a2 *. b1)   let scalar_triple a b c = dot a (cross b c)   let vector_triple a b c = cross a (cross b c)   let () = Printf.printf "a: %s\n" (string_of_vector a); Printf.printf "b: %s\n" (string_of_vector b); Printf.printf "c: %s\n" (string_of_vector c); Printf.printf "a . b = %g\n" (dot a b); Printf.printf "a x b = %s\n" (string_of_vector (cross a b)); Printf.printf "a . (b x c) = %g\n" (scalar_triple a b c); Printf.printf "a x (b x c) = %s\n" (string_of_vector (vector_triple a b c)); ;;
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#PHP
PHP
#!/usr/bin/php <?php $string = fgets(STDIN); $integer = (int) fgets(STDIN);
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Picat
Picat
main => print("Enter a string: "), String = read_line(), print("Enter a number: "), Number = read_int(), println([string=String,number=Number]).
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#Scala
Scala
$ include "seed7_05.s7i";   var integer: foo is 5; # foo is global   const proc: aFunc is func local var integer: bar is 10; # bar is local to aFunc begin writeln("foo + bar = " <& foo + bar); end func;   const proc: main is func begin aFunc; end func;
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#Seed7
Seed7
$ include "seed7_05.s7i";   var integer: foo is 5; # foo is global   const proc: aFunc is func local var integer: bar is 10; # bar is local to aFunc begin writeln("foo + bar = " <& foo + bar); end func;   const proc: main is func begin aFunc; end func;
http://rosettacode.org/wiki/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would represent a point in the region,   and a vector from the origin to the point. Given the vectors: A = (a1, a2, a3) B = (b1, b2, b3) C = (c1, c2, c3) then the following common vector products are defined: The dot product       (a scalar quantity) A • B = a1b1   +   a2b2   +   a3b3 The cross product       (a vector quantity) A x B = (a2b3  -   a3b2,     a3b1   -   a1b3,     a1b2   -   a2b1) The scalar triple product       (a scalar quantity) A • (B x C) The vector triple product       (a vector quantity) A x (B x C) Task Given the three vectors: a = ( 3, 4, 5) b = ( 4, 3, 5) c = (-5, -12, -13) Create a named function/subroutine/method to compute the dot product of two vectors. Create a function to compute the cross product of two vectors. Optionally create a function to compute the scalar triple product of three vectors. Optionally create a function to compute the vector triple product of three vectors. Compute and display: a • b Compute and display: a x b Compute and display: a • (b x c), the scalar triple product. Compute and display: a x (b x c), the vector triple product. References   A starting page on Wolfram MathWorld is   Vector Multiplication .   Wikipedia   dot product.   Wikipedia   cross product.   Wikipedia   triple product. Related tasks   Dot product   Quaternion type
#Octave
Octave
a = [3, 4, 5]; b = [4, 3, 5]; c = [-5, -12, -13];   function r = s3prod(a, b, c) r = dot(a, cross(b, c)); endfunction   function r = v3prod(a, b, c) r = cross(a, cross(b, c)); endfunction   % 49 dot(a, b) % or matrix-multiplication between row and column vectors a * b'   % 5 5 -7 cross(a, b) % only for 3d-vectors   % 6 s3prod(a, b, c)   % -267 204 -3 v3prod(a, b, c)
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#PicoLisp
PicoLisp
(in NIL # Guarantee reading from standard input (let (Str (read) Num (read)) (prinl "The string is: \"" Str "\"") (prinl "The number is: " Num) ) )
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Pike
Pike
int main(){ write("Enter a String: "); string str = Stdio.stdin->gets(); write("Enter 75000: "); int num = Stdio.stdin->gets(); }
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#Set_lang
Set lang
set a 0 > Useless intialization - All lowercase variables have an initial value of 0 set b 66 > Simple variable assignment - ''b'' is now the ASCII value of 66, or the character 'B' [c=0] set c 5 > Conditional variable assignment - If ''c'' is 0, then set ''c'' to 5 set ? 6 > A "goto" command; Setting the ''?'' variable defines the line of code to be executed next set z 1 > This line of code will never be executed, because the previous skipped it set c 10 > Line #5 skipped to here set d A > Assigning a variable to another variable - ''d'' is now ASCII 65, or the character 'A' set b ! > The ''!'' deals with I/O. Setting a variable to it receives an input character and assigns it to the variable set ! a > Setting the exclamation point to a variable outputs that variable set e (d+1) > Combiners are defined inside round brackets - () - and have an addition and a subtraction function set f (e-1) > Variable ''e'' was assigned to ''d'' + 1 (65 + 1 = 66, character B), and ''f'' was assigned to ''e'' - 1 (66 - 1 = 65, character A)  
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#smart_BASIC
smart BASIC
x = 14 y = 0.4E3 z = 3-2i
http://rosettacode.org/wiki/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would represent a point in the region,   and a vector from the origin to the point. Given the vectors: A = (a1, a2, a3) B = (b1, b2, b3) C = (c1, c2, c3) then the following common vector products are defined: The dot product       (a scalar quantity) A • B = a1b1   +   a2b2   +   a3b3 The cross product       (a vector quantity) A x B = (a2b3  -   a3b2,     a3b1   -   a1b3,     a1b2   -   a2b1) The scalar triple product       (a scalar quantity) A • (B x C) The vector triple product       (a vector quantity) A x (B x C) Task Given the three vectors: a = ( 3, 4, 5) b = ( 4, 3, 5) c = (-5, -12, -13) Create a named function/subroutine/method to compute the dot product of two vectors. Create a function to compute the cross product of two vectors. Optionally create a function to compute the scalar triple product of three vectors. Optionally create a function to compute the vector triple product of three vectors. Compute and display: a • b Compute and display: a x b Compute and display: a • (b x c), the scalar triple product. Compute and display: a x (b x c), the vector triple product. References   A starting page on Wolfram MathWorld is   Vector Multiplication .   Wikipedia   dot product.   Wikipedia   cross product.   Wikipedia   triple product. Related tasks   Dot product   Quaternion type
#ooRexx
ooRexx
  a = .vector~new(3, 4, 5); b = .vector~new(4, 3, 5); c = .vector~new(-5, -12, -13);   say a~dot(b) say a~cross(b) say a~scalarTriple(b, c) say a~vectorTriple(b, c)     ::class vector ::method init expose x y z use arg x, y, z   ::attribute x get ::attribute y get ::attribute z get   -- dot product operation ::method dot expose x y z use strict arg other   return x * other~x + y * other~y + z * other~z   -- cross product operation ::method cross expose x y z use strict arg other   newX = y * other~z - z * other~y newY = z * other~x - x * other~z newZ = x * other~y - y * other~x return self~class~new(newX, newY, newZ)   -- scalar triple product ::method scalarTriple use strict arg vectorB, vectorC return self~dot(vectorB~cross(vectorC))   -- vector triple product ::method vectorTriple use strict arg vectorB, vectorC return self~cross(vectorB~cross(vectorC))   ::method string expose x y z return "<"||x", "y", "z">"  
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#PL.2FI
PL/I
declare s character (100) varying; declare k fixed decimal (15);   put ('please type a string:'); get edit (s) (L); put skip list (s);   put skip list ('please type the integer 75000'); get list (k); put skip list (k); put skip list ('Thanks');
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Plain_English
Plain English
To run: Start up. Demonstrate input. Wait for the escape key. Shut down.   To demonstrate input: Write "Enter a string: " to the console without advancing. Read a string from the console. Write "Enter a number: " to the console without advancing. Read a number from the console. \Now show the input values Write "The string: " then the string to the console. Write "The number: " then the number to the console.
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#SNOBOL4
SNOBOL4
define('foo(x,y)a,b,c') :(foo_end) foo a = 1; b = 2; c = 3 foo = a * ( x * x ) + b * y + c :(return) foo_end
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#SPL
SPL
a += 1
http://rosettacode.org/wiki/Undefined_values
Undefined values
#6502_Assembly
6502 Assembly
var foo; // untyped var bar:*; // explicitly untyped   trace(foo + ", " + bar); // outputs "undefined, undefined"   if (foo == undefined) trace("foo is undefined"); // outputs "foo is undefined"
http://rosettacode.org/wiki/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would represent a point in the region,   and a vector from the origin to the point. Given the vectors: A = (a1, a2, a3) B = (b1, b2, b3) C = (c1, c2, c3) then the following common vector products are defined: The dot product       (a scalar quantity) A • B = a1b1   +   a2b2   +   a3b3 The cross product       (a vector quantity) A x B = (a2b3  -   a3b2,     a3b1   -   a1b3,     a1b2   -   a2b1) The scalar triple product       (a scalar quantity) A • (B x C) The vector triple product       (a vector quantity) A x (B x C) Task Given the three vectors: a = ( 3, 4, 5) b = ( 4, 3, 5) c = (-5, -12, -13) Create a named function/subroutine/method to compute the dot product of two vectors. Create a function to compute the cross product of two vectors. Optionally create a function to compute the scalar triple product of three vectors. Optionally create a function to compute the vector triple product of three vectors. Compute and display: a • b Compute and display: a x b Compute and display: a • (b x c), the scalar triple product. Compute and display: a x (b x c), the vector triple product. References   A starting page on Wolfram MathWorld is   Vector Multiplication .   Wikipedia   dot product.   Wikipedia   cross product.   Wikipedia   triple product. Related tasks   Dot product   Quaternion type
#PARI.2FGP
PARI/GP
dot(u,v)={ sum(i=1,#u,u[i]*v[i]) }; cross(u,v)={ [u[2]*v[3] - u[3]*v[2], u[3]*v[1] - u[1]*v[3], u[1]*v[2] - u[2]*v[1]] }; striple(a,b,c)={ dot(a,cross(b,c)) }; vtriple(a,b,c)={ cross(a,cross(b,c)) };   a = [3,4,5]; b = [4,3,5]; c = [-5,-12,-13]; dot(a,b) cross(a,b) striple(a,b,c) vtriple(a,b,c)
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Pop11
Pop11
;;; Setup item reader lvars itemrep = incharitem(charin); lvars s, c, j = 0; ;;; read chars up to a newline and put them on the stack while (charin() ->> c) /= `\n` do j + 1 -> j ; c endwhile; ;;; build the string consstring(j) -> s; ;;; read the integer lvars i = itemrep();
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#PostScript
PostScript
%open stdin for reading (and name the channel "kbd"): /kbd (%stdin) (r) file def %make ten-char buffer to read string into: /buf (..........) def %read string into buffer: kbd buf readline
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#SSEM
SSEM
  // variable declaration var table, chair;   // assignment var table = 10, chair = -10;   // multiple assignment to the same value table = chair = 0;   // multiple assignment to an array ( var table, chair; #table, chair = [10, -10]; #table ... chair = [10, -10, 2, 3]; // with ellipsis: now chair is [-10, 2, 3] )   // the letters a-z are predeclared in the interpreter for interactive programming a = 10; x = a - 8;   // variables are type-neutral and mutable: reassign to different objects a = 10; a = [1, 2, 3]; a = nil;   // immutable variables (only in class definitions) const z = 42;   // lexical scope // the closures g and h refer to different values of their c ( f = { var c = 0; { c = c + 1 } }; g = f.value; h = f.value; c = 100; // this doesn't change it. )   // dynamic scope: environments f = { ~table = ~table + 1 }; Environment.use { ~table = 100; f.value }; // 101. Environment.use { ~table = -1; f.value }; // 0.   // there is a default environment ~table = 7; f.value;   // lexical scope in environments: ( Environment.use { ~table = 100; f = { ~table = ~table + 1 }.inEnvir; }; ) f.value; // 101.   // because objects keep reference to other objects, references are not needed: // objects can take the role of variables. But there is a Ref object, that just holds a value   a = Ref([1, 2, 3]); // a reference to an array, can also be written as a quote `[1, 2, 3]; f = { |x| x.value = x.value.squared }; // a function that operates on a ref f.(a); // `[ 1, 4, 9 ]   // proxy objects serve as delegators in environments. This can be called line by line: ProxySpace.push; ~z // returns a NodeProxy ~z.play; // play a silent sound ~z = ~x + ~y; // make it the sum of two silent sounds ~x = { PinkNoise.ar(0.1) }; // … which now are noise, ~y = { SinOsc.ar(440, 0, 0.1) }; // and a sine tone    
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#SuperCollider
SuperCollider
  // variable declaration var table, chair;   // assignment var table = 10, chair = -10;   // multiple assignment to the same value table = chair = 0;   // multiple assignment to an array ( var table, chair; #table, chair = [10, -10]; #table ... chair = [10, -10, 2, 3]; // with ellipsis: now chair is [-10, 2, 3] )   // the letters a-z are predeclared in the interpreter for interactive programming a = 10; x = a - 8;   // variables are type-neutral and mutable: reassign to different objects a = 10; a = [1, 2, 3]; a = nil;   // immutable variables (only in class definitions) const z = 42;   // lexical scope // the closures g and h refer to different values of their c ( f = { var c = 0; { c = c + 1 } }; g = f.value; h = f.value; c = 100; // this doesn't change it. )   // dynamic scope: environments f = { ~table = ~table + 1 }; Environment.use { ~table = 100; f.value }; // 101. Environment.use { ~table = -1; f.value }; // 0.   // there is a default environment ~table = 7; f.value;   // lexical scope in environments: ( Environment.use { ~table = 100; f = { ~table = ~table + 1 }.inEnvir; }; ) f.value; // 101.   // because objects keep reference to other objects, references are not needed: // objects can take the role of variables. But there is a Ref object, that just holds a value   a = Ref([1, 2, 3]); // a reference to an array, can also be written as a quote `[1, 2, 3]; f = { |x| x.value = x.value.squared }; // a function that operates on a ref f.(a); // `[ 1, 4, 9 ]   // proxy objects serve as delegators in environments. This can be called line by line: ProxySpace.push; ~z // returns a NodeProxy ~z.play; // play a silent sound ~z = ~x + ~y; // make it the sum of two silent sounds ~x = { PinkNoise.ar(0.1) }; // … which now are noise, ~y = { SinOsc.ar(440, 0, 0.1) }; // and a sine tone    
http://rosettacode.org/wiki/Undefined_values
Undefined values
#ActionScript
ActionScript
var foo; // untyped var bar:*; // explicitly untyped   trace(foo + ", " + bar); // outputs "undefined, undefined"   if (foo == undefined) trace("foo is undefined"); // outputs "foo is undefined"
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Ada
Ada
  pragma Initialize_Scalars; with Ada.Text_IO; use Ada.Text_IO;   procedure Invalid_Value is type Color is (Red, Green, Blue); X : Float; Y : Color; begin if not X'Valid then Put_Line ("X is not valid"); end if; X := 1.0; if X'Valid then Put_Line ("X is" & Float'Image (X)); end if; if not Y'Valid then Put_Line ("Y is not valid"); end if; Y := Green; if Y'Valid then Put_Line ("Y is " & Color'Image (Y)); end if; end Invalid_Value;  
http://rosettacode.org/wiki/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would represent a point in the region,   and a vector from the origin to the point. Given the vectors: A = (a1, a2, a3) B = (b1, b2, b3) C = (c1, c2, c3) then the following common vector products are defined: The dot product       (a scalar quantity) A • B = a1b1   +   a2b2   +   a3b3 The cross product       (a vector quantity) A x B = (a2b3  -   a3b2,     a3b1   -   a1b3,     a1b2   -   a2b1) The scalar triple product       (a scalar quantity) A • (B x C) The vector triple product       (a vector quantity) A x (B x C) Task Given the three vectors: a = ( 3, 4, 5) b = ( 4, 3, 5) c = (-5, -12, -13) Create a named function/subroutine/method to compute the dot product of two vectors. Create a function to compute the cross product of two vectors. Optionally create a function to compute the scalar triple product of three vectors. Optionally create a function to compute the vector triple product of three vectors. Compute and display: a • b Compute and display: a x b Compute and display: a • (b x c), the scalar triple product. Compute and display: a x (b x c), the vector triple product. References   A starting page on Wolfram MathWorld is   Vector Multiplication .   Wikipedia   dot product.   Wikipedia   cross product.   Wikipedia   triple product. Related tasks   Dot product   Quaternion type
#Pascal
Pascal
Program VectorProduct (output);   type Tvector = record x, y, z: double end;   function dotProduct(a, b: Tvector): double; begin dotProduct := a.x*b.x + a.y*b.y + a.z*b.z; end;   function crossProduct(a, b: Tvector): Tvector; begin crossProduct.x := a.y*b.z - a.z*b.y; crossProduct.y := a.z*b.x - a.x*b.z; crossProduct.z := a.x*b.y - a.y*b.x; end;   function scalarTripleProduct(a, b, c: Tvector): double; begin scalarTripleProduct := dotProduct(a, crossProduct(b, c)); end;   function vectorTripleProduct(a, b, c: Tvector): Tvector; begin vectorTripleProduct := crossProduct(a, crossProduct(b, c)); end;   procedure printVector(a: Tvector); begin writeln(a.x:15:8, a.y:15:8, a.z:15:8); end;   var a: Tvector = (x: 3; y: 4; z: 5); b: Tvector = (x: 4; y: 3; z: 5); c: Tvector = (x:-5; y:-12; z:-13);   begin write('a: '); printVector(a); write('b: '); printVector(b); write('c: '); printVector(c); writeln('a . b: ', dotProduct(a,b):15:8); write('a x b: '); printVector(crossProduct(a,b)); writeln('a . (b x c): ', scalarTripleProduct(a,b,c):15:8); write('a x (b x c): '); printVector(vectorTripleProduct(a,b,c)); end.
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#PowerShell
PowerShell
$string = Read-Host "Input a string" [int]$number = Read-Host "Input a number"
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#PureBasic
PureBasic
If OpenConsole() ; Declare a string and a integer to be used Define txt.s, num.i   Print("Enter a string: ") txt=Input()   Repeat Print("Enter the number 75000: ") num=Val(Input()) ; Converts the Input to a Value with Val() Until num=75000 ; Check that the user really gives us 75000!   Print("You made it!") Delay(3000): CloseConsole() EndIf
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#Swift
Swift
import Foundation   // All variables declared outside of a struct/class/etc are global   // Swift is a typed language // Swift can infer the type of variables var str = "Hello, playground" // String let letStr:String = "This is a constant"   // However, all variables must be initialized // Intialize variable of type String to nil var str1:String! // str1 is nil   // Assign value to str1 str1 = "foo bar" // str1 is foo bar   // Swift also has optional types // Declare optional with type of String var optionalString = Optional<String>("foo bar") // (Some "foo bar")   println(optionalString) // Optional("foo bar")   // Optionals can also be declared with the shorthand ? var optionalString1:String? = "foo bar"   // ! can be used to force unwrap but will throw a runtime error if trying to unwrap a nil value println(optionalString1!)   optionalString1 = nil // Is now nil // println(optionalString1!) would now throw a runtime error   // Optional chaining can be used to gracefully fail if there is a nil value if let value = optionalString1?.lowercaseString { // Is never executed } else { println("optionalString1 is nil") }   // Swift also has type aliasing typealias MyNewType = String // MyNewType is an alias of String var myNewTypeString = MyNewType("foo bar")   // Swift also has special types Any and AnyObject // Any can hold any type // AnyObject can hold any object type let myAnyObjectString:AnyObject = "foo bar"   // Downcast myAnyObjectString to String if let myString = myAnyObjectString as? String { println(myString) // foo bar } else { println("myString is not a string") }   // Swift treats functions as first-class // Declare a variable with a type of a function that takes no args // and returns Void var myFunc:(() -> Void) func showScopes() { // Variable is scoped to function let myFunctionVariable = "foo bar function"   // Nested functions inherit variables declared in enclosing scope func nestFunc() { println(myFunctionVariable) } nestFunc() }   myFunc = showScopes // myFunc is now showScopes myFunc() // foo bar function
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#Tcl
Tcl
namespace eval foo { # Define a procedure with two formal arguments; they are local variables proc bar {callerVarName argumentVar} { ### Associate some non-local variables with the procedure global globalVar; # Variable in global namespace variable namespaceVar; # Variable in local (::foo) namespace # Access to variable in caller's context; may be local or global upvar 1 callerVarName callerVar   ### Reading a variable uses the same syntax in all cases puts "caller's var has $callerVar" # But global and namespace vars can be accessed by using qualified names puts "global var has $globalVar which is $::globalVar"   ### Writing a variable has no special syntax ### but [set] is by far the most common command for writing set namespaceVar $globalVar incr globalVar   ### Destroying a variable is done like this unset argumentVar } }
http://rosettacode.org/wiki/Undefined_values
Undefined values
#ALGOL_68
ALGOL 68
MODE R = REF BOOL; R r := NIL;   MODE U = UNION(BOOL, VOID); U u := EMPTY;   IF r IS R(NIL) THEN print(("r IS NIL", new line)) ELSE print(("r ISNT NIL", new line)) FI;   CASE u IN (VOID):print(("u is EMPTY", new line)) OUT print(("u isnt EMPTY", new line)) ESAC
http://rosettacode.org/wiki/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would represent a point in the region,   and a vector from the origin to the point. Given the vectors: A = (a1, a2, a3) B = (b1, b2, b3) C = (c1, c2, c3) then the following common vector products are defined: The dot product       (a scalar quantity) A • B = a1b1   +   a2b2   +   a3b3 The cross product       (a vector quantity) A x B = (a2b3  -   a3b2,     a3b1   -   a1b3,     a1b2   -   a2b1) The scalar triple product       (a scalar quantity) A • (B x C) The vector triple product       (a vector quantity) A x (B x C) Task Given the three vectors: a = ( 3, 4, 5) b = ( 4, 3, 5) c = (-5, -12, -13) Create a named function/subroutine/method to compute the dot product of two vectors. Create a function to compute the cross product of two vectors. Optionally create a function to compute the scalar triple product of three vectors. Optionally create a function to compute the vector triple product of three vectors. Compute and display: a • b Compute and display: a x b Compute and display: a • (b x c), the scalar triple product. Compute and display: a x (b x c), the vector triple product. References   A starting page on Wolfram MathWorld is   Vector Multiplication .   Wikipedia   dot product.   Wikipedia   cross product.   Wikipedia   triple product. Related tasks   Dot product   Quaternion type
#Perl
Perl
package Vector; use List::Util 'sum'; use List::MoreUtils 'pairwise';   sub new { shift; bless [@_] }   use overload ( '""' => sub { "(@{+shift})" }, '&' => sub { sum pairwise { $a * $b } @{+shift}, @{+shift} }, '^' => sub { my @a = @{+shift}; my @b = @{+shift}; bless [ $a[1]*$b[2] - $a[2]*$b[1], $a[2]*$b[0] - $a[0]*$b[2], $a[0]*$b[1] - $a[1]*$b[0] ] }, );   package main; my $a = Vector->new(3, 4, 5); my $b = Vector->new(4, 3, 5); my $c = Vector->new(-5, -12, -13);   print "a = $a b = $b c = $c\n"; print "$a . $b = ", $a & $b, "\n"; print "$a x $b = ", $a ^ $b, "\n"; print "$a . ($b x $c) = ", $a & ($b ^ $c), "\n"; print "$a x ($b x $c) = ", $a ^ ($b ^ $c), "\n";
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Python
Python
string = raw_input("Input a string: ")
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Quackery
Quackery
$ "Please enter a string: " input say 'You entered: "' echo$ say '"' cr cr   $ "Please enter an integer: " input trim reverse trim reverse $->n iff [ say "You entered: " echo cr ] else [ say "That was not an integer." cr drop ]
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#TI-83_BASIC
TI-83 BASIC
  :1→A  
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#TI-89_BASIC
TI-89 BASIC
Local mynum, myfunc
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Arturo
Arturo
undef: null   print undef
http://rosettacode.org/wiki/Undefined_values
Undefined values
#BASIC
BASIC
ok% = TRUE ON ERROR LOCAL IF ERR<>26 REPORT : END ELSE ok% = FALSE IF ok% THEN PRINT variable$ ELSE PRINT "Not defined" ENDIF RESTORE ERROR
http://rosettacode.org/wiki/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would represent a point in the region,   and a vector from the origin to the point. Given the vectors: A = (a1, a2, a3) B = (b1, b2, b3) C = (c1, c2, c3) then the following common vector products are defined: The dot product       (a scalar quantity) A • B = a1b1   +   a2b2   +   a3b3 The cross product       (a vector quantity) A x B = (a2b3  -   a3b2,     a3b1   -   a1b3,     a1b2   -   a2b1) The scalar triple product       (a scalar quantity) A • (B x C) The vector triple product       (a vector quantity) A x (B x C) Task Given the three vectors: a = ( 3, 4, 5) b = ( 4, 3, 5) c = (-5, -12, -13) Create a named function/subroutine/method to compute the dot product of two vectors. Create a function to compute the cross product of two vectors. Optionally create a function to compute the scalar triple product of three vectors. Optionally create a function to compute the vector triple product of three vectors. Compute and display: a • b Compute and display: a x b Compute and display: a • (b x c), the scalar triple product. Compute and display: a x (b x c), the vector triple product. References   A starting page on Wolfram MathWorld is   Vector Multiplication .   Wikipedia   dot product.   Wikipedia   cross product.   Wikipedia   triple product. Related tasks   Dot product   Quaternion type
#Phix
Phix
function dot_product(sequence a, b) return sum(sq_mul(a,b)) end function function cross_product(sequence a, b) integer {a1,a2,a3} = a, {b1,b2,b3} = b return {a2*b3-a3*b2, a3*b1-a1*b3, a1*b2-a2*b1} end function function scalar_triple_product(sequence a, b, c) return dot_product(a,cross_product(b,c)) end function function vector_triple_product(sequence a, b, c) return cross_product(a,cross_product(b,c)) end function constant a = {3, 4, 5}, b = {4, 3, 5}, c = {-5, -12, -13} printf(1," a . b = %v\n",{dot_product(a,b)}) printf(1," a x b = %v\n",{cross_product(a,b)}) printf(1,"a . (b x c) = %v\n",{scalar_triple_product(a,b,c)}) printf(1,"a x (b x c) = %v\n",{vector_triple_product(a,b,c)})
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#R
R
stringval <- readline("String: ") intval <- as.integer(readline("Integer: "))
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Racket
Racket
  #lang racket (printf "Input a string: ") (define s (read-line)) (printf "You entered: ~a\n" s)   (printf "Input a number: ") (define m (or (string->number (read-line)) (error "I said a number!"))) (printf "You entered: ~a\n" m)   ;; alternatively, use the generic `read' (printf "Input a number: ") (define n (read)) (unless (number? n) (error "I said a number!")) (printf "You entered: ~a\n" n)  
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT,{} var1=1, var2="b" PRINT "var1=",var1 PRINT "var2=",var2   basket=* DATA apples DATA bananas DATA cherry   LOOP n,letter="a'b'c",fruit=basket var=CONCAT (letter,n) SET @var=VALUE(fruit) PRINT var,"=",@var ENDLOOP  
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#TXR
TXR
@(cases) hey @a how are you @(or) hey @b long time no see @(end)
http://rosettacode.org/wiki/Undefined_values
Undefined values
#BBC_BASIC
BBC BASIC
ok% = TRUE ON ERROR LOCAL IF ERR<>26 REPORT : END ELSE ok% = FALSE IF ok% THEN PRINT variable$ ELSE PRINT "Not defined" ENDIF RESTORE ERROR
http://rosettacode.org/wiki/Undefined_values
Undefined values
#C
C
#include <stdio.h> #include <stdlib.h>   int main() { int junk, *junkp;   /* Print an unitialized variable! */ printf("junk: %d\n", junk);   /* Follow a pointer to unitialized memory! */ junkp = malloc(sizeof *junkp); if (junkp) printf("*junkp: %d\n", *junkp); return 0; }
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths: /foo/bar /foo/bar/1 /foo/bar/2 /foo/bar/a /foo/bar/b When the program is executed in   `/foo`,   it should print: bar and when the program is executed in   `/foo/bar`,   it should print: 1 2 a b
#11l
11l
print(sorted(fs:list_dir(‘.’)).join("\n"))
http://rosettacode.org/wiki/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would represent a point in the region,   and a vector from the origin to the point. Given the vectors: A = (a1, a2, a3) B = (b1, b2, b3) C = (c1, c2, c3) then the following common vector products are defined: The dot product       (a scalar quantity) A • B = a1b1   +   a2b2   +   a3b3 The cross product       (a vector quantity) A x B = (a2b3  -   a3b2,     a3b1   -   a1b3,     a1b2   -   a2b1) The scalar triple product       (a scalar quantity) A • (B x C) The vector triple product       (a vector quantity) A x (B x C) Task Given the three vectors: a = ( 3, 4, 5) b = ( 4, 3, 5) c = (-5, -12, -13) Create a named function/subroutine/method to compute the dot product of two vectors. Create a function to compute the cross product of two vectors. Optionally create a function to compute the scalar triple product of three vectors. Optionally create a function to compute the vector triple product of three vectors. Compute and display: a • b Compute and display: a x b Compute and display: a • (b x c), the scalar triple product. Compute and display: a x (b x c), the vector triple product. References   A starting page on Wolfram MathWorld is   Vector Multiplication .   Wikipedia   dot product.   Wikipedia   cross product.   Wikipedia   triple product. Related tasks   Dot product   Quaternion type
#Phixmonti
Phixmonti
include ..\Utilitys.pmt   ( 3 4 5 ) var vectorA ( 4 3 5 ) var vectorB ( -5 -12 -13 ) var vectorC   def dotProduct /# x y -- n #/ 0 >ps len for var i i get rot i get rot * ps> + >ps endfor drop drop ps> enddef   def crossProduct /# x y -- z #/ 1 get rot 2 get rot * >ps 1 get rot 2 get rot * >ps 3 get rot 1 get rot * >ps 3 get rot 1 get rot * >ps 2 get rot 3 get rot * >ps 2 get rot 3 get rot * ps> - ps> ps> - ps> ps> - 3 tolist nip nip enddef   "Dot Product = " print vectorA vectorB dotProduct ? "Cross Product = " print vectorA vectorB crossProduct ? "Scalar Triple Product = " print vectorB vectorC crossProduct vectorA swap dotProduct ? "Vector Triple Product = " print vectorB vectorC crossProduct vectorA swap crossProduct ?
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Raku
Raku
my $str = prompt("Enter a string: "); my $int = prompt("Enter a integer: ");
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Rascal
Rascal
import util::IDE; public void InputConsole(){ x = ""; createConsole("Input Console", "Welcome to the Input Console\nInput\> ", str (str inp) {x = "<inp == "75000" ? "You entered 75000" : "You entered a string">"; return "<x>\n<inp>\nInput\>";}); }
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#uBasic.2F4tH
uBasic/4tH
' Initialization A = 15 ' global variable   Proc _Initialize(24)   _Initialize Param (1) Local (1) ' A@ now holds 24 B@ = 23 ' local variable Return   ' Assignment A = 15 ' global variable   Proc _Assign(24)   _Assign Param (1) Local (1) ' A@ now holds 24 A@ = 5 ' reassignment of parameter A@ B@ = 23 ' local variable Return
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#UNIX_Shell
UNIX Shell
  #!/bin/sh # The unix shell uses typeless variables apples=6 # pears=5+4 # Some shells cannot perform addition this way pears = `expr 5+4` # We use the external expr to perform the calculation myfavourite="raspberries"  
http://rosettacode.org/wiki/Undefined_values
Undefined values
#C.23
C#
string foo = null;
http://rosettacode.org/wiki/Undefined_values
Undefined values
#C.2B.2B
C++
#include <iostream>   int main() { int undefined; if (undefined == 42) { std::cout << "42"; }   if (undefined != 42) { std::cout << "not 42"; } }
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths: /foo/bar /foo/bar/1 /foo/bar/2 /foo/bar/a /foo/bar/b When the program is executed in   `/foo`,   it should print: bar and when the program is executed in   `/foo/bar`,   it should print: 1 2 a b
#8080_Assembly
8080 Assembly
dma: equ 80h puts: equ 9h ; Write string to console sfirst: equ 11h ; Find first matching file snext: equ 12h ; Get next matching file org 100h ;;; First, retrieve all filenames in current directory ;;; CP/M has function 11h (sfirst) and function 13h (snext) ;;; to return the first, and then following, files that ;;; match a wildcard. lxi d,0 ; Amount of files push d ; Push on stack lxi h,fnames ; Start of area to save names push h ; Push on stack lxi d,fcb ; FCB that will match any file mvi c,sfirst ; Get the first file getnames: call 5 ; Call CP/M BDOS inr a jz namesdone ; FF = we have all files dcr a ; Dir entry is at DMA+32*A rrc ; Rotate 3 right, same as rrc ; rotate 5 left, *32 rrc adi dma+1 ; Add DMA offset + 1 (filename offset) mov e,a ; Low byte of address mvi d,0 ; High byte is 0 mvi b,8 ; Filename is 8 bytes pop h ; Get pointer to name area call memcpy ; Copy the name mvi m,' ' ; Separate name and extension inx h mvi b,3 ; Extension is 3 bytes call memcpy ; Copy the extension mvi m,13 ; While we're at it, terminate inx h ; the filename with \r\n mvi m,10 inx h pop d ; Get amount of files inx d ; Increment it (we've added a file) push d ; Put it back onto the stack push h ; Put the name pointer on the stack too mvi c,snext ; Go get the next file jmp getnames namesdone: pop h ; Terminate the file list with $ mvi m,'$' ; so it can be printed with function 9 ;;; CP/M does not keep its directory in sorted order, ;;; so we need to sort the list of files ourselves. ;;; What follows is a simple insertion sort. lxi d,1 ; DE (i) = 1 sortouter: pop h ; Get amount of files push h call cmpdehl ; i < length(files)? jnc sortdone ; If not, we're done push d ; push i; DE (j) = i sortinner: push d ; push j mov a,d ; j > 0? ora e jz sortinnerdone ; If not, inner loop is done dcx d ; DE = j-1 call lookup ; HL = files[j-1] push h ; push files[j-1] inx d ; DE = j call lookup ; HL = files[j] pop d ; pop DE = files[j-1] push d ; keep them across comparison push h call cmpentries ; A[j] >= A[j-1]? pop h pop d jc sortinnerdone ; Then inner loop is done. mvi b,12 ; Otherwise we should swap them swaploop: ldax d ; Get byte from files[j-1] mov c,m ; Get byte from files[j] mov m,a ; files[j][x]=files[j-1][x] mov a,c ; files[j-1][x]=files[j]-[x] stax d inx h ; Increment pointers inx d dcr b ; all 12 bytes done yet? jnz swaploop ; if not, swap next byte pop d ; DE = j dcx d ; j = j-1 jmp sortinner sortinnerdone: pop d ; pop j pop d ; pop i inx d ; i = i + 1 jmp sortouter sortdone: pop h ; Remove file count from stack ;;; We're done sorting the list, print it. lxi d,fnames ; Print the now sorted list of files mvi c,puts jmp 5 ;;; Subroutine: compare entries under DE and HL cmpentries: mvi b,12 ; Each entry has 12 relevant bytes. cmploop: ldax d ; Get byte from entry DE cmp m ; Compare with byte from entry HL rnz ; If they differ, we know the ordering inx h ; Increment both pointers inx d dcr b ; Decrement byte counter jnz cmploop ; Compare next byte ret ;;; Subroutine: look up filename entry (HL=DE*14+fnames) lookup: push d ; Save entry number mov h,d mov l,e dad h ; HL = HL' * 2 dad d ; HL = HL' * 3 dad h ; HL = HL' * 6 dad d ; HL = HL' * 7 dad h ; HL = HL' * 14 lxi d,fnames ; Offset dad d ; Add the offset pop d ; Restore entry number ret ;;; Subroutine: compare DE and HL cmpdehl: mov a,d cmp h rnz mov a,e cmp l ret ;;; Subroutine: copy B bytes from DE to HL memcpy: ldax d ; Get byte from source mov m,a ; Store byte at destination inx h ; Increment both pointers inx d dcr b ; Done yet? jnz memcpy ; If not, copy next byte ret ;;; File control block used to specify wildcard fcb: db 0,'???????????' ; Accept any file ds fcb+36-$ ; Pad the FCB out to 36 bytes fnames:
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths: /foo/bar /foo/bar/1 /foo/bar/2 /foo/bar/a /foo/bar/b When the program is executed in   `/foo`,   it should print: bar and when the program is executed in   `/foo/bar`,   it should print: 1 2 a b
#8th
8th
  "*" f:glob ' s:cmp a:sort "\n" a:join .  
http://rosettacode.org/wiki/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would represent a point in the region,   and a vector from the origin to the point. Given the vectors: A = (a1, a2, a3) B = (b1, b2, b3) C = (c1, c2, c3) then the following common vector products are defined: The dot product       (a scalar quantity) A • B = a1b1   +   a2b2   +   a3b3 The cross product       (a vector quantity) A x B = (a2b3  -   a3b2,     a3b1   -   a1b3,     a1b2   -   a2b1) The scalar triple product       (a scalar quantity) A • (B x C) The vector triple product       (a vector quantity) A x (B x C) Task Given the three vectors: a = ( 3, 4, 5) b = ( 4, 3, 5) c = (-5, -12, -13) Create a named function/subroutine/method to compute the dot product of two vectors. Create a function to compute the cross product of two vectors. Optionally create a function to compute the scalar triple product of three vectors. Optionally create a function to compute the vector triple product of three vectors. Compute and display: a • b Compute and display: a x b Compute and display: a • (b x c), the scalar triple product. Compute and display: a x (b x c), the vector triple product. References   A starting page on Wolfram MathWorld is   Vector Multiplication .   Wikipedia   dot product.   Wikipedia   cross product.   Wikipedia   triple product. Related tasks   Dot product   Quaternion type
#PHP
PHP
<?php   class Vector { private $values;   public function setValues(array $values) { if (count($values) != 3) throw new Exception('Values must contain exactly 3 values'); foreach ($values as $value) if (!is_int($value) && !is_float($value)) throw new Exception('Value "' . $value . '" has an invalid type'); $this->values = $values; }   public function getValues() { if ($this->values == null) $this->setValues(array ( 0, 0, 0 )); return $this->values; }   public function Vector(array $values) { $this->setValues($values); }   public static function dotProduct(Vector $va, Vector $vb) { $a = $va->getValues(); $b = $vb->getValues(); return ($a[0] * $b[0]) + ($a[1] * $b[1]) + ($a[2] * $b[2]); }   public static function crossProduct(Vector $va, Vector $vb) { $a = $va->getValues(); $b = $vb->getValues(); return new Vector(array ( ($a[1] * $b[2]) - ($a[2] * $b[1]), ($a[2] * $b[0]) - ($a[0] * $b[2]), ($a[0] * $b[1]) - ($a[1] * $b[0]) )); }   public static function scalarTripleProduct(Vector $va, Vector $vb, Vector $vc) { return self::dotProduct($va, self::crossProduct($vb, $vc)); }   public static function vectorTrippleProduct(Vector $va, Vector $vb, Vector $vc) { return self::crossProduct($va, self::crossProduct($vb, $vc)); } }   class Program {   public function Program() { $a = array ( 3, 4, 5 ); $b = array ( 4, 3, 5 ); $c = array ( -5, -12, -13 ); $va = new Vector($a); $vb = new Vector($b); $vc = new Vector($c);   $result1 = Vector::dotProduct($va, $vb); $result2 = Vector::crossProduct($va, $vb)->getValues(); $result3 = Vector::scalarTripleProduct($va, $vb, $vc); $result4 = Vector::vectorTrippleProduct($va, $vb, $vc)->getValues();   printf("\n"); printf("A = (%0.2f, %0.2f, %0.2f)\n", $a[0], $a[1], $a[2]); printf("B = (%0.2f, %0.2f, %0.2f)\n", $b[0], $b[1], $b[2]); printf("C = (%0.2f, %0.2f, %0.2f)\n", $c[0], $c[1], $c[2]); printf("\n"); printf("A · B = %0.2f\n", $result1); printf("A × B = (%0.2f, %0.2f, %0.2f)\n", $result2[0], $result2[1], $result2[2]); printf("A · (B × C) = %0.2f\n", $result3); printf("A × (B × C) =(%0.2f, %0.2f, %0.2f)\n", $result4[0], $result4[1], $result4[2]); } }   new Program(); ?>  
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Raven
Raven
'Input a string: ' print expect as str 'Input an integer: ' print expect 0 prefer as num
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#REBOL
REBOL
rebol [ Title: "Textual User Input" URL: http://rosettacode.org/wiki/User_Input_-_text ]   s: n: ""   ; Because I have several things to check for, I've made a function to ; handle it. Note the question mark in the function name, this convention ; is often used in Forth to indicate test of some sort.   valid?: func [s n][ error? try [n: to-integer n] ; Ignore error if conversion fails. all [0 < length? s 75000 = n]]   ; I don't want to give up until I've gotten something useful, so I ; loop until the user enters valid data.   while [not valid? s n][ print "Please enter a string, and the number 75000:" s: ask "string: " n: ask "number: " ]   ; It always pays to be polite...   print rejoin [ "Thank you. Your string was '" s "'."]
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#Ursa
Ursa
# variable declaration # # declare [type] [name] # -or- # decl [type] [name] decl int test   # initialization / assignment # # the set statement can be used to init variables and # assign values to them set test 10   # datatypes # # ursa currently has 10 built-in types, but # more may be added in the future. # boolean # double # file # function # int # iodevice # port # serverport # string # task # # also, java classes may be used as data types # cygnus/x ursa   # scope # # there is a global variable space, and functions # have their own scope. control statements (for, # if, try, while) don't have their own scope yet, # but this will be implemented in the near future   # referencing # # variables are referenced by their name decl port p out p endl console
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#VBA
VBA
Dim variable As datatype Dim var1,var2,... As datatype
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Common_Lisp
Common Lisp
  ;; assumption: none of these variables initially exist   (defvar *x*) ;; variable exists now, but has no value (defvar *y* 42) ;; variable exists now, and has a value   (special-variable-p '*x*) -> T ;; Symbol *x* names a special variable (boundp '*x*) -> NIL ;; *x* has no binding (boundp '*y*) -> T   (special-variable-p '*z*) -> NIL ;; *z* does not name a special variable
http://rosettacode.org/wiki/Undefined_values
Undefined values
#D
D
void main() { // Initialized: int a = 5; double b = 5.0; char c = 'f'; int[] d = [1, 2, 3];   // Default initialized: int aa; // set to 0 double bb; // set to double.init, that is a NaN char cc; // set to 0xFF int[] dd; // set to null int[3] ee; // set to [0, 0, 0]   // Undefined (contain garbage): int aaa = void; double[] bbb = void; int[3] eee = void; }
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths: /foo/bar /foo/bar/1 /foo/bar/2 /foo/bar/a /foo/bar/b When the program is executed in   `/foo`,   it should print: bar and when the program is executed in   `/foo/bar`,   it should print: 1 2 a b
#Ada
Ada
with Ada.Text_IO, Ada.Directories, Ada.Containers.Indefinite_Vectors;   procedure Directory_List is   use Ada.Directories, Ada.Text_IO; Search: Search_Type; Found: Directory_Entry_Type; package SV is new Ada.Containers.Indefinite_Vectors(Natural, String); Result: SV.Vector; package Sorting is new SV.Generic_Sorting; use Sorting; function SName return String is (Simple_Name(Found));   begin -- search directory and store it in Result, a vector of strings Start_Search(Search, Directory => ".", Pattern =>""); while More_Entries(Search) loop Get_Next_Entry(Search, Found); declare Name: String := Simple_Name(Found); begin if Name(Name'First) /= '.' then Result.Append(Name); end if; -- ingnore filenames beginning with "." end; end loop; -- Result holds the entire directory in arbitrary order   Sort(Result); -- Result holds the directory in proper order   -- print Result for I in Result.First_Index .. Result.Last_Index loop Put_Line(Result.Element(I)); end loop; end Directory_List;
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths: /foo/bar /foo/bar/1 /foo/bar/2 /foo/bar/a /foo/bar/b When the program is executed in   `/foo`,   it should print: bar and when the program is executed in   `/foo/bar`,   it should print: 1 2 a b
#Aime
Aime
record r; file f; text s;   f.opendir(1.argv);   while (~f.case(s)) { if (s != "." && s != "..") { r[s] = 0; } }   r.vcall(o_, 0, "\n");
http://rosettacode.org/wiki/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would represent a point in the region,   and a vector from the origin to the point. Given the vectors: A = (a1, a2, a3) B = (b1, b2, b3) C = (c1, c2, c3) then the following common vector products are defined: The dot product       (a scalar quantity) A • B = a1b1   +   a2b2   +   a3b3 The cross product       (a vector quantity) A x B = (a2b3  -   a3b2,     a3b1   -   a1b3,     a1b2   -   a2b1) The scalar triple product       (a scalar quantity) A • (B x C) The vector triple product       (a vector quantity) A x (B x C) Task Given the three vectors: a = ( 3, 4, 5) b = ( 4, 3, 5) c = (-5, -12, -13) Create a named function/subroutine/method to compute the dot product of two vectors. Create a function to compute the cross product of two vectors. Optionally create a function to compute the scalar triple product of three vectors. Optionally create a function to compute the vector triple product of three vectors. Compute and display: a • b Compute and display: a x b Compute and display: a • (b x c), the scalar triple product. Compute and display: a x (b x c), the vector triple product. References   A starting page on Wolfram MathWorld is   Vector Multiplication .   Wikipedia   dot product.   Wikipedia   cross product.   Wikipedia   triple product. Related tasks   Dot product   Quaternion type
#Picat
Picat
go => A = [3, 4, 5], B = [4, 3, 5], C = [-5, -12, -13],   println(a=A), println(b=B), println(c=C), println("A . B"=dot(A,B)), println("A x B"=cross(A,B)), println("A . (B x C)"=scalar_triple(A,B,C)), println("A X (B X C)"=vector_triple(A,B,C)), nl.   dot(A,B) = sum([ AA*BB : {AA,BB} in zip(A,B)]). cross(A,B) = [A[2]*B[3]-A[3]*B[2], A[3]*B[1]-A[1]*B[3], A[1]*B[2]-A[2]*B[1]].   scalar_triple(A,B,C) = dot(A,cross(B,C)). vector_triple(A,B,C) = cross(A,cross(B,C)).
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Red
Red
n: ask "Please enter # 75000: " str: ask "Please enter any string: "
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Retro
Retro
:example ("-) 'Enter_a_string:_ s:put s:get s:keep [ 'Enter_75000:_ s:put s:get-word s:to-number nl #75000 eq? ] until 'Your_string_was:_'%s'\n s:format s:put ;
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#VBScript
VBScript
Dim variable As datatype Dim var1,var2,... As datatype
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#Visual_Basic
Visual Basic
Dim variable As datatype Dim var1,var2,... As datatype
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Delphi
Delphi
var P: PInteger; begin New(P); //Allocate some memory try If Assigned(P) Then //... begin P^ := 42; end; finally Dispose(P); //Release memory allocated by New end; end;
http://rosettacode.org/wiki/Undefined_values
Undefined values
#D.C3.A9j.C3.A0_Vu
Déjà Vu
try: bogus catch name-error:  !print "There is *no* :bogus in the current context" return !print "You won't see this."
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identifiers
#11l
11l
V Δx = 1 Δx++ print(Δx)
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths: /foo/bar /foo/bar/1 /foo/bar/2 /foo/bar/a /foo/bar/b When the program is executed in   `/foo`,   it should print: bar and when the program is executed in   `/foo/bar`,   it should print: 1 2 a b
#Arturo
Arturo
print list "."
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths: /foo/bar /foo/bar/1 /foo/bar/2 /foo/bar/a /foo/bar/b When the program is executed in   `/foo`,   it should print: bar and when the program is executed in   `/foo/bar`,   it should print: 1 2 a b
#AWK
AWK
  # syntax: GAWK -f UNIX_LS.AWK * | SORT BEGINFILE { printf("%s\n",FILENAME) nextfile } END { exit(0) }  
http://rosettacode.org/wiki/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would represent a point in the region,   and a vector from the origin to the point. Given the vectors: A = (a1, a2, a3) B = (b1, b2, b3) C = (c1, c2, c3) then the following common vector products are defined: The dot product       (a scalar quantity) A • B = a1b1   +   a2b2   +   a3b3 The cross product       (a vector quantity) A x B = (a2b3  -   a3b2,     a3b1   -   a1b3,     a1b2   -   a2b1) The scalar triple product       (a scalar quantity) A • (B x C) The vector triple product       (a vector quantity) A x (B x C) Task Given the three vectors: a = ( 3, 4, 5) b = ( 4, 3, 5) c = (-5, -12, -13) Create a named function/subroutine/method to compute the dot product of two vectors. Create a function to compute the cross product of two vectors. Optionally create a function to compute the scalar triple product of three vectors. Optionally create a function to compute the vector triple product of three vectors. Compute and display: a • b Compute and display: a x b Compute and display: a • (b x c), the scalar triple product. Compute and display: a x (b x c), the vector triple product. References   A starting page on Wolfram MathWorld is   Vector Multiplication .   Wikipedia   dot product.   Wikipedia   cross product.   Wikipedia   triple product. Related tasks   Dot product   Quaternion type
#PicoLisp
PicoLisp
(de dotProduct (A B) (sum * A B) )   (de crossProduct (A B) (list (- (* (cadr A) (caddr B)) (* (caddr A) (cadr B))) (- (* (caddr A) (car B)) (* (car A) (caddr B))) (- (* (car A) (cadr B)) (* (cadr A) (car B))) ) )   (de scalarTriple (A B C) (dotProduct A (crossProduct B C)) )   (de vectorTriple (A B C) (crossProduct A (crossProduct B C)) )
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#REXX
REXX
do until userNumber==75000
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Ring
Ring
  see "Enter a string : " give s see "Enter an integer : " give i see "String = " + s + nl see "Integer = " + i + nl  
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#Visual_Basic_.NET
Visual Basic .NET
Dim variable As datatype Dim var1,var2,... As datatype
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#Vlang
Vlang
name := 'Bob' age := 20 large_number := i64(9999999999)
http://rosettacode.org/wiki/Undefined_values
Undefined values
#E
E
if (foo == bar || (def baz := lookup(foo)) != null) { ... }
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Erlang
Erlang
  -module( undefined_values ).   -export( [task/0] ).   -record( a_record, {member_1, member_2} ).   task() -> Record = #a_record{member_1=a_value}, io:fwrite( "Record member_1 ~p, member_2 ~p~n", [Record#a_record.member_1, Record#a_record.member_2] ), io:fwrite( "Member_2 is undefined ~p~n", [Record#a_record.member_2 =:= undefined] ).  
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identifiers
#8th
8th
  1 var, Δ   Δ @ n:1+ Δ !   Δ @ . cr   \ unicode silliness   : 念 ' G:@ w:exec ; : 店 ' G:! w:exec ; : ਵਾਧਾ ' n:1+ w:exec ; : الوداع ' G:bye w:exec ; : キャリッジリターン ' G:cr w:exec ; : प्रिंट ' G:. w:exec ;   Δ 念 ਵਾਧਾ Δ 店   Δ 念 प्रिंट キャリッジリターン الوداع    
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identifiers
#ACL2
ACL2
(let ((Δ 1)) (1+ Δ))
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identifiers
#Ada
Ada
with Ada.Text_IO; procedure main is Δ : Integer; begin Δ := 41; Δ := Δ + 1; Ada.Text_IO.Put_Line (Δ'Img); end main;
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths: /foo/bar /foo/bar/1 /foo/bar/2 /foo/bar/a /foo/bar/b When the program is executed in   `/foo`,   it should print: bar and when the program is executed in   `/foo/bar`,   it should print: 1 2 a b
#BaCon
BaCon
' Emulate ls cnt% = 0 files$ = "" OPEN CURDIR$ FOR DIRECTORY AS mydir GETFILE myfile$ FROM mydir WHILE ISTRUE(LEN(myfile$)) IF LEFT$(myfile$, 1) != "." THEN INCR cnt% files$ = APPEND$(files$, cnt%, UNFLATTEN$(myfile$)) ENDIF GETFILE myfile$ FROM mydir WEND CLOSE DIRECTORY mydir IF cnt% > 0 THEN FOR f$ IN SORT$(files$) PRINT FLATTEN$(f$) NEXT ENDIF
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths: /foo/bar /foo/bar/1 /foo/bar/2 /foo/bar/a /foo/bar/b When the program is executed in   `/foo`,   it should print: bar and when the program is executed in   `/foo/bar`,   it should print: 1 2 a b
#BASIC256
BASIC256
directory$ = dir("m:\foo\bar\") #Specified directory #directory$ = dir(currentdir) #Current directory   while directory$ <> "" print directory$ directory$ = dir() end while end
http://rosettacode.org/wiki/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would represent a point in the region,   and a vector from the origin to the point. Given the vectors: A = (a1, a2, a3) B = (b1, b2, b3) C = (c1, c2, c3) then the following common vector products are defined: The dot product       (a scalar quantity) A • B = a1b1   +   a2b2   +   a3b3 The cross product       (a vector quantity) A x B = (a2b3  -   a3b2,     a3b1   -   a1b3,     a1b2   -   a2b1) The scalar triple product       (a scalar quantity) A • (B x C) The vector triple product       (a vector quantity) A x (B x C) Task Given the three vectors: a = ( 3, 4, 5) b = ( 4, 3, 5) c = (-5, -12, -13) Create a named function/subroutine/method to compute the dot product of two vectors. Create a function to compute the cross product of two vectors. Optionally create a function to compute the scalar triple product of three vectors. Optionally create a function to compute the vector triple product of three vectors. Compute and display: a • b Compute and display: a x b Compute and display: a • (b x c), the scalar triple product. Compute and display: a x (b x c), the vector triple product. References   A starting page on Wolfram MathWorld is   Vector Multiplication .   Wikipedia   dot product.   Wikipedia   cross product.   Wikipedia   triple product. Related tasks   Dot product   Quaternion type
#PL.2FI
PL/I
/* dot product, cross product, etc. 4 June 2011 */   test_products: procedure options (main);   declare a(3) fixed initial (3, 4, 5); declare b(3) fixed initial (4, 3, 5); declare c(3) fixed initial (-5, -12, -13); declare e(3) fixed;   put skip list ('a . b =', dot_product(a, b)); call cross_product(a, b, e); put skip list ('a x b =', e); put skip list ('a . (b x c) =', scalar_triple_product(a, b, c)); call vector_triple_product(a, b, c, e); put skip list ('a x (b x c) =', e);     dot_product: procedure (a, b) returns (fixed); declare (a, b) (*) fixed; return (sum(a*b)); end dot_product;   cross_product: procedure (a, b, c); declare (a, b, c) (*) fixed; c(1) = a(2)*b(3) - a(3)*b(2); c(2) = a(3)*b(1) - a(1)*b(3); c(3) = a(1)*b(2) - a(2)*b(1); end cross_product;   scalar_triple_product: procedure (a, b, c) returns (fixed); declare (a, b, c)(*) fixed; declare t(hbound(a, 1)) fixed; call cross_product(b, c, t); return (dot_product(a, t)); end scalar_triple_product;   vector_triple_product: procedure (a, b, c, e); declare (a, b, c, e)(*) fixed; declare t(hbound(a,1)) fixed; call cross_product(b, c, t); call cross_product(a, t, e); end vector_triple_product;   end test_products;
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Robotic
Robotic
  input string "Enter string:" set "$str" to "input" input string "Enter number:" set "number" to "input" [ "You entered:" [ "&$str&" [ "&number&" end  
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Ruby
Ruby
print "Enter a string: " s = gets printf "Enter an integer: " i = gets.to_i # If string entered, will return zero printf "Enter a real number: " f = Float(gets) rescue nil # converts a floating point number or returns nil puts "String = #{s}" puts "Integer = #{i}" puts "Float = #{f}"
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#WDTE
WDTE
let example t => io.writeln io.stdout t;
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#Wren
Wren
var a // declares the variable 'a' with the default value of 'null' a = 1 // initializes 'a' a = "a" // assigns a different value to 'a' var b = 2 // declares and initializes 'b' at the same time b = true // assigns a different value to 'b' var c = [3, 4] // 'c' is assigned a List which is a reference type c = false // 'c' is reassigned a Bool which is a value type   var d = 1 // declaration at top level { var d = 2 // declaration within a nested scope, hides top level 'd' var e = 3 // not visible outside its scope i.e this block } System.print(d) // prints the value of the top level 'd' System.print(e) // compiler error : Variable is used but not defined
http://rosettacode.org/wiki/Undefined_values
Undefined values
#ERRE
ERRE
42 .  ! 42
http://rosettacode.org/wiki/Undefined_values
Undefined values
#Factor
Factor
42 .  ! 42
http://rosettacode.org/wiki/Unicode_strings
Unicode strings
As the world gets smaller each day, internationalization becomes more and more important.   For handling multiple languages, Unicode is your best friend. It is a very capable tool, but also quite complex compared to older single- and double-byte character encodings. How well prepared is your programming language for Unicode? Task Discuss and demonstrate its unicode awareness and capabilities. Some suggested topics:   How easy is it to present Unicode strings in source code?   Can Unicode literals be written directly, or be part of identifiers/keywords/etc?   How well can the language communicate with the rest of the world?   Is it good at input/output with Unicode?   Is it convenient to manipulate Unicode strings in the language?   How broad/deep does the language support Unicode?   What encodings (e.g. UTF-8, UTF-16, etc) can be used?   Does it support normalization? Note This task is a bit unusual in that it encourages general discussion rather than clever coding. See also   Unicode variable names   Terminal control/Display an extended character
#11l
11l
#!/usr/local/bin/a68g --script # # -*- coding: utf-8 -*- #   # UNICHAR/UNICODE must be printed using REPR to convert to UTF8 #   MODE UNICHAR = STRUCT(BITS #31# bits); # assuming bits width >=31 # MODE UNICODE = FLEX[0]UNICHAR;   OP INITUNICHAR = (BITS bits)UNICHAR: (UNICHAR out; bits OF out := #ABS# bits; out); OP INITUNICHAR = (CHAR char)UNICHAR: (UNICHAR out; bits OF out := BIN ABS char; out); OP INITBITS = (UNICHAR unichar)BITS: #BIN# bits OF unichar;   PROC raise value error = ([]UNION(FORMAT,BITS,STRING)argv )VOID: ( putf(stand error, argv); stop );   MODE YIELDCHAR = PROC(CHAR)VOID; MODE GENCHAR = PROC(YIELDCHAR)VOID; MODE YIELDUNICHAR = PROC(UNICHAR)VOID; MODE GENUNICHAR = PROC(YIELDUNICHAR)VOID;   PRIO DOCONV = 1;   # Convert a stream of UNICHAR into a stream of UTFCHAR # OP DOCONV = (GENUNICHAR gen unichar, YIELDCHAR yield)VOID:( BITS non ascii = NOT 2r1111111; # FOR UNICHAR unichar IN # gen unichar( # ) DO ( # ## (UNICHAR unichar)VOID: ( BITS bits := INITBITS unichar; IF (bits AND non ascii) = 2r0 THEN # ascii # yield(REPR ABS bits) ELSE FLEX[6]CHAR buf := "?"*6; # initialise work around # INT bytes := 0; BITS byte lead bits = 2r10000000; FOR ofs FROM UPB buf BY -1 WHILE bytes +:= 1; buf[ofs]:= REPR ABS (byte lead bits OR bits AND 2r111111); bits := bits SHR 6; # WHILE # bits NE 2r0 DO SKIP OD; BITS first byte lead bits = BIN (ABS(2r1 SHL bytes)-2) SHL (UPB buf - bytes + 1); buf := buf[UPB buf-bytes+1:]; buf[1] := REPR ABS(BIN ABS buf[1] OR first byte lead bits); FOR i TO UPB buf DO yield(buf[i]) OD FI # OD # )) );   # Convert a STRING into a stream of UNICHAR # OP DOCONV = (STRING string, YIELDUNICHAR yield)VOID: ( PROC gen char = (YIELDCHAR yield)VOID: FOR i FROM LWB string TO UPB string DO yield(string[i]) OD; gen char DOCONV yield );   CO Prosser/Thompson UTF8 encoding scheme Bits Last code point Byte 1 Byte 2 Byte 3 Byte 4 Byte 5 Byte 6 7 U+007F 0xxxxxxx 11 U+07FF 110xxxxx 10xxxxxx 16 U+FFFF 1110xxxx 10xxxxxx 10xxxxxx 21 U+1FFFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx 26 U+3FFFFFF 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 31 U+7FFFFFFF 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx END CO   # Quickly calculate the length of the UTF8 encoded string # PROC upb utf8 = (STRING utf8 string)INT:( INT bytes to go := 0; INT upb := 0; FOR i FROM LWB utf8 string TO UPB utf8 string DO CHAR byte := utf8 string[i]; IF bytes to go = 0 THEN # start new utf char # bytes to go := IF ABS byte <= ABS 2r01111111 THEN 1 # 7 bits # ELIF ABS byte <= ABS 2r11011111 THEN 2 # 11 bits # ELIF ABS byte <= ABS 2r11101111 THEN 3 # 16 bits # ELIF ABS byte <= ABS 2r11110111 THEN 4 # 21 bits # ELIF ABS byte <= ABS 2r11111011 THEN 5 # 26 bits # ELIF ABS byte <= ABS 2r11111101 THEN 6 # 31 bits # ELSE raise value error(("Invalid UTF-8 bytes", BIN ABS byte)); ~ FI FI; bytes to go -:= 1; # skip over trailing bytes # IF bytes to go = 0 THEN upb +:= 1 FI OD; upb );   # Convert a stream of CHAR into a stream of UNICHAR # OP DOCONV = (GENCHAR gen char, YIELDUNICHAR yield)VOID: ( INT bytes to go := 0; INT lshift; BITS mask, out;   # FOR CHAR byte IN # gen char( # ) DO ( # ## (CHAR byte)VOID: ( INT bits := ABS byte; IF bytes to go = 0 THEN # start new unichar # bytes to go := IF bits <= ABS 2r01111111 THEN 1 # 7 bits # ELIF bits <= ABS 2r11011111 THEN 2 # 11 bits # ELIF bits <= ABS 2r11101111 THEN 3 # 16 bits # ELIF bits <= ABS 2r11110111 THEN 4 # 21 bits # ELIF bits <= ABS 2r11111011 THEN 5 # 26 bits # ELIF bits <= ABS 2r11111101 THEN 6 # 31 bits # ELSE raise value error(("Invalid UTF-8 bytes", BIN bits)); ~ FI; IF bytes to go = 1 THEN lshift := 7; mask := 2r1111111 ELSE lshift := 7 - bytes to go; mask := BIN(ABS(2r1 SHL lshift)-1) FI; out := mask AND BIN bits;   lshift := 6; mask := 2r111111 # subsequently pic 6 bits at a time # ELSE out := (out SHL lshift) OR ( mask AND BIN bits) FI; bytes to go -:= 1; IF bytes to go = 0 THEN yield(INITUNICHAR out) FI # OD # )) );   # Convert a string of UNICHAR into a stream of UTFCHAR # OP DOCONV = (UNICODE unicode, YIELDCHAR yield)VOID:( PROC gen unichar = (YIELDUNICHAR yield)VOID: FOR i FROM LWB unicode TO UPB unicode DO yield(unicode[i]) OD; gen unichar DOCONV yield );   # Some convenience/shorthand U operators # # Convert a BITS into a UNICODE char # OP U = (BITS bits)UNICHAR: INITUNICHAR bits;   # Convert a []BITS into a UNICODE char # OP U = ([]BITS array bits)[]UNICHAR:( [LWB array bits:UPB array bits]UNICHAR out; FOR i FROM LWB array bits TO UPB array bits DO bits OF out[i]:=array bits[i] OD; out );   # Convert a CHAR into a UNICODE char # OP U = (CHAR char)UNICHAR: INITUNICHAR char;   # Convert a STRING into a UNICODE string # OP U = (STRING utf8 string)UNICODE: ( FLEX[upb utf8(utf8 string)]UNICHAR out; INT i := 0; # FOR UNICHAR char IN # utf8 string DOCONV ( ## (UNICHAR char)VOID: out[i+:=1] := char # OD #); out );   # Convert a UNICODE string into a UTF8 STRING # OP REPR = (UNICODE string)STRING: ( STRING out; # FOR CHAR char IN # string DOCONV ( ## (CHAR char)VOID: ( out +:= char # OD #)); out );   # define the most useful OPerators on UNICODE CHARacter arrays # # Note: LWB, UPB and slicing works as per normal #   OP + = (UNICODE a,b)UNICODE: ( [UPB a + UPB b]UNICHAR out; out[:UPB a]:= a; out[UPB a+1:]:= b; out );   OP + = (UNICODE a, UNICHAR b)UNICODE: a+UNICODE(b); OP + = (UNICHAR a, UNICODE b)UNICODE: UNICODE(a)+b; OP + = (UNICHAR a,b)UNICODE: UNICODE(a)+b;   # Suffix a character to the end of a UNICODE string # OP +:= = (REF UNICODE a, UNICODE b)VOID: a := a + b; OP +:= = (REF UNICODE a, UNICHAR b)VOID: a := a + b;   # Prefix a character to the beginning of a UNICODE string # OP +=: = (UNICODE b, REF UNICODE a)VOID: a := b + a; OP +=: = (UNICHAR b, REF UNICODE a)VOID: a := b + a;   OP * = (UNICODE a, INT n)UNICODE: ( UNICODE out := a; FOR i FROM 2 TO n DO out +:= a OD; out ); OP * = (INT n, UNICODE a)UNICODE: a * n;   OP * = (UNICHAR a, INT n)UNICODE: UNICODE(a)*n; OP * = (INT n, UNICHAR a)UNICODE: n*UNICODE(a);   OP *:= = (REF UNICODE a, INT b)VOID: a := a * b;   # Wirthy Operators # OP LT = (UNICHAR a,b)BOOL: ABS bits OF a LT ABS bits OF b, LE = (UNICHAR a,b)BOOL: ABS bits OF a LE ABS bits OF b, EQ = (UNICHAR a,b)BOOL: ABS bits OF a EQ ABS bits OF b, NE = (UNICHAR a,b)BOOL: ABS bits OF a NE ABS bits OF b, GE = (UNICHAR a,b)BOOL: ABS bits OF a GE ABS bits OF b, GT = (UNICHAR a,b)BOOL: ABS bits OF a GT ABS bits OF b;   # ASCII OPerators # OP < = (UNICHAR a,b)BOOL: a LT b, <= = (UNICHAR a,b)BOOL: a LE b, = = (UNICHAR a,b)BOOL: a EQ b, /= = (UNICHAR a,b)BOOL: a NE b, >= = (UNICHAR a,b)BOOL: a GE b, > = (UNICHAR a,b)BOOL: a GT b;   # Non ASCII OPerators OP ≤ = (UNICHAR a,b)BOOL: a LE b, ≠ = (UNICHAR a,b)BOOL: a NE b, ≥ = (UNICHAR a,b)BOOL: a GE b; #   # Compare two UNICODE strings for equality # PROC unicode cmp = (UNICODE str a,str b)INT: (   IF LWB str a > LWB str b THEN exit lt ELIF LWB str a < LWB str b THEN exit gt FI;   INT min upb = UPB(UPB str a < UPB str b | str a | str b );   FOR i FROM LWB str a TO min upb DO UNICHAR a := str a[i], UNICHAR b := str b[i]; IF a < b THEN exit lt ELIF a > b THEN exit gt FI OD;   IF UPB str a > UPB str b THEN exit gt ELIF UPB str a < UPB str b THEN exit lt FI;   exit eq: 0 EXIT exit lt: -1 EXIT exit gt: 1 );   OP LT = (UNICODE a,b)BOOL: unicode cmp(a,b)< 0, LE = (UNICODE a,b)BOOL: unicode cmp(a,b)<=0, EQ = (UNICODE a,b)BOOL: unicode cmp(a,b) =0, NE = (UNICODE a,b)BOOL: unicode cmp(a,b)/=0, GE = (UNICODE a,b)BOOL: unicode cmp(a,b)>=0, GT = (UNICODE a,b)BOOL: unicode cmp(a,b)> 0;   # ASCII OPerators # OP < = (UNICODE a,b)BOOL: a LT b, <= = (UNICODE a,b)BOOL: a LE b, = = (UNICODE a,b)BOOL: a EQ b, /= = (UNICODE a,b)BOOL: a NE b, >= = (UNICODE a,b)BOOL: a GE b, > = (UNICODE a,b)BOOL: a GT b;   # Non ASCII OPerators OP ≤ = (UNICODE a,b)BOOL: a LE b, ≠ = (UNICODE a,b)BOOL: a NE b, ≥ = (UNICODE a,b)BOOL: a GE b; #   COMMENT - Todo: for all UNICODE and UNICHAR Add NonASCII OPerators: ×, ×:=, Add ASCII Operators: &, &:=, &=: Add Wirthy OPerators: PLUSTO, PLUSAB, TIMESAB for UNICODE/UNICHAR, Add UNICODE against UNICHAR comparison OPerators, Add char_in_string and string_in_string PROCedures, Add standard Unicode functions: to_upper_case, to_lower_case, unicode_block, char_count, get_directionality, get_numeric_value, get_type, is_defined, is_digit, is_identifier_ignorable, is_iso_control, is_letter, is_letter_or_digit, is_lower_case, is_mirrored, is_space_char, is_supplementary_code_point, is_title_case, is_unicode_identifier_part, is_unicode_identifier_start, is_upper_case, is_valid_code_point, is_whitespace END COMMENT   test:(   UNICHAR aircraft := U16r 2708; printf(($"aircraft: "$, $"16r"16rdddd$, UNICODE(aircraft), $g$, " => ", REPR UNICODE(aircraft), $l$));   UNICODE chinese forty two = U16r 56db + U16r 5341 + U16r 4e8c; printf(($"chinese forty two: "$, $g$, REPR chinese forty two, ", length string = ", UPB chinese forty two, $l$));   UNICODE poker = U "A123456789♥♦♣♠JQK"; printf(($"poker: "$, $g$, REPR poker, ", length string = ", UPB poker, $l$));   UNICODE selectric := U"×÷≤≥≠¬∨∧⏨→↓↑□⌊⌈⎩⎧○⊥¢"; printf(($"selectric: "$, $g$, REPR selectric, $l$)); printf(($"selectric*4: "$, $g$, REPR(selectric*4), $l$));   print(( "1 < 2 is ", U"1" < U"2", ", ", "111 < 11 is ",U"111" < U"11", ", ", "111 < 12 is ",U"111" < U"12", ", ", "♥ < ♦ is ", U"♥" < U"♦", ", ", "♥Q < ♥K is ",U"♥Q" < U"♥K", " & ", "♥J < ♥K is ",U"♥J" < U"♥K", new line ))   )
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identifiers
#ALGOL_68
ALGOL 68
set |Δ| to 1 set |Δ| to |Δ| + 1 return |Δ|
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identifiers
#AppleScript
AppleScript
set |Δ| to 1 set |Δ| to |Δ| + 1 return |Δ|
http://rosettacode.org/wiki/Unicode_variable_names
Unicode variable names
Task Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables. Show how to: Set a variable with a name including the 'Δ', (delta character), to 1 Increment it Print its value. Related task Case-sensitivity of identifiers
#Arturo
Arturo
"Δ": 1 "Δ": inc var "Δ"   print ["Delta =>" var "Δ"]
http://rosettacode.org/wiki/Unix/ls
Unix/ls
Task Write a program that will list everything in the current folder,   similar to:   the Unix utility   “ls”   [1]       or   the Windows terminal command   “DIR” The output must be sorted, but printing extended details and producing multi-column output is not required. Example output For the list of paths: /foo/bar /foo/bar/1 /foo/bar/2 /foo/bar/a /foo/bar/b When the program is executed in   `/foo`,   it should print: bar and when the program is executed in   `/foo/bar`,   it should print: 1 2 a b
#C
C
  #include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include <sys/types.h> #include <dirent.h> #include <unistd.h>   int cmpstr(const void *a, const void *b) { return strcmp(*(const char**)a, *(const char**)b); }   int main(void) { DIR *basedir; char path[PATH_MAX]; struct dirent *entry; char **dirnames; int diralloc = 128; int dirsize = 0;   if (!(dirnames = malloc(diralloc * sizeof(char*)))) { perror("malloc error:"); return 1; }   if (!getcwd(path, PATH_MAX)) { perror("getcwd error:"); return 1; }   if (!(basedir = opendir(path))) { perror("opendir error:"); return 1; }   while ((entry = readdir(basedir))) { if (dirsize >= diralloc) { diralloc *= 2; if (!(dirnames = realloc(dirnames, diralloc * sizeof(char*)))) { perror("realloc error:"); return 1; } } dirnames[dirsize++] = strdup(entry->d_name); }   qsort(dirnames, dirsize, sizeof(char*), cmpstr);   int i; for (i = 0; i < dirsize; ++i) { if (dirnames[i][0] != '.') { printf("%s\n", dirnames[i]); } }   for (i = 0; i < dirsize; ++i) free(dirnames[i]); free(dirnames); closedir(basedir); return 0; }  
http://rosettacode.org/wiki/Vector_products
Vector products
A vector is defined as having three dimensions as being represented by an ordered collection of three numbers:   (X, Y, Z). If you imagine a graph with the   x   and   y   axis being at right angles to each other and having a third,   z   axis coming out of the page, then a triplet of numbers,   (X, Y, Z)   would represent a point in the region,   and a vector from the origin to the point. Given the vectors: A = (a1, a2, a3) B = (b1, b2, b3) C = (c1, c2, c3) then the following common vector products are defined: The dot product       (a scalar quantity) A • B = a1b1   +   a2b2   +   a3b3 The cross product       (a vector quantity) A x B = (a2b3  -   a3b2,     a3b1   -   a1b3,     a1b2   -   a2b1) The scalar triple product       (a scalar quantity) A • (B x C) The vector triple product       (a vector quantity) A x (B x C) Task Given the three vectors: a = ( 3, 4, 5) b = ( 4, 3, 5) c = (-5, -12, -13) Create a named function/subroutine/method to compute the dot product of two vectors. Create a function to compute the cross product of two vectors. Optionally create a function to compute the scalar triple product of three vectors. Optionally create a function to compute the vector triple product of three vectors. Compute and display: a • b Compute and display: a x b Compute and display: a • (b x c), the scalar triple product. Compute and display: a x (b x c), the vector triple product. References   A starting page on Wolfram MathWorld is   Vector Multiplication .   Wikipedia   dot product.   Wikipedia   cross product.   Wikipedia   triple product. Related tasks   Dot product   Quaternion type
#Plain_English
Plain English
To run: Start up. Make a vector from 3 and 4 and 5. Make another vector from 4 and 3 and 5. Make a third vector from -5 and -12 and -13. Write "A vector: " then the vector on the console. Write "Another vector: " then the other vector on the console. Write "A third vector: " then the third vector on the console. Write "" on the console. Compute a dot product of the vector and the other vector. Write "Dot product between the vector and the other vector: " then the dot product on the console. Compute a cross product of the vector and the other vector. Write "Cross product between the vector and the other vector: " then the cross product on the console. Compute a scalar triple product of the vector and the other vector and the third vector. Write "Scalar triple product between the vector and the other vector and the third vector: " then the scalar triple product on the console. Compute a vector triple product of the vector and the other vector and the third vector. Write "Vector triple product between the vector and the other vector and the third vector: " then the vector triple product on the console. Wait for the escape key. Shut down.   A vector has a first number, a second number, and a third number.   To make a vector from a first number and a second number and a third number: Put the first into the vector's first. Put the second into the vector's second. Put the third into the vector's third.   To put a vector into another vector: Put the vector's first into the other vector's first. Put the vector's second into the other vector's second. Put the vector's third into the other vector's third.   To convert a vector into a string: Append "(" then the vector's first then ", " then the vector's second then ", " then the vector's third then ")" to the string.   A dot product is a number.   To compute a dot product of a vector and another vector: Put the vector's first times the other vector's first into a first number. Put the vector's second times the other vector's second into a second number. Put the vector's third times the other vector's third into a third number. Put the first plus the second plus the third into the dot product.   A cross product is a vector.   To compute a cross product of a vector and another vector: Put the vector's second times the other vector's third into a first number. Put the vector's third times the other vector's second into a second number. Put the vector's third times the other vector's first into a third number. Put the vector's first times the other vector's third into a fourth number. Put the vector's first times the other vector's second into a fifth number. Put the vector's second times the other vector's first into a sixth number. Make a result vector from the first minus the second and the third minus the fourth and the fifth minus the sixth. Put the result into the cross product.   A scalar triple product is a number.   To compute a scalar triple product of a vector and another vector and a third vector: Compute a cross product of the other vector and the third vector. Compute a dot product of the vector and the cross product. Put the dot product into the scalar triple product.   A vector triple product is a vector.   To compute a vector triple product of a vector and another vector and a third vector: Compute a cross product of the other vector and the third vector. Compute another cross product of the vector and the cross product. Put the other cross product into the vector triple product.
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Rust
Rust
use std::io::{self, Write}; use std::fmt::Display; use std::process;   fn main() { let s = grab_input("Give me a string") .unwrap_or_else(|e| exit_err(&e, e.raw_os_error().unwrap_or(-1)));   println!("You entered: {}", s.trim());   let n: i32 = grab_input("Give me an integer") .unwrap_or_else(|e| exit_err(&e, e.raw_os_error().unwrap_or(-1))) .trim() .parse() .unwrap_or_else(|e| exit_err(&e, 2));   println!("You entered: {}", n); }   fn grab_input(msg: &str) -> io::Result<String> { let mut buf = String::new(); print!("{}: ", msg); try!(io::stdout().flush());   try!(io::stdin().read_line(&mut buf)); Ok(buf) }   fn exit_err<T: Display>(msg: T, code: i32) -> ! { let _ = writeln!(&mut io::stderr(), "Error: {}", msg); process::exit(code) }
http://rosettacode.org/wiki/User_input/Text
User input/Text
User input/Text is part of Short Circuit's Console Program Basics selection. Task Input a string and the integer   75000   from the text console. See also: User input/Graphical
#Scala
Scala
print("Enter a number: ") val i=Console.readLong // Task says to enter 75000 print("Enter a string: ") val s=Console.readLine
http://rosettacode.org/wiki/Variables
Variables
Task Demonstrate a language's methods of:   variable declaration   initialization   assignment   datatypes   scope   referencing,     and   other variable related facilities
#XPL0
XPL0
There are only three variable types: 32-bit signed integers (in the 32-bit version), IEEE-754 64-bit reals, and characters which are actually 32-bit addresses of (or pointers to) strings. When a 'char' variable is subscripted, it accesses a single byte. All variable names must be declared before they are used, for example: int I, J, K; real X, Y, Array(10); char String(80); Variables (as well as all declared names, such as for procedures) must start with a capital letter or underline. Names may contain digits or underlines and be any length, but only the first 16 characters are significant. Names are case-insensitive by default, unless the /c switch is used when compiling. Variables are usually assigned values like this: X:= 3.14, but the first declared variables in a procedure can have argument values passed into them. Variables other than arguments are only initialized by explicit assignments in the body of the code. Local variables are encapsulated in the procedures that declare them and are not visible (are out of scope) outside those procedures. Procedures can be (statically) nested several levels deep. The deepest procedure can "see" all variables declared in the procedures in which it is nested. If two variables are declared with identical names, the most local one is used.