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 repr...
#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, ...
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 repr...
#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  ...
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; Sett...
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 repr...
#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 ::meth...
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 str...
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 repr...
#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] )   //...
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] )   //...
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;...
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 repr...
#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; ...
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("Yo...
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 St...
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 ...
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 repr...
#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}; ...
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 repr...
#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 fu...
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: ") (defi...
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:...
#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 repr...
#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 ...
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 stri...
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 ...
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:...
#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, f...
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:...
#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 repr...
#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 typ...
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 ...
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. # bo...
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 '...
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]   // U...
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:...
#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.Gen...
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:...
#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 repr...
#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...
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 identif...
#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:...
#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:...
#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 repr...
#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 vectorTrip...
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_r...
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 identif...
#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 identif...
#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 identif...
#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:...
#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 T...
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:...
#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 repr...
#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)); ca...
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 L...
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 ...
#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 INI...
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 identif...
#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 identif...
#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 identif...
#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:...
#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 d...
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 repr...
#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 ...
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_els...
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 exam...