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/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#Racket
Racket
  #lang racket (require net/uri-codec) (uri-decode "http%3A%2F%2Ffoo%20bar%2F")  
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#Raku
Raku
my @urls = < http%3A%2F%2Ffoo%20bar%2F google.com/search?q=%60Abdu%27l-Bah%C3%A1 >;   say .subst( :g, / [ '%' ( <:hexdigit> ** 2 ) ]+ / , { Blob.new((:16(~$_) for $0)).decode } ) for @urls;
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
#Metafont
Metafont
string s; message "write a string: "; s := readstring; message s; message "write a number now: "; b := scantokens readstring; if b = 750: message "You've got it!" else: message "Sorry..." fi; 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
#min
min
"Enter a string" ask "Enter an integer" ask int
http://rosettacode.org/wiki/User_input/Graphical
User input/Graphical
In this task, the goal is to input a string and the integer 75000, from graphical user interface. See also: User input/Text
#Run_BASIC
Run BASIC
html "<TABLE BORDER=1 BGCOLOR=silver> <TR><TD colspan=2>Please input a string and a number</TD></TR>   <TR><TD align=right>String</TD><TD><input type=text name=str size=18></TD></TR> <TR><TD align=right>Number</TD><TD><input type=number name=num size=18 value=75000></TD></TR>   <TR><TD colspan=2 align=center>"   button #go, "Accept", [go] button #ex, "Exit", [ex]   html "</TD></TR></TABLE>" Wait   [go] print #request get$("str") print val(#request get$("num")) wait   [ex] end
http://rosettacode.org/wiki/User_input/Graphical
User input/Graphical
In this task, the goal is to input a string and the integer 75000, from graphical user interface. See also: User input/Text
#Scala
Scala
import swing.Dialog.{Message, showInput} import scala.swing.Swing   object UserInput extends App { def responce = showInput(null, "Complete the sentence:\n\"Green eggs and...\"", "Customized Dialog", Message.Plain, Swing.EmptyIcon, Nil, "ham") println(responce) }
http://rosettacode.org/wiki/URL_encoding
URL encoding
Task Provide a function or mechanism to convert a provided string into URL encoding representation. In URL encoding, special characters, control characters and extended characters are converted into a percent symbol followed by a two digit hexadecimal code, So a space character encodes into %20 within the string. For the purposes of this task, every character except 0-9, A-Z and a-z requires conversion, so the following characters all require conversion by default: ASCII control codes (Character ranges 00-1F hex (0-31 decimal) and 7F (127 decimal). ASCII symbols (Character ranges 32-47 decimal (20-2F hex)) ASCII symbols (Character ranges 58-64 decimal (3A-40 hex)) ASCII symbols (Character ranges 91-96 decimal (5B-60 hex)) ASCII symbols (Character ranges 123-126 decimal (7B-7E hex)) Extended characters with character codes of 128 decimal (80 hex) and above. Example The string "http://foo bar/" would be encoded as "http%3A%2F%2Ffoo%20bar%2F". Variations Lowercase escapes are legal, as in "http%3a%2f%2ffoo%20bar%2f". Some standards give different rules: RFC 3986, Uniform Resource Identifier (URI): Generic Syntax, section 2.3, says that "-._~" should not be encoded. HTML 5, section 4.10.22.5 URL-encoded form data, says to preserve "-._*", and to encode space " " to "+". The options below provide for utilization of an exception string, enabling preservation (non encoding) of particular characters to meet specific standards. Options It is permissible to use an exception string (containing a set of symbols that do not need to be converted). However, this is an optional feature and is not a requirement of this task. Related tasks   URL decoding   URL parser
#Rust
Rust
const INPUT: &str = "http://foo bar/"; const MAX_CHAR_VAL: u32 = std::char::MAX as u32;   fn main() { let mut buff = [0; 4]; println!("{}", INPUT.chars() .map(|ch| { match ch as u32 { 0 ..= 47 | 58 ..= 64 | 91 ..= 96 | 123 ..= MAX_CHAR_VAL => { ch.encode_utf8(&mut buff); buff[0..ch.len_utf8()].iter().map(|&byte| format!("%{:X}", byte)).collect::<String>() }, _ => ch.to_string(), } }) .collect::<String>() ); }
http://rosettacode.org/wiki/URL_encoding
URL encoding
Task Provide a function or mechanism to convert a provided string into URL encoding representation. In URL encoding, special characters, control characters and extended characters are converted into a percent symbol followed by a two digit hexadecimal code, So a space character encodes into %20 within the string. For the purposes of this task, every character except 0-9, A-Z and a-z requires conversion, so the following characters all require conversion by default: ASCII control codes (Character ranges 00-1F hex (0-31 decimal) and 7F (127 decimal). ASCII symbols (Character ranges 32-47 decimal (20-2F hex)) ASCII symbols (Character ranges 58-64 decimal (3A-40 hex)) ASCII symbols (Character ranges 91-96 decimal (5B-60 hex)) ASCII symbols (Character ranges 123-126 decimal (7B-7E hex)) Extended characters with character codes of 128 decimal (80 hex) and above. Example The string "http://foo bar/" would be encoded as "http%3A%2F%2Ffoo%20bar%2F". Variations Lowercase escapes are legal, as in "http%3a%2f%2ffoo%20bar%2f". Some standards give different rules: RFC 3986, Uniform Resource Identifier (URI): Generic Syntax, section 2.3, says that "-._~" should not be encoded. HTML 5, section 4.10.22.5 URL-encoded form data, says to preserve "-._*", and to encode space " " to "+". The options below provide for utilization of an exception string, enabling preservation (non encoding) of particular characters to meet specific standards. Options It is permissible to use an exception string (containing a set of symbols that do not need to be converted). However, this is an optional feature and is not a requirement of this task. Related tasks   URL decoding   URL parser
#Scala
Scala
import java.net.{URLDecoder, URLEncoder} import scala.compat.Platform.currentTime   object UrlCoded extends App { val original = """http://foo bar/""" val encoded: String = URLEncoder.encode(original, "UTF-8")   assert(encoded == "http%3A%2F%2Ffoo+bar%2F", s"Original: $original not properly encoded: $encoded")   val percentEncoding = encoded.replace("+", "%20") assert(percentEncoding == "http%3A%2F%2Ffoo%20bar%2F", s"Original: $original not properly percent-encoded: $percentEncoding")   assert(URLDecoder.decode(encoded, "UTF-8") == URLDecoder.decode(percentEncoding, "UTF-8"))   println(s"Successfully completed without errors. [total ${currentTime - executionStart} ms]") }
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
#OxygenBasic
OxygenBasic
  'WAYS OF DECLARING VARIABLES 'AND ASSIGNING VALUES var int a,b,c,d int a=1,b=2,c=3,d=4 dim int a=1,b=2, c=3, d=4 dim as int a=1,b=2, c=3, d=4 dim a=1,b=2, c=3, d=4 as int print c '3   'CREATING ARRAY VARIABLES int array[100] dim int a={10,20,30,40} 'implicit array print a[3] '30   'COMMONLY USED TYPES: 'byte word int sys float char string   'LIMITING SCOPE dim int a=10 scope dim int a=100 dim int b=1000 print a '100 end scope print a 'prior a: 10 print b 'error b is out of scope   'REFERENCING VARIABLES dim int*p 'p is a pointer variable dim int a={2,4,6,8} @p=@a[3] 'address of p is assigned address of a[3] print @p 'the address print p '6 print p[1] '6 print p[2] '8  
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
#Oz
Oz
declare Var %% new variable Var, initially free {Show Var} Var = 42 %% now Var has the value 42 {Show Var} Var = 42 %% the same value is assigned again: ok Var = 43 %% a different value is assigned: exception
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
#Maple
Maple
with(LinearAlgebra): A := Vector([3,4,5]): B := Vector([4,3,5]): C := Vector([-5,-12,-13]): >>>A.B; 49 >>>CrossProduct(A,B); Vector([5, 5, -7]) >>>A.(CrossProduct(B,C)); 6 >>>CrossProduct(A,CrossProduct(B,C)); Vector([-267, 204, -3])
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#Red
Red
>> dehex "http%3A%2F%2Ffoo%20bar%2F" == "http://foo bar/" >> dehex "google.com/search?q=%60Abdu%27l-Bah%C3%A1" == "google.com/search?q=`Abdu'l-Bahá"
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#Retro
Retro
create buffer 32000 allot   {{ create bit 5 allot  : extract ( $c-$a ) drop @+ bit ! @+ bit 1+ ! bit ;  : render ( $c-$n ) dup '+ = [ drop 32 ] ifTrue dup 13 = [ drop 32 ] ifTrue dup 10 = [ drop 32 ] ifTrue dup '% = [ extract hex toNumber decimal ] ifTrue ;  : <decode> ( $-$ ) repeat @+ 0; render ^buffer'add again ; ---reveal---  : decode ( $- ) buffer ^buffer'set <decode> drop ; }}   "http%3A%2F%2Ffoo%20bar%2F" decode buffer puts
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
#Mirah
Mirah
s = System.console.readLine()   puts s
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
#mIRC_Scripting_Language
mIRC Scripting Language
alias askmesomething { echo -a You answered: $input(What's your name?, e) }
http://rosettacode.org/wiki/User_input/Graphical
User input/Graphical
In this task, the goal is to input a string and the integer 75000, from graphical user interface. See also: User input/Text
#Scratch
Scratch
var gtk2 = require('Gtk2') -> init;   var gui = %s'Gtk2::Builder'.new; gui.add_from_string(DATA.slurp);   func clicked_ok(*_) { var entry = gui.get_object('entry1'); var text = entry.get_text;   var spinner = gui.get_object('spinbutton1'); var number = spinner.get_text;   say "string: #{text}"; say "number: #{number}";   number == 75000 ? gtk2.main_quit : warn "Invalid number!"; }   func clicked_cancel(*_) { gtk2.main_quit; }   gui.get_object('button1').signal_connect('clicked', clicked_ok); gui.get_object('button2').signal_connect('clicked', clicked_cancel);   gtk2.main;   __DATA__ <?xml version="1.0" encoding="UTF-8"?> <interface> <requires lib="gtk+" version="2.24"/> <!-- interface-naming-policy project-wide --> <object class="GtkAdjustment" id="adjustment1"> <property name="upper">100000</property> <property name="value">75000</property> <property name="step_increment">1</property> <property name="page_increment">10</property> </object> <object class="GtkWindow" id="window1"> <property name="visible">True</property> <property name="can_focus">False</property> <child> <object class="GtkVBox" id="vbox1"> <property name="visible">True</property> <property name="can_focus">False</property> <child> <object class="GtkLabel" id="label1"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">Please insert a string and a number:</property> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">0</property> </packing> </child> <child> <object class="GtkHBox" id="hbox1"> <property name="visible">True</property> <property name="can_focus">False</property> <child> <object class="GtkLabel" id="label2"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">string:</property> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="padding">55</property> <property name="position">0</property> </packing> </child> <child> <object class="GtkEntry" id="entry1"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="invisible_char">•</property> <property name="primary_icon_activatable">False</property> <property name="secondary_icon_activatable">False</property> <property name="primary_icon_sensitive">True</property> <property name="secondary_icon_sensitive">True</property> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">1</property> </packing> </child> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">1</property> </packing> </child> <child> <object class="GtkHBox" id="hbox2"> <property name="visible">True</property> <property name="can_focus">False</property> <child> <object class="GtkLabel" id="label3"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">number:</property> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">0</property> </packing> </child> <child> <object class="GtkSpinButton" id="spinbutton1"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="invisible_char">•</property> <property name="primary_icon_activatable">False</property> <property name="secondary_icon_activatable">False</property> <property name="primary_icon_sensitive">True</property> <property name="secondary_icon_sensitive">True</property> <property name="adjustment">adjustment1</property> <property name="numeric">True</property> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">1</property> </packing> </child> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">2</property> </packing> </child> <child> <object class="GtkHButtonBox" id="hbuttonbox1"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="layout_style">spread</property> <child> <object class="GtkButton" id="button1"> <property name="label">gtk-ok</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <property name="use_stock">True</property> </object> <packing> <property name="expand">False</property> <property name="fill">False</property> <property name="position">0</property> </packing> </child> <child> <object class="GtkButton" id="button2"> <property name="label">gtk-cancel</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <property name="use_stock">True</property> </object> <packing> <property name="expand">False</property> <property name="fill">False</property> <property name="position">1</property> </packing> </child> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">3</property> </packing> </child> </object> </child> </object> </interface>
http://rosettacode.org/wiki/URL_encoding
URL encoding
Task Provide a function or mechanism to convert a provided string into URL encoding representation. In URL encoding, special characters, control characters and extended characters are converted into a percent symbol followed by a two digit hexadecimal code, So a space character encodes into %20 within the string. For the purposes of this task, every character except 0-9, A-Z and a-z requires conversion, so the following characters all require conversion by default: ASCII control codes (Character ranges 00-1F hex (0-31 decimal) and 7F (127 decimal). ASCII symbols (Character ranges 32-47 decimal (20-2F hex)) ASCII symbols (Character ranges 58-64 decimal (3A-40 hex)) ASCII symbols (Character ranges 91-96 decimal (5B-60 hex)) ASCII symbols (Character ranges 123-126 decimal (7B-7E hex)) Extended characters with character codes of 128 decimal (80 hex) and above. Example The string "http://foo bar/" would be encoded as "http%3A%2F%2Ffoo%20bar%2F". Variations Lowercase escapes are legal, as in "http%3a%2f%2ffoo%20bar%2f". Some standards give different rules: RFC 3986, Uniform Resource Identifier (URI): Generic Syntax, section 2.3, says that "-._~" should not be encoded. HTML 5, section 4.10.22.5 URL-encoded form data, says to preserve "-._*", and to encode space " " to "+". The options below provide for utilization of an exception string, enabling preservation (non encoding) of particular characters to meet specific standards. Options It is permissible to use an exception string (containing a set of symbols that do not need to be converted). However, this is an optional feature and is not a requirement of this task. Related tasks   URL decoding   URL parser
#Seed7
Seed7
$ include "seed7_05.s7i"; include "encoding.s7i";   const proc: main is func begin writeln(toPercentEncoded("http://foo bar/")); writeln(toUrlEncoded("http://foo bar/")); end func;
http://rosettacode.org/wiki/URL_encoding
URL encoding
Task Provide a function or mechanism to convert a provided string into URL encoding representation. In URL encoding, special characters, control characters and extended characters are converted into a percent symbol followed by a two digit hexadecimal code, So a space character encodes into %20 within the string. For the purposes of this task, every character except 0-9, A-Z and a-z requires conversion, so the following characters all require conversion by default: ASCII control codes (Character ranges 00-1F hex (0-31 decimal) and 7F (127 decimal). ASCII symbols (Character ranges 32-47 decimal (20-2F hex)) ASCII symbols (Character ranges 58-64 decimal (3A-40 hex)) ASCII symbols (Character ranges 91-96 decimal (5B-60 hex)) ASCII symbols (Character ranges 123-126 decimal (7B-7E hex)) Extended characters with character codes of 128 decimal (80 hex) and above. Example The string "http://foo bar/" would be encoded as "http%3A%2F%2Ffoo%20bar%2F". Variations Lowercase escapes are legal, as in "http%3a%2f%2ffoo%20bar%2f". Some standards give different rules: RFC 3986, Uniform Resource Identifier (URI): Generic Syntax, section 2.3, says that "-._~" should not be encoded. HTML 5, section 4.10.22.5 URL-encoded form data, says to preserve "-._*", and to encode space " " to "+". The options below provide for utilization of an exception string, enabling preservation (non encoding) of particular characters to meet specific standards. Options It is permissible to use an exception string (containing a set of symbols that do not need to be converted). However, this is an optional feature and is not a requirement of this task. Related tasks   URL decoding   URL parser
#Sidef
Sidef
func urlencode(str) { str.gsub!(%r"([^-A-Za-z0-9_.!~*'() ])", {|a| "%%%02X" % a.ord}); str.gsub!(' ', '+'); return str; }   say urlencode('http://foo bar/');
http://rosettacode.org/wiki/URL_encoding
URL encoding
Task Provide a function or mechanism to convert a provided string into URL encoding representation. In URL encoding, special characters, control characters and extended characters are converted into a percent symbol followed by a two digit hexadecimal code, So a space character encodes into %20 within the string. For the purposes of this task, every character except 0-9, A-Z and a-z requires conversion, so the following characters all require conversion by default: ASCII control codes (Character ranges 00-1F hex (0-31 decimal) and 7F (127 decimal). ASCII symbols (Character ranges 32-47 decimal (20-2F hex)) ASCII symbols (Character ranges 58-64 decimal (3A-40 hex)) ASCII symbols (Character ranges 91-96 decimal (5B-60 hex)) ASCII symbols (Character ranges 123-126 decimal (7B-7E hex)) Extended characters with character codes of 128 decimal (80 hex) and above. Example The string "http://foo bar/" would be encoded as "http%3A%2F%2Ffoo%20bar%2F". Variations Lowercase escapes are legal, as in "http%3a%2f%2ffoo%20bar%2f". Some standards give different rules: RFC 3986, Uniform Resource Identifier (URI): Generic Syntax, section 2.3, says that "-._~" should not be encoded. HTML 5, section 4.10.22.5 URL-encoded form data, says to preserve "-._*", and to encode space " " to "+". The options below provide for utilization of an exception string, enabling preservation (non encoding) of particular characters to meet specific standards. Options It is permissible to use an exception string (containing a set of symbols that do not need to be converted). However, this is an optional feature and is not a requirement of this task. Related tasks   URL decoding   URL parser
#Tcl
Tcl
# Encode all except "unreserved" characters; use UTF-8 for extended chars. # See http://tools.ietf.org/html/rfc3986 §2.4 and §2.5 proc urlEncode {str} { set uStr [encoding convertto utf-8 $str] set chRE {[^-A-Za-z0-9._~\n]}; # Newline is special case! set replacement {%[format "%02X" [scan "\\\0" "%c"]]} return [string map {"\n" "%0A"} [subst [regsub -all $chRE $uStr $replacement]]] }
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
#PARI.2FGP
PARI/GP
'x
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
#Pascal
Pascal
sub dofruit { $fruit='apple'; }   dofruit; print "The fruit is $fruit";
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
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
a={3,4,5}; b={4,3,5}; c={-5,-12,-13}; a.b Cross[a,b] a.Cross[b,c] Cross[a,Cross[b,c]]
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#REXX
REXX
/* Rexx */   Do X = 0 url. = '' X = X + 1; url.0 = X; url.X = 'http%3A%2F%2Ffoo%20bar%2F' X = X + 1; url.0 = X; url.X = 'mailto%3A%22Ivan%20Aim%22%20%3Civan%2Eaim%40email%2Ecom%3E' X = X + 1; url.0 = X; url.X = '%6D%61%69%6C%74%6F%3A%22%49%72%6D%61%20%55%73%65%72%22%20%3C%69%72%6D%61%2E%75%73%65%72%40%6D%61%69%6C%2E%63%6F%6D%3E'   Do u_ = 1 to url.0 Say url.u_ Say DecodeURL(url.u_) Say End u_   Return End Exit   DecodeURL: Procedure Do Parse Arg encoded decoded = '' PCT = '%'   Do while length(encoded) > 0 Parse Var encoded head (PCT) +1 code +2 tail decoded = decoded || head Select When length(strip(code, 'T')) = 2 & datatype(code, 'X') then Do code = x2c(code) decoded = decoded || code End When length(strip(code, 'T')) \= 0 then Do decoded = decoded || PCT tail = code || tail End Otherwise Do Nop End End encoded = tail End   Return decoded End Exit  
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#Ruby
Ruby
require 'cgi' puts CGI.unescape("http%3A%2F%2Ffoo%20bar%2F") # => "http://foo bar/"
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
#Modula-3
Modula-3
MODULE Input EXPORTS Main;   IMPORT IO, Fmt;   VAR string: TEXT; number: INTEGER;   BEGIN IO.Put("Enter a string: "); string := IO.GetLine(); IO.Put("Enter a number: "); number := IO.GetInt(); IO.Put("You entered: " & string & " and " & Fmt.Int(number) & "\n"); END Input.
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
#MUMPS
MUMPS
TXTINP NEW S,N WRITE "Enter a string: " READ S,! WRITE "Enter the number 75000: " READ N,! KILL S,N QUIT
http://rosettacode.org/wiki/User_input/Graphical
User input/Graphical
In this task, the goal is to input a string and the integer 75000, from graphical user interface. See also: User input/Text
#Sidef
Sidef
var gtk2 = require('Gtk2') -> init;   var gui = %s'Gtk2::Builder'.new; gui.add_from_string(DATA.slurp);   func clicked_ok(*_) { var entry = gui.get_object('entry1'); var text = entry.get_text;   var spinner = gui.get_object('spinbutton1'); var number = spinner.get_text;   say "string: #{text}"; say "number: #{number}";   number == 75000 ? gtk2.main_quit : warn "Invalid number!"; }   func clicked_cancel(*_) { gtk2.main_quit; }   gui.get_object('button1').signal_connect('clicked', clicked_ok); gui.get_object('button2').signal_connect('clicked', clicked_cancel);   gtk2.main;   __DATA__ <?xml version="1.0" encoding="UTF-8"?> <interface> <requires lib="gtk+" version="2.24"/> <!-- interface-naming-policy project-wide --> <object class="GtkAdjustment" id="adjustment1"> <property name="upper">100000</property> <property name="value">75000</property> <property name="step_increment">1</property> <property name="page_increment">10</property> </object> <object class="GtkWindow" id="window1"> <property name="visible">True</property> <property name="can_focus">False</property> <child> <object class="GtkVBox" id="vbox1"> <property name="visible">True</property> <property name="can_focus">False</property> <child> <object class="GtkLabel" id="label1"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">Please insert a string and a number:</property> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">0</property> </packing> </child> <child> <object class="GtkHBox" id="hbox1"> <property name="visible">True</property> <property name="can_focus">False</property> <child> <object class="GtkLabel" id="label2"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">string:</property> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="padding">55</property> <property name="position">0</property> </packing> </child> <child> <object class="GtkEntry" id="entry1"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="invisible_char">•</property> <property name="primary_icon_activatable">False</property> <property name="secondary_icon_activatable">False</property> <property name="primary_icon_sensitive">True</property> <property name="secondary_icon_sensitive">True</property> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">1</property> </packing> </child> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">1</property> </packing> </child> <child> <object class="GtkHBox" id="hbox2"> <property name="visible">True</property> <property name="can_focus">False</property> <child> <object class="GtkLabel" id="label3"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">number:</property> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">0</property> </packing> </child> <child> <object class="GtkSpinButton" id="spinbutton1"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="invisible_char">•</property> <property name="primary_icon_activatable">False</property> <property name="secondary_icon_activatable">False</property> <property name="primary_icon_sensitive">True</property> <property name="secondary_icon_sensitive">True</property> <property name="adjustment">adjustment1</property> <property name="numeric">True</property> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">1</property> </packing> </child> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">2</property> </packing> </child> <child> <object class="GtkHButtonBox" id="hbuttonbox1"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="layout_style">spread</property> <child> <object class="GtkButton" id="button1"> <property name="label">gtk-ok</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <property name="use_stock">True</property> </object> <packing> <property name="expand">False</property> <property name="fill">False</property> <property name="position">0</property> </packing> </child> <child> <object class="GtkButton" id="button2"> <property name="label">gtk-cancel</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <property name="use_stock">True</property> </object> <packing> <property name="expand">False</property> <property name="fill">False</property> <property name="position">1</property> </packing> </child> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="position">3</property> </packing> </child> </object> </child> </object> </interface>
http://rosettacode.org/wiki/URL_encoding
URL encoding
Task Provide a function or mechanism to convert a provided string into URL encoding representation. In URL encoding, special characters, control characters and extended characters are converted into a percent symbol followed by a two digit hexadecimal code, So a space character encodes into %20 within the string. For the purposes of this task, every character except 0-9, A-Z and a-z requires conversion, so the following characters all require conversion by default: ASCII control codes (Character ranges 00-1F hex (0-31 decimal) and 7F (127 decimal). ASCII symbols (Character ranges 32-47 decimal (20-2F hex)) ASCII symbols (Character ranges 58-64 decimal (3A-40 hex)) ASCII symbols (Character ranges 91-96 decimal (5B-60 hex)) ASCII symbols (Character ranges 123-126 decimal (7B-7E hex)) Extended characters with character codes of 128 decimal (80 hex) and above. Example The string "http://foo bar/" would be encoded as "http%3A%2F%2Ffoo%20bar%2F". Variations Lowercase escapes are legal, as in "http%3a%2f%2ffoo%20bar%2f". Some standards give different rules: RFC 3986, Uniform Resource Identifier (URI): Generic Syntax, section 2.3, says that "-._~" should not be encoded. HTML 5, section 4.10.22.5 URL-encoded form data, says to preserve "-._*", and to encode space " " to "+". The options below provide for utilization of an exception string, enabling preservation (non encoding) of particular characters to meet specific standards. Options It is permissible to use an exception string (containing a set of symbols that do not need to be converted). However, this is an optional feature and is not a requirement of this task. Related tasks   URL decoding   URL parser
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT text="http://foo bar/" BUILD S_TABLE spez_char="::>/:</::<%:" spez_char=STRINGS (text,spez_char) LOOP/CLEAR c=spez_char c=ENCODE(c,hex),c=concat("%",c),spez_char=APPEND(spez_char,c) ENDLOOP url_encoded=SUBSTITUTE(text,spez_char,0,0,spez_char) print "text: ", text PRINT "encoded: ", url_encoded  
http://rosettacode.org/wiki/URL_encoding
URL encoding
Task Provide a function or mechanism to convert a provided string into URL encoding representation. In URL encoding, special characters, control characters and extended characters are converted into a percent symbol followed by a two digit hexadecimal code, So a space character encodes into %20 within the string. For the purposes of this task, every character except 0-9, A-Z and a-z requires conversion, so the following characters all require conversion by default: ASCII control codes (Character ranges 00-1F hex (0-31 decimal) and 7F (127 decimal). ASCII symbols (Character ranges 32-47 decimal (20-2F hex)) ASCII symbols (Character ranges 58-64 decimal (3A-40 hex)) ASCII symbols (Character ranges 91-96 decimal (5B-60 hex)) ASCII symbols (Character ranges 123-126 decimal (7B-7E hex)) Extended characters with character codes of 128 decimal (80 hex) and above. Example The string "http://foo bar/" would be encoded as "http%3A%2F%2Ffoo%20bar%2F". Variations Lowercase escapes are legal, as in "http%3a%2f%2ffoo%20bar%2f". Some standards give different rules: RFC 3986, Uniform Resource Identifier (URI): Generic Syntax, section 2.3, says that "-._~" should not be encoded. HTML 5, section 4.10.22.5 URL-encoded form data, says to preserve "-._*", and to encode space " " to "+". The options below provide for utilization of an exception string, enabling preservation (non encoding) of particular characters to meet specific standards. Options It is permissible to use an exception string (containing a set of symbols that do not need to be converted). However, this is an optional feature and is not a requirement of this task. Related tasks   URL decoding   URL parser
#UNIX_Shell
UNIX Shell
function urlencode { typeset decoded=$1 encoded= rest= c= typeset rest2= bug='rest2=${rest}'   if [[ -z ${BASH_VERSION} ]]; then # bug /usr/bin/sh HP-UX 11.00 typeset _decoded='xyz%26xyz' rest="${_decoded#?}" c="${_decoded%%${rest}}" if (( ${#c} != 1 )); then typeset qm='????????????????????????????????????????????????????????????????????????' typeset bug='(( ${#rest} > 0 )) && typeset -L${#rest} rest2="${qm}" || rest2=${rest}' fi fi   rest="${decoded#?}" eval ${bug} c="${decoded%%${rest2}}" decoded="${rest}"   while [[ -n ${c} ]]; do case ${c} in [-a-zA-z0-9.]) ;; ' ') c='+' ;; *) c=$(printf "%%%02X" "'$c") ;; esac   encoded="${encoded}${c}"   rest="${decoded#?}" eval ${bug} c="${decoded%%${rest2}}" decoded="${rest}" done   if [[ -n ${BASH_VERSION:-} ]]; then \echo -E "${encoded}" else print -r -- "${encoded}" fi }  
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
#Perl
Perl
sub dofruit { $fruit='apple'; }   dofruit; print "The fruit is $fruit";
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
#Phix
Phix
<-------- object ---------> | | +-atom +-sequence | | +-integer +-string
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
#MATLAB_.2F_Octave
MATLAB / Octave
% Create a named function/subroutine/method to compute the dot product of two vectors. dot(a,b) % Create a function to compute the cross product of two vectors. cross(a,b) % Optionally create a function to compute the scalar triple product of three vectors. dot(a,cross(b,c)) % Optionally create a function to compute the vector triple product of three vectors. cross(a,cross(b,c)) % Compute and display: a • b cross(a,b) % Compute and display: a x b cross(a,b) % Compute and display: a • b x c, the scaler triple product. dot(a,cross(b,c)) % Compute and display: a x b x c, the vector triple product. cross(a,cross(b,c))
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#Rust
Rust
const INPUT1: &str = "http%3A%2F%2Ffoo%20bar%2F"; const INPUT2: &str = "google.com/search?q=%60Abdu%27l-Bah%C3%A1";   fn append_frag(text: &mut String, frag: &mut String) { if !frag.is_empty() { let encoded = frag.chars() .collect::<Vec<char>>() .chunks(2) .map(|ch| { u8::from_str_radix(&ch.iter().collect::<String>(), 16).unwrap() }).collect::<Vec<u8>>(); text.push_str(&std::str::from_utf8(&encoded).unwrap()); frag.clear(); } }   fn decode(text: &str) -> String { let mut output = String::new(); let mut encoded_ch = String::new(); let mut iter = text.chars(); while let Some(ch) = iter.next() { if ch == '%' { encoded_ch.push_str(&format!("{}{}", iter.next().unwrap(), iter.next().unwrap())); } else { append_frag(&mut output, &mut encoded_ch); output.push(ch); } } append_frag(&mut output, &mut encoded_ch); output }   fn main() { println!("{}", decode(INPUT1)); println!("{}", decode(INPUT2)); }
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#Scala
Scala
import java.net.{URLDecoder, URLEncoder} import scala.compat.Platform.currentTime   object UrlCoded extends App { val original = """http://foo bar/""" val encoded: String = URLEncoder.encode(original, "UTF-8")   assert(encoded == "http%3A%2F%2Ffoo+bar%2F", s"Original: $original not properly encoded: $encoded")   val percentEncoding = encoded.replace("+", "%20") assert(percentEncoding == "http%3A%2F%2Ffoo%20bar%2F", s"Original: $original not properly percent-encoded: $percentEncoding")   assert(URLDecoder.decode(encoded, "UTF-8") == URLDecoder.decode(percentEncoding, "UTF-8"))   println(s"Successfully completed without errors. [total ${currentTime - executionStart} ms]") }
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
#Nanoquery
Nanoquery
string = str(input("Enter a string: ")) integer = int(input("Enter an 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
#Neko
Neko
/** User input/Text, in Neko Tectonics: nekoc userinput.neko neko userinput */   var stdin = $loader.loadprim("std@file_stdin", 0)() var file_read_char = $loader.loadprim("std@file_read_char", 1)   /* Read a line from file f into string s returning length without any newline */ var NEWLINE = 10 var readline = function(f, s) { var len = 0 var ch while true { try ch = file_read_char(f) catch a break; if ch == NEWLINE break; if $sset(s, len, ch) == null break; else len += 1 } return $ssub(s, 0, len) }   $print("Enter a line of text, then the number 75000\n")   try { var RECL = 132 var str = $smake(RECL) var userstring = readline(stdin, str) $print(":", userstring, ":\n")   var num = $int(readline(stdin, str)) if num == 75000 $print("Rosetta Code 75000, for the win!\n") else $print("Sorry, need 75000\n") } catch problem $print("Exception: ", problem, "\n")
http://rosettacode.org/wiki/User_input/Graphical
User input/Graphical
In this task, the goal is to input a string and the integer 75000, from graphical user interface. See also: User input/Text
#Standard_ML
Standard ML
open XWindows ; open Motif ;   val store : string list ref = ref [] ;   val inputWindow = fn () => let val shell = XtAppInitialise "" "demo" "top" [] [ XmNwidth 320, XmNheight 100 ] ; val main = XmCreateMainWindow shell "main" [ XmNmappedWhenManaged true ] ; val enter = XmCreateText main "inputarea" [ XmNeditMode XmSINGLE_LINE_EDIT, XmNscrollHorizontal false ] ; val getinp = fn (w,s,t) => ( store := XmTextGetString enter :: !store  ; t ) in   ( XtSetCallbacks enter [ (XmNactivateCallback , getinp) ] XmNarmCallback ; XtManageChild enter ; XtManageChild main  ; XtRealizeWidget shell )   end ;   inputWindow () ;
http://rosettacode.org/wiki/User_input/Graphical
User input/Graphical
In this task, the goal is to input a string and the integer 75000, from graphical user interface. See also: User input/Text
#Tcl
Tcl
# create entry widget: pack [entry .e1]   # read its content: set input [.e get]
http://rosettacode.org/wiki/URL_encoding
URL encoding
Task Provide a function or mechanism to convert a provided string into URL encoding representation. In URL encoding, special characters, control characters and extended characters are converted into a percent symbol followed by a two digit hexadecimal code, So a space character encodes into %20 within the string. For the purposes of this task, every character except 0-9, A-Z and a-z requires conversion, so the following characters all require conversion by default: ASCII control codes (Character ranges 00-1F hex (0-31 decimal) and 7F (127 decimal). ASCII symbols (Character ranges 32-47 decimal (20-2F hex)) ASCII symbols (Character ranges 58-64 decimal (3A-40 hex)) ASCII symbols (Character ranges 91-96 decimal (5B-60 hex)) ASCII symbols (Character ranges 123-126 decimal (7B-7E hex)) Extended characters with character codes of 128 decimal (80 hex) and above. Example The string "http://foo bar/" would be encoded as "http%3A%2F%2Ffoo%20bar%2F". Variations Lowercase escapes are legal, as in "http%3a%2f%2ffoo%20bar%2f". Some standards give different rules: RFC 3986, Uniform Resource Identifier (URI): Generic Syntax, section 2.3, says that "-._~" should not be encoded. HTML 5, section 4.10.22.5 URL-encoded form data, says to preserve "-._*", and to encode space " " to "+". The options below provide for utilization of an exception string, enabling preservation (non encoding) of particular characters to meet specific standards. Options It is permissible to use an exception string (containing a set of symbols that do not need to be converted). However, this is an optional feature and is not a requirement of this task. Related tasks   URL decoding   URL parser
#VBScript
VBScript
Function UrlEncode(url) For i = 1 To Len(url) n = Asc(Mid(url,i,1)) If (n >= 48 And n <= 57) Or (n >= 65 And n <= 90) _ Or (n >= 97 And n <= 122) Then UrlEncode = UrlEncode & Mid(url,i,1) Else ChrHex = Hex(Asc(Mid(url,i,1))) For j = 0 to (Len(ChrHex) / 2) - 1 UrlEncode = UrlEncode & "%" & Mid(ChrHex,(2*j) + 1,2) Next End If Next End Function   WScript.Echo UrlEncode("http://foo baré/")
http://rosettacode.org/wiki/URL_encoding
URL encoding
Task Provide a function or mechanism to convert a provided string into URL encoding representation. In URL encoding, special characters, control characters and extended characters are converted into a percent symbol followed by a two digit hexadecimal code, So a space character encodes into %20 within the string. For the purposes of this task, every character except 0-9, A-Z and a-z requires conversion, so the following characters all require conversion by default: ASCII control codes (Character ranges 00-1F hex (0-31 decimal) and 7F (127 decimal). ASCII symbols (Character ranges 32-47 decimal (20-2F hex)) ASCII symbols (Character ranges 58-64 decimal (3A-40 hex)) ASCII symbols (Character ranges 91-96 decimal (5B-60 hex)) ASCII symbols (Character ranges 123-126 decimal (7B-7E hex)) Extended characters with character codes of 128 decimal (80 hex) and above. Example The string "http://foo bar/" would be encoded as "http%3A%2F%2Ffoo%20bar%2F". Variations Lowercase escapes are legal, as in "http%3a%2f%2ffoo%20bar%2f". Some standards give different rules: RFC 3986, Uniform Resource Identifier (URI): Generic Syntax, section 2.3, says that "-._~" should not be encoded. HTML 5, section 4.10.22.5 URL-encoded form data, says to preserve "-._*", and to encode space " " to "+". The options below provide for utilization of an exception string, enabling preservation (non encoding) of particular characters to meet specific standards. Options It is permissible to use an exception string (containing a set of symbols that do not need to be converted). However, this is an optional feature and is not a requirement of this task. Related tasks   URL decoding   URL parser
#Vlang
Vlang
import net.urllib fn main() { println(urllib.query_escape("http://foo bar/")) }
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
#PHP
PHP
<?php /** * @author Elad Yosifon */     /* * PHP is a weak typed language, * no separation between variable declaration, initialization and assignment. * * variable type is defined by the value that is assigned to it. * a variable name must start with a "$" sign (called "sigil", not a dollar sign). * variable naming rules: * + case-sensitive. * + first character after $ must not be a number. * + after the first character all alphanumeric chars and _(underscore) sign is allowed, e.g. $i_am_a_new_var_with_the_number_0 * */   # NULL typed variable $null = NULL; var_dump($null); // output: null   # defining a boolean $boolean = true; var_dump($boolean); // output: boolean true $boolean = false; var_dump($boolean); // output: boolean false   /* * casting is made using (TYPE) as a prefix */ # bool and boolean is the same $boolean = (bool)1; var_dump($boolean); // output: boolean true $boolean = (boolean)1; var_dump($boolean); // output: boolean true   $boolean = (bool)0; var_dump($boolean); // output: boolean false $boolean = (boolean)0; var_dump($boolean); // output: boolean false   # defining an integer $int = 0; var_dump($int); // output: int 0   # defining a float, $float = 0.01; var_dump($float); // output: float 0.01   # which is also identical to "real" and "double" var_dump((double)$float); // output: float 0.01 var_dump((real)$float); // output: float 0.01   # casting back to int (auto flooring the value) var_dump((int)$float); // output: int 0 var_dump((int)($float+1)); // output: int 1 var_dump((int)($float+1.9)); // output: int 1   # defining a string $string = 'string'; var_dump($string); // output: string 'string' (length=6)   # referencing a variable (there are no pointers in PHP). $another_string = &$string; var_dump($another_string); // output: string 'string' (length=6)   $string = "I'm the same string!"; var_dump($another_string); // output: string 'I'm the same string!' (length=20) # "deleting" a variable from memory unset($another_string);   $string = 'string'; /* * a string can also be defined with double-quotes, HEREDOC and NOWDOC operators. * content inside double-quotes is being parsed before assignment. * concatenation operator is .= */ $parsed_string = "This is a $string"; var_dump($parsed_string); // output: string 'This is a string' (length=16) $parsed_string .= " with another {$string}"; var_dump($parsed_string); // output: string 'This is a string with another string' (length=36)   # with string parsing $heredoc = <<<HEREDOC This is the content of \$string: {$string} HEREDOC; var_dump($heredoc); // output: string 'This is the content of $string: string' (length=38)   # without string parsing (notice the single quotes surrounding NOWDOC) $nowdoc = <<<'NOWDOC' This is the content of \$string: {$string} NOWDOC; var_dump($nowdoc); // output: string 'This is the content of \$string: {$string}' (length=42)   # as of PHP5, defining an object typed stdClass => standard class $stdObject = new stdClass(); var_dump($stdObject); // output: object(stdClass)[1] # defining an object typed Foo class Foo {} $foo = new Foo(); var_dump($foo); // output: object(Foo)[2] # defining an empty array $array = array(); var_dump($array); // output: array {empty}   /* * an array with non-integer key is also considered as an associative array(i.e. hash table) * can contain mixed variable types, can contain integer based keys and non-integer keys */ $assoc = array( 0 => $int, 'integer' => $int, 1 => $float, 'float' => $float, 2 => $string, 'string' => $string, 3 => NULL, // <=== key 3 is NULL 3, // <=== this is a value, not a key (key is 4) 5 => $stdObject, 'Foo' => $foo, ); var_dump($assoc);   // output: // ======= // array // 0 => int 0 // 'integer' => int 0 // 1 => float 0.01 // 'float' => float 0.01 // 2 => string 'string' (length=6) // 'string' => string 'string' (length=6) // 3 => null // 4 => int 3 // 5 => // object(stdClass)[1] // 'Foo' => // object(Foo)[2]       /* * all variables are "global" but not reachable inside functions(unless specifically "globalized" inside) */   function a_function() { # not reachable var_dump(isset($foo)); // output: boolean false   global $foo; # "global" (reachable) inside a_function()'s scope var_dump(isset($foo)); // output: boolean true }   a_function();   /** * there is another special type of variable called (Resource). * for more info regarding Resources: * @url http://php.net/manual/en/language.types.resource.php * @url http://php.net/manual/en/resource.php */  
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
#Mercury
Mercury
:- module vector_product. :- interface.   :- import_module io. :- pred main(io::di, io::uo) is det.   :- implementation. :- import_module int, list, string.   main(!IO) :- A = vector3d(3, 4, 5), B = vector3d(4, 3, 5), C = vector3d(-5, -12, -13), io.format("A . B = %d\n", [i(A `dot_product` B)], !IO), io.format("A x B = %s\n", [s(to_string(A `cross_product` B))], !IO), io.format("A . (B x C) = %d\n", [i(scalar_triple_product(A, B, C))], !IO), io.format("A x (B x C) = %s\n", [s(to_string(vector_triple_product(A, B, C)))], !IO).   :- type vector3d ---> vector3d(int, int, int).   :- func dot_product(vector3d, vector3d) = int.   dot_product(vector3d(A1, A2, A3), vector3d(B1, B2, B3)) = A1 * B1 + A2 * B2 + A3 * B3.   :- func cross_product(vector3d, vector3d) = vector3d.   cross_product(vector3d(A1, A2, A3), vector3d(B1, B2, B3)) = vector3d(A2 * B3 - A3 * B2, A3 * B1 - A1 * B3, A1 * B2 - A2 * B1).   :- func scalar_triple_product(vector3d, vector3d, vector3d) = int.   scalar_triple_product(A, B, C) = A `dot_product` (B `cross_product` C).   :- func vector_triple_product(vector3d, vector3d, vector3d) = vector3d.   vector_triple_product(A, B, C) = A `cross_product` (B `cross_product` C).   :- func to_string(vector3d) = string.   to_string(vector3d(X, Y, Z)) = string.format("(%d, %d, %d)", [i(X), i(Y), i(Z)]).
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#Seed7
Seed7
$ include "seed7_05.s7i"; include "encoding.s7i";   const proc: main is func begin writeln(fromPercentEncoded("http%3A%2F%2Ffoo%20bar%2F")); writeln(fromUrlEncoded("http%3A%2F%2Ffoo+bar%2F")); end func;
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#Sidef
Sidef
func urldecode(str) { str.gsub!('+', ' '); str.gsub!(/\%([A-Fa-f0-9]{2})/, {|a| 'C'.pack(a.hex)}); return str; }   say urldecode('http%3A%2F%2Ffoo+bar%2F'); # => "http://foo bar/"
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
#Nemerle
Nemerle
using System; using System.Console;   module Input { Main() : void { Write("Enter a string:"); _ = ReadLine()   mutable entry = 0; mutable numeric = false;   do { Write("Enter 75000:"); numeric = int.TryParse(ReadLine(), out entry); } while ((!numeric) || (entry != 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
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols nobinary   checkVal = 75000 say 'Input a string then the number' checkVal parse ask inString parse ask inNumber .   say 'Input string:' inString say 'Input number:' inNumber if inNumber == checkVal then do say 'Success! Input number is as requested' end else do say 'Failure! Number' inNumber 'is not' checkVal end return  
http://rosettacode.org/wiki/User_input/Graphical
User input/Graphical
In this task, the goal is to input a string and the integer 75000, from graphical user interface. See also: User input/Text
#TI-89_BASIC
TI-89 BASIC
Prgm Dialog Title "Rosetta Code" Request "A string", s DropDown "An integer", {"75000"}, n EndDlog 74999 + n → n EndPrgm
http://rosettacode.org/wiki/User_input/Graphical
User input/Graphical
In this task, the goal is to input a string and the integer 75000, from graphical user interface. See also: User input/Text
#VBScript
VBScript
strUserIn = InputBox("Enter Data") Wscript.Echo strUserIn
http://rosettacode.org/wiki/URL_encoding
URL encoding
Task Provide a function or mechanism to convert a provided string into URL encoding representation. In URL encoding, special characters, control characters and extended characters are converted into a percent symbol followed by a two digit hexadecimal code, So a space character encodes into %20 within the string. For the purposes of this task, every character except 0-9, A-Z and a-z requires conversion, so the following characters all require conversion by default: ASCII control codes (Character ranges 00-1F hex (0-31 decimal) and 7F (127 decimal). ASCII symbols (Character ranges 32-47 decimal (20-2F hex)) ASCII symbols (Character ranges 58-64 decimal (3A-40 hex)) ASCII symbols (Character ranges 91-96 decimal (5B-60 hex)) ASCII symbols (Character ranges 123-126 decimal (7B-7E hex)) Extended characters with character codes of 128 decimal (80 hex) and above. Example The string "http://foo bar/" would be encoded as "http%3A%2F%2Ffoo%20bar%2F". Variations Lowercase escapes are legal, as in "http%3a%2f%2ffoo%20bar%2f". Some standards give different rules: RFC 3986, Uniform Resource Identifier (URI): Generic Syntax, section 2.3, says that "-._~" should not be encoded. HTML 5, section 4.10.22.5 URL-encoded form data, says to preserve "-._*", and to encode space " " to "+". The options below provide for utilization of an exception string, enabling preservation (non encoding) of particular characters to meet specific standards. Options It is permissible to use an exception string (containing a set of symbols that do not need to be converted). However, this is an optional feature and is not a requirement of this task. Related tasks   URL decoding   URL parser
#Wren
Wren
import "/fmt" for Fmt   var urlEncode = Fn.new { |url| var res = "" for (b in url.bytes) { if ((b >= 48 && b <= 57) || (b >= 65 && b <= 90) || (b >= 97 && b <= 122)) { res = res + String.fromByte(b) } else { res = res + Fmt.swrite("\%$2X", b) } } return res }   var urls = [ "http://foo bar/", "mailto:\"Ivan Aim\" <[email protected]>", "mailto:\"Irma User\" <[email protected]>", "http://foo.bar.com/~user-name/_subdir/*~.html" ] for (url in urls) System.print(urlEncode.call(url))
http://rosettacode.org/wiki/URL_encoding
URL encoding
Task Provide a function or mechanism to convert a provided string into URL encoding representation. In URL encoding, special characters, control characters and extended characters are converted into a percent symbol followed by a two digit hexadecimal code, So a space character encodes into %20 within the string. For the purposes of this task, every character except 0-9, A-Z and a-z requires conversion, so the following characters all require conversion by default: ASCII control codes (Character ranges 00-1F hex (0-31 decimal) and 7F (127 decimal). ASCII symbols (Character ranges 32-47 decimal (20-2F hex)) ASCII symbols (Character ranges 58-64 decimal (3A-40 hex)) ASCII symbols (Character ranges 91-96 decimal (5B-60 hex)) ASCII symbols (Character ranges 123-126 decimal (7B-7E hex)) Extended characters with character codes of 128 decimal (80 hex) and above. Example The string "http://foo bar/" would be encoded as "http%3A%2F%2Ffoo%20bar%2F". Variations Lowercase escapes are legal, as in "http%3a%2f%2ffoo%20bar%2f". Some standards give different rules: RFC 3986, Uniform Resource Identifier (URI): Generic Syntax, section 2.3, says that "-._~" should not be encoded. HTML 5, section 4.10.22.5 URL-encoded form data, says to preserve "-._*", and to encode space " " to "+". The options below provide for utilization of an exception string, enabling preservation (non encoding) of particular characters to meet specific standards. Options It is permissible to use an exception string (containing a set of symbols that do not need to be converted). However, this is an optional feature and is not a requirement of this task. Related tasks   URL decoding   URL parser
#XPL0
XPL0
code Text=12; string 0; \use zero-terminated strings   func Encode(S0); \Encode URL string and return its address char S0; char HD, S1(80); \BEWARE: very temporary string space returned int C, I, J; [HD:= "0123456789ABCDEF"; \hex digits I:= 0; J:= 0; repeat C:= S0(I); I:= I+1; if C>=^0 & C<=^9 ! C>=^A & C<=^Z ! C>=^a & C<=^z ! C=0 then [S1(J):= C; J:= J+1] \simply pass char to S1 else [S1(J):= ^%; J:= J+1; \encode char into S1 S1(J):= HD(C>>4); J:= J+1; S1(J):= HD(C&$0F); J:= J+1; ]; until C=0; return S1; ];   Text(0, Encode("http://foo bar/"))
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
#PicoLisp
PicoLisp
(use (A B C) (setq A 1 B 2 C 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
#PL.2FI
PL/I
/* The PROCEDURE block and BEGIN block are used to delimit scopes. */   declare i float; /* external, global variable, excluded from the */ /* local area (BEGIN block) below. */ begin; declare (i, j) fixed binary; /* local variable */ get list (i, j); put list (i,j); end;   /* Examples of initialization. */   declare p fixed initial (25); declare q(7) fixed initial (9, 3, 5, 1, 2, 8, 15); /* sets all elements of array Q at run time, on block entry. */ declare r(7) fixed initial (9, 3, 5, 1, 2, 8, 15); /* sets all elements of array R at compile time. */   p = 44; /* run-time assignment. */ q = 0; /* run-time initialization of all elements of Q to zero. */ q = r; /* run-time assignment of all elements of array R to */ /* corresponding elemets of S. */
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
#MiniScript
MiniScript
vectorA = [3, 4, 5] vectorB = [4, 3, 5] vectorC = [-5, -12, -13]   dotProduct = function(x, y) return x[0]*y[0] + x[1]*y[1] + x[2]*y[2] end function   crossProduct = function(x, y) return [x[1]*y[2] - x[2]*y[1], x[2]*y[0] - x[0]*y[2], x[0]*y[1] - x[1]*y[0]] end function   print "Dot Product = " + dotProduct(vectorA, vectorB) print "Cross Product = " + crossProduct(vectorA, vectorB) print "Scalar Triple Product = " + dotProduct(vectorA, crossProduct(vectorB,vectorC)) print "Vector Triple Product = " + crossProduct(vectorA, crossProduct(vectorB,vectorC))  
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#Swift
Swift
import Foundation   let encoded = "http%3A%2F%2Ffoo%20bar%2F" if let normal = encoded.stringByReplacingPercentEscapesUsingEncoding(NSUTF8StringEncoding) { println(normal) }
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#Tcl
Tcl
proc urlDecode {str} { set specialMap {"[" "%5B" "]" "%5D"} set seqRE {%([0-9a-fA-F]{2})} set replacement {[format "%c" [scan "\1" "%2x"]]} set modStr [regsub -all $seqRE [string map $specialMap $str] $replacement] return [encoding convertfrom utf-8 [subst -nobackslash -novariable $modStr]] }
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
#newLISP
newLISP
(print "Enter an integer: ") (set 'x (read-line)) (print "Enter a string: ") (set 'y (read-line))
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
#Nim
Nim
import rdstdin, strutils   let str = readLineFromStdin "Input a string: " let num = parseInt(readLineFromStdin "Input an integer: ")
http://rosettacode.org/wiki/User_input/Graphical
User input/Graphical
In this task, the goal is to input a string and the integer 75000, from graphical user interface. See also: User input/Text
#Vedit_macro_language
Vedit macro language
Dialog_Input_1(1, "`User Input example`, `??Enter a string `, `??Enter a number `")
http://rosettacode.org/wiki/User_input/Graphical
User input/Graphical
In this task, the goal is to input a string and the integer 75000, from graphical user interface. See also: User input/Text
#Visual_Basic
Visual Basic
import "graphics" for Canvas, Color import "input" for Keyboard, Clipboard import "dome" for Window, Process   var X = 10 var Y = 28   class Main { construct new() {}   init() { _text = "" _enterNum = false Keyboard.handleText = true Keyboard.textRegion(X, Y, 8, 8) }   update() { var change = false if (Keyboard.text.count > 0) { _text = _text + Keyboard.text change = true }   // enable backspace key to delete last character entered if (Keyboard["backspace"].justPressed && _text.count > 0) { var codePoints = _text.codePoints codePoints = codePoints.take(codePoints.count - 1) _text = "" for (point in codePoints) { _text = _text + String.fromCodePoint(point) } change = true }   // enable return key to terminate input if (Keyboard["return"].justPressed) { System.print("'%(_text)' was entered.") if (!_enterNum) { _text = "" _enterNum = true change = true } else if (_text == "75000") { Process.exit() } else { _text = "" change = true } }   if (change) { Keyboard.textRegion(X.min(_text.count * 8), Y, 8, 8) } }   draw(dt) { Canvas.cls() Canvas.rect(X, Y, 8, 8, Color.red) if (!_enterNum) { Canvas.print("Enter Text and press return:", 10, 10, Color.white) } else { Canvas.print("Enter 75000 and press return:", 10, 10, Color.white) } Canvas.print(_text, 10, 20, Color.white) } }   var Game = Main.new()
http://rosettacode.org/wiki/URL_encoding
URL encoding
Task Provide a function or mechanism to convert a provided string into URL encoding representation. In URL encoding, special characters, control characters and extended characters are converted into a percent symbol followed by a two digit hexadecimal code, So a space character encodes into %20 within the string. For the purposes of this task, every character except 0-9, A-Z and a-z requires conversion, so the following characters all require conversion by default: ASCII control codes (Character ranges 00-1F hex (0-31 decimal) and 7F (127 decimal). ASCII symbols (Character ranges 32-47 decimal (20-2F hex)) ASCII symbols (Character ranges 58-64 decimal (3A-40 hex)) ASCII symbols (Character ranges 91-96 decimal (5B-60 hex)) ASCII symbols (Character ranges 123-126 decimal (7B-7E hex)) Extended characters with character codes of 128 decimal (80 hex) and above. Example The string "http://foo bar/" would be encoded as "http%3A%2F%2Ffoo%20bar%2F". Variations Lowercase escapes are legal, as in "http%3a%2f%2ffoo%20bar%2f". Some standards give different rules: RFC 3986, Uniform Resource Identifier (URI): Generic Syntax, section 2.3, says that "-._~" should not be encoded. HTML 5, section 4.10.22.5 URL-encoded form data, says to preserve "-._*", and to encode space " " to "+". The options below provide for utilization of an exception string, enabling preservation (non encoding) of particular characters to meet specific standards. Options It is permissible to use an exception string (containing a set of symbols that do not need to be converted). However, this is an optional feature and is not a requirement of this task. Related tasks   URL decoding   URL parser
#Yabasic
Yabasic
sub encode_url$(s$, exclusions$, spaceplus) local res$, i, ch$   for i=1 to len(s$) ch$ = mid$(s$, i, 1) if ch$ = " " and spaceplus then ch$ = "+" elsif not instr(esclusions$, ch$) and (ch$ < "0" or (ch$ > "9" and ch$ < "A") or (ch$ > "Z" and ch$ < "a") or ch$ > "z") then res$ = res$ + "%" ch$ = upper$(hex$(asc(ch$))) end if res$ = res$ + ch$ next i return res$ end sub   print encode_url$("http://foo bar/")
http://rosettacode.org/wiki/URL_encoding
URL encoding
Task Provide a function or mechanism to convert a provided string into URL encoding representation. In URL encoding, special characters, control characters and extended characters are converted into a percent symbol followed by a two digit hexadecimal code, So a space character encodes into %20 within the string. For the purposes of this task, every character except 0-9, A-Z and a-z requires conversion, so the following characters all require conversion by default: ASCII control codes (Character ranges 00-1F hex (0-31 decimal) and 7F (127 decimal). ASCII symbols (Character ranges 32-47 decimal (20-2F hex)) ASCII symbols (Character ranges 58-64 decimal (3A-40 hex)) ASCII symbols (Character ranges 91-96 decimal (5B-60 hex)) ASCII symbols (Character ranges 123-126 decimal (7B-7E hex)) Extended characters with character codes of 128 decimal (80 hex) and above. Example The string "http://foo bar/" would be encoded as "http%3A%2F%2Ffoo%20bar%2F". Variations Lowercase escapes are legal, as in "http%3a%2f%2ffoo%20bar%2f". Some standards give different rules: RFC 3986, Uniform Resource Identifier (URI): Generic Syntax, section 2.3, says that "-._~" should not be encoded. HTML 5, section 4.10.22.5 URL-encoded form data, says to preserve "-._*", and to encode space " " to "+". The options below provide for utilization of an exception string, enabling preservation (non encoding) of particular characters to meet specific standards. Options It is permissible to use an exception string (containing a set of symbols that do not need to be converted). However, this is an optional feature and is not a requirement of this task. Related tasks   URL decoding   URL parser
#zkl
zkl
var CURL=Import("zklCurl"); CURL.urlEncode("http://foo bar/") //--> "http%3A%2F%2Ffoo%20bar%2F"
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
#Pony
Pony
var counter: I32 = 10 // mutable variable 'counter' with value 10 let temp: F64 = 36.6 // immutable variable 'temp' let str: String // immutable variable 'str' with no initial value str = "i am a string" // variables must be initialized before use let another_str = "i am another string" // type of variable 'another_str' infered from assigned value   let b = true let b' = false // variable names can contain ' to make a distinct variable with almost the same name
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
#PowerShell
PowerShell
$s = "abc" $i = 123
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
#.D0.9C.D0.9A-61.2F52
МК-61/52
ПП 54 С/П ПП 66 С/П ИП0 ИП3 ИП6 П3 -> П0 -> П6 ИП1 ИП4 ИП7 П4 -> П1 -> П7 ИП2 ИП5 ИП8 П5 -> П2 -> П8 ПП 66 ИП6 ИП7 ИП8 П2 -> П1 -> П0 ИП9 ИПA ИПB П5 -> П4 -> П3 ПП 54 С/П ПП 66 С/П ИП0 ИП3 * ИП1 ИП4 * + ИП2 ИП5 * + В/О ИП1 ИП5 * ИП2 ИП4 * - П9 ИП2 ИП3 * ИП0 ИП5 * - ПA ИП0 ИП4 * ИП1 ИП3 * - ПB В/О
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT url_encoded="http%3A%2F%2Ffoo%20bar%2F" BUILD S_TABLE hex=":%><:><2<>2<%:" hex=STRINGS (url_encoded,hex), hex=SPLIT(hex) hex=DECODE (hex,hex) url_decoded=SUBSTITUTE(url_encoded,":%><2<>2<%:",0,0,hex) PRINT "encoded: ", url_encoded PRINT "decoded: ", url_decoded  
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#UNIX_Shell
UNIX Shell
urldecode() { local u="${1//+/ }"; printf '%b' "${u//%/\\x}"; }
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
#NS-HUBASIC
NS-HUBASIC
10 INPUT "ENTER A STRING: ",STRING$ 20 PRINT "YOU ENTERED ";STRING$;"." 30 INPUT "ENTER AN INTEGER: ",INTEGER 40 PRINT "YOU ENTERED";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
#Oberon-2
Oberon-2
  MODULE InputText; IMPORT In, Out; VAR i: INTEGER; str: ARRAY 512 OF CHAR; BEGIN Out.String("Enter a integer: ");Out.Flush();In.Int(i); Out.String("Enter a string: ");Out.Flush();In.String(str); END InputText.  
http://rosettacode.org/wiki/User_input/Graphical
User input/Graphical
In this task, the goal is to input a string and the integer 75000, from graphical user interface. See also: User input/Text
#Wren
Wren
import "graphics" for Canvas, Color import "input" for Keyboard, Clipboard import "dome" for Window, Process   var X = 10 var Y = 28   class Main { construct new() {}   init() { _text = "" _enterNum = false Keyboard.handleText = true Keyboard.textRegion(X, Y, 8, 8) }   update() { var change = false if (Keyboard.text.count > 0) { _text = _text + Keyboard.text change = true }   // enable backspace key to delete last character entered if (Keyboard["backspace"].justPressed && _text.count > 0) { var codePoints = _text.codePoints codePoints = codePoints.take(codePoints.count - 1) _text = "" for (point in codePoints) { _text = _text + String.fromCodePoint(point) } change = true }   // enable return key to terminate input if (Keyboard["return"].justPressed) { System.print("'%(_text)' was entered.") if (!_enterNum) { _text = "" _enterNum = true change = true } else if (_text == "75000") { Process.exit() } else { _text = "" change = true } }   if (change) { Keyboard.textRegion(X.min(_text.count * 8), Y, 8, 8) } }   draw(dt) { Canvas.cls() Canvas.rect(X, Y, 8, 8, Color.red) if (!_enterNum) { Canvas.print("Enter Text and press return:", 10, 10, Color.white) } else { Canvas.print("Enter 75000 and press return:", 10, 10, Color.white) } Canvas.print(_text, 10, 20, Color.white) } }   var Game = Main.new()
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
#Prolog
Prolog
mortal(X) :- man(X). man(socrates).
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
#PureBasic
PureBasic
; Variables are initialized when they appear in sourcecode with default value of 0 and type int Debug a ; or value "" for a string, they are not case sensitive Debug b$ ; This initializes a double precision float, if type is following the dot Debug c.d ; They can be initialized with define (double precision float, string, integer) Define d.d = 3.5, e$ = "Test", f.i = a + 2 ; Define can have a default type (all bytes except j which is long): Define.b g, h, j.l ; Define without following variables sets default type. In this case to single precision float Define.f ; So this will be an single precision float and no integer Debug k ; EnableExplicit forces declaration of used variables with define EnableExplicit ; Will throw an error because L isn't initialized Debug L DisableExplicit ; Global Variables are available in Procedures and Threads too Global M = 3, N = 2 Procedure Dummy(parameter1, parameter2 = 20) ; Parameter contain values which where used when calling the function, ; their types have to be specified in the above Procedure header. ; The last ones can have default values which get applied if this parameter is not given.   ; Variables in Procedures are separate from those outside, ; so d can be initialized again with another type ; which would otherwise lead to an error d.i ; Protected makes a variable local even if another one with same name is declared as global (see above) Protected M = 2 ; Shares a variable with main program like it was declared by global Shared a ; prevents a variable to be initialized with default value again when procedure is called a second time, ; could be used for example as a counter, which contains the number of times a function was called Static a ; N here also would have a value of 2, while for example ; f would, when named, initialize a new variable, and so have a value of 0 EndProcedure ; finally there are constants which are prefixed by an #: #Test = 1 ; Their value cannot be changed while program is running #String_Constant = "blubb" ; In constrast to variables, a constant has no types except an (optional) $ sign to mark it as string constant #Float_Constant = 2.3 ; Maps, LinkedLists , Arrays and Structures are not handled here, because they are no elemental variables
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
#Modula-2
Modula-2
MODULE VectorProducts; FROM RealStr IMPORT RealToStr; FROM Terminal IMPORT WriteString,WriteLn,ReadChar;   PROCEDURE WriteReal(r : REAL); VAR buf : ARRAY[0..31] OF CHAR; BEGIN RealToStr(r, buf); WriteString(buf) END WriteReal;   TYPE Vector = RECORD a,b,c : REAL; END;   PROCEDURE Dot(u,v : Vector) : REAL; BEGIN RETURN u.a * v.a + u.b * v.b + u.c * v.c END Dot;   PROCEDURE Cross(u,v : Vector) : Vector; BEGIN RETURN Vector{ u.b*v.c - u.c*v.b, u.c*v.a - u.a*v.c, u.a*v.b - u.b*v.a } END Cross;   PROCEDURE ScalarTriple(u,v,w : Vector) : REAL; BEGIN RETURN Dot(u, Cross(v, w)) END ScalarTriple;   PROCEDURE VectorTriple(u,v,w : Vector) : Vector; BEGIN RETURN Cross(u, Cross(v, w)) END VectorTriple;   PROCEDURE WriteVector(v : Vector); BEGIN WriteString("<"); WriteReal(v.a); WriteString(", "); WriteReal(v.b); WriteString(", "); WriteReal(v.c); WriteString(">") END WriteVector;   VAR a,b,c : Vector; BEGIN a := Vector{3.0, 4.0, 5.0}; b := Vector{4.0, 3.0, 5.0}; c := Vector{-5.0, -12.0, -13.0};   WriteVector(a); WriteString(" dot "); WriteVector(b); WriteString(" = "); WriteReal(Dot(a,b)); WriteLn;   WriteVector(a); WriteString(" cross "); WriteVector(b); WriteString(" = "); WriteVector(Cross(a,b)); WriteLn;   WriteVector(a); WriteString(" cross ("); WriteVector(b); WriteString(" cross "); WriteVector(c); WriteString(") = "); WriteVector(VectorTriple(a,b,c)); WriteLn;   ReadChar END VectorProducts.
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#VBScript
VBScript
Function RegExTest(str,patrn) Dim regEx Set regEx = New RegExp regEx.IgnoreCase = True regEx.Pattern = patrn RegExTest = regEx.Test(str) End Function   Function URLDecode(sStr) Dim str,code,a0 str="" code=sStr code=Replace(code,"+"," ") While len(code)>0 If InStr(code,"%")>0 Then str = str & Mid(code,1,InStr(code,"%")-1) code = Mid(code,InStr(code,"%")) a0 = UCase(Mid(code,2,1)) If a0="U" And RegExTest(code,"^%u[0-9A-F]{4}") Then str = str & ChrW((Int("&H" & Mid(code,3,4)))) code = Mid(code,7) ElseIf a0="E" And RegExTest(code,"^(%[0-9A-F]{2}){3}") Then str = str & ChrW((Int("&H" & Mid(code,2,2)) And 15) * 4096 + (Int("&H" & Mid(code,5,2)) And 63) * 64 + (Int("&H" & Mid(code,8,2)) And 63)) code = Mid(code,10) ElseIf a0>="C" And a0<="D" And RegExTest(code,"^(%[0-9A-F]{2}){2}") Then str = str & ChrW((Int("&H" & Mid(code,2,2)) And 3) * 64 + (Int("&H" & Mid(code,5,2)) And 63)) code = Mid(code,7) ElseIf (a0<="B" Or a0="F") And RegExTest(code,"^%[0-9A-F]{2}") Then str = str & Chr(Int("&H" & Mid(code,2,2))) code = Mid(code,4) Else str = str & "%" code = Mid(code,2) End If Else str = str & code code = "" End If Wend URLDecode = str End Function   url = "http%3A%2F%2Ffoo%20bar%C3%A8%2F" WScript.Echo "Encoded URL: " & url & vbCrLf &_ "Decoded URL: " & UrlDecode(url)
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#Vlang
Vlang
import net.urllib fn main() { for escaped in [ "http%3A%2F%2Ffoo%20bar%2F", "google.com/search?q=%60Abdu%27l-Bah%C3%A1", ] { u := urllib.query_unescape(escaped)? println(u) } }
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
#Objeck
Objeck
  use IO;   bundle Default { class Hello { function : Main(args : String[]) ~ Nil { string := Console->GetInstance()->ReadString(); string->PrintLine();   number := Console->GetInstance()->ReadString()->ToInt(); number->PrintLine(); } } }  
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
#OCaml
OCaml
print_string "Enter a string: "; let str = read_line () in print_string "Enter an integer: "; let num = read_int () in Printf.printf "%s%d\n" str num
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
#Python
Python
  # these examples, respectively, refer to integer, float, boolean, and string objects example1 = 3 example2 = 3.0 example3 = True example4 = "hello"   # example1 now refers to a string object. example1 = "goodbye"  
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
#Quackery
Quackery
[ stack ] is mystack
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
#Nemerle
Nemerle
using System.Console;   module VectorProducts3d { Dot(x : int * int * int, y : int * int * int) : int { def (x1, x2, x3) = x; def (y1, y2, y3) = y; (x1 * y1) + (x2 * y2) + (x3 * y3) }   Cross(x : int * int * int, y : int * int * int) : int * int * int { def (x1, x2, x3) = x; def (y1, y2, y3) = y; ((x2 * y3 - x3 * y2), (x3 * y1 - x1 * y3), (x1 * y2 - x2 * y1)) }   ScalarTriple(a : int * int * int, b : int * int * int, c : int * int * int) : int { Dot(a, Cross(b, c)) }   VectorTriple(a : int * int * int, b : int * int * int, c : int * int * int) : int * int * int { Cross(a, Cross(b, c)) }   Main() : void { def a = (3, 4, 5); def b = (4, 3, 5); def c = (-5, -12, -13); WriteLine(Dot(a, b)); WriteLine(Cross(a, b)); WriteLine(ScalarTriple(a, b, c)); WriteLine(VectorTriple(a, b, c)); } }
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#Wren
Wren
import "/fmt" for Conv   var urlDecode = Fn.new { |enc| var res = "" var i = 0 while (i < enc.count) { var c = enc[i] if (c == "\%") { var b = Conv.atoi(enc[i+1..i+2], 16) res = res + String.fromByte(b) i = i + 3 } else { res = res + c i = i + 1 } } return res }   // We need to escape % characters in Wren as % is otherwise used for string interpolation. var encs = [ "http\%3A\%2F\%2Ffoo\%20bar\%2F", "google.com/search?q=\%60Abdu\%27l-Bah\%C3\%A1" ] for (enc in encs)System.print(urlDecode.call(enc))
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
#Octave
Octave
% read a string ("s") s = input("Enter a string: ", "s");   % read a GNU Octave expression, which is evaluated; e.g. % 5/7 gives 0.71429 i = input("Enter an expression: ");   % parse the input for an integer printf("Enter an integer: "); ri = scanf("%d");   % show the values disp(s); disp(i); disp(ri);
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
#R
R
foo <- 3.4 bar = "abc"
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
#Racket
Racket
  #lang racket   ;; define a variable and initialize it (define foo 0) ;; increment it (set! foo (add1 foo))   ;; Racket is lexically scoped, which makes local variables work: (define (bar) (define foo 100) (set! foo (add1 foo)) foo) (bar) ; -> 101   ;; and it also makes it possible to have variables with a global value ;; that are accessible only in a specific local lexical scope: (define baz (let () ; used to create a new scope (define foo 0) (define (bar) (set! foo (add1 foo)) foo) bar)) ; this is the value that gets bound to `baz' (list (baz) (baz) (baz)) ; -> '(1 2 3)   ;; define a new type, and initialize a variable with an instance (struct pos (x y)) (define p (pos 1 2)) (list (pos-x p) (pos-y p)) ; -> '(1 2)   ;; for a mutable reference, a struct (or some specific fields in a ;; struct) can be declared mutable (struct mpos (x y) #:mutable) (define mp (mpos 1 2)) (set-mpos-x! mp 11) (set-mpos-y! mp 22) (list (mpos-x mp) (mpos-y mp)) ; -> '(11 22)   ;; but for just a mutable value, we have boxes as a builtin type (define b (box 10)) (set-box! b (add1 (unbox b))) (unbox b) ; -> 11   ;; (Racket has many more related features: static typing in typed ;; racket, structs that are extensions of other structs, ;; pattern-matching on structs, classes, and much more)  
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
#Never
Never
func printv(a[d] : float) -> int { prints("[" + a[0] + ", " + a[1] + ", " + a[2] + "]\n"); 0 }   func dot(a[d1] : float, b[d2] : float) -> float { a[0] * b[0] + a[1] * b[1] + a[2] * b[2] }   func cross(a[d1] : float, b[d2] : float) -> [_] : float { [ a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0] ] : float }   func scalar_triple(a[d1] : float, b[d2] : float, c[d3] : float) -> float { dot(a, cross(b, c)) }   func vector_triple(a[d1] : float, b[d2] : float, c[d3] : float) -> [_] : float { cross(a, cross(b, c)) }   func main() -> int { var a = [ 3.0, 4.0, 5.0 ] : float; var b = [ 4.0, 3.0, 5.0 ] : float; var c = [ -5.0, -12.0, -13.0 ] : float;   printv(a); printv(b); printv(c); printf(dot(a, b)); printv(cross(a, b)); printf(scalar_triple(a, b, c)); printv(vector_triple(a, b, c)); 0 }  
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#XPL0
XPL0
code Text=12; string 0; \use zero-terminated strings   func Decode(S0); \Decode URL string and return its address char S0; char S1(80); \BEWARE: very temporary string space returned int C, N, I, J; [I:= 0; J:= 0; repeat C:= S0(I); I:= I+1; \get char if C=^% then \convert hex to char [C:= S0(I); I:= I+1; if C>=^a then C:= C & ~$20; \convert to uppercase N:= C - (if C<=^9 then ^0 else ^A-10); C:= S0(I); I:= I+1; if C>=^a then C:= C & ~$20; C:= N*16 + C - (if C<=^9 then ^0 else ^A-10); ]; S1(J):= C; J:= J+1; \put char in output string until C=0; return S1; ];   Text(0, Decode("http%3A%2F%2Ffoo%20bar%2f"))
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#Yabasic
Yabasic
sub decode_url$(s$) local res$, ch$   while(s$ <> "") ch$ = left$(s$, 1) if ch$ = "%" then ch$ = chr$(dec(mid$(s$, 2, 2))) s$ = right$(s$, len(s$) - 3) else if ch$ = "+" ch$ = " " s$ = right$(s$, len(s$) - 1) endif res$ = res$ + ch$ wend return res$ end sub   print decode_url$("http%3A%2F%2Ffoo%20bar%2F") print decode_url$("google.com/search?q=%60Abdu%27l-Bah%C3%A1")
http://rosettacode.org/wiki/URL_decoding
URL decoding
This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function or mechanism to convert an URL-encoded string into its original unencoded form. Test cases   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".
#zkl
zkl
"http%3A%2F%2Ffoo%20bar%2F".pump(String, // push each char through these fcns: fcn(c){ if(c=="%") return(Void.Read,2); return(Void.Skip,c) },// %-->read 2 chars else pass through fcn(_,b,c){ (b+c).toInt(16).toChar() }) // "%" (ignored) "3"+"1"-->0x31-->"1"
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
#Oforth
Oforth
import: console   : testInput{ | s n | System.Console askln ->s while (System.Console askln asInteger dup ->n isNull) [ "Not an integer" println ]   System.Out "Received : " << s << " and " << n << cr ;
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
#Oz
Oz
declare StdIn = {New class $ from Open.file Open.text end init(name:stdin)} StringInput Num = {NewCell 0} in {System.printInfo "Enter a string: "} StringInput = {StdIn getS($)}   for until:@Num == 75000 do {System.printInfo "Enter 75000: "} Line = {StdIn getS($)} in Num := try {String.toInt Line} catch _ then 0 end 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
#Raku
Raku
  my @y = <A B C D>; # Array of strings 'A', 'B', 'C', and 'D' say @y[2]; # the @-sigil requires the container to implement the role Positional @y[1,2] = 'x','y'; # that's where subscripts and many other things come from say @y; # OUTPUT«[A x y D]␤» # we start to count at 0 btw.   my $x = @y; # $x is now a reference for the array @y   say $x[1]; # prints 'x' followed by a newline character   my Int $with-type-check; # type checks are enforced by the compiler   my Int:D $defined-i = 10; # definedness can also be asked for and default values are required in that case   my Int:D $after-midnight where * > 24 = 25; # SQL is fun and so is Raku   my \bad = 'good'; # if you don't like sigils say bad; # you don't have to use them say "this is quite bad"; # but then string interpolation say "this is quite {bad}" # becomes more wordy  
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
#Nim
Nim
import strformat, strutils   type Vector3 = array[1..3, float]   proc `$`(a: Vector3): string = result = "(" for x in a: result.addSep(", ", 1) result.add &"{x}" result.add ')'   proc cross(a, b: Vector3): Vector3 = result = [a[2]*b[3] - a[3]*b[2], a[3]*b[1] - a[1]*b[3], a[1]*b[2] - a[2]*b[1]]   proc dot(a, b: Vector3): float = for i in a.low..a.high: result += a[i] * b[i]   proc scalarTriple(a, b, c: Vector3): float = a.dot(b.cross(c))   proc vectorTriple(a, b, c: Vector3): Vector3 = a.cross(b.cross(c))   let a = [3.0, 4.0, 5.0] b = [4.0, 3.0, 5.0] c = [-5.0, -12.0, -13.0]   echo &"a ⨯ b = {a.cross(b)}" echo &"a . b = {a.dot(b)}" echo &"a . (b ⨯ c) = {scalarTriple(a, b, c)}" echo &"a ⨯ (b ⨯ c) = {vectorTriple(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
#PARI.2FGP
PARI/GP
s=input(); n=eval(input());
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
#Pascal
Pascal
program UserInput(input, output); var i : Integer; s : String; begin write('Enter an integer: '); readln(i); write('Enter a string: '); readln(s) 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
#Rascal
Rascal
Type Name = Exp;
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
#REXX
REXX
aa = 10 /*assigns chars 10 ───► AA */ bb = '' /*assigns a null value ───► BB */ cc = 2*10 /*assigns chars 20 ───► CC */ dd = 'Adam' /*assigns chars Adam ───► DD */ ee = "Adam" /*same as above ───► EE */ ff = 10. /*assigns chars 10. ───► FF */ gg = '10.' /*same as above ───► GG */ hh = "+10" /*assigns chars +10 ───► hh */ ii = 1e1 /*assigns chars 1e1 ───► ii */ jj = +.1e+2 /*assigns chars .1e+2 ───► jj */
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
#Objeck
Objeck
bundle Default { class VectorProduct { function : Main(args : String[]) ~ Nil { a := Vector3D->New(3.0, 4.0, 5.0); b := Vector3D->New(4.0, 3.0, 5.0); c := Vector3D->New(-5.0, -12.0, -13.0);   a->Dot(b)->Print(); a->Cross(b)->Print(); a->ScaleTrip(b, c)->Print(); a->VectorTrip(b, c)->Print(); } }   class Vector3D { @a : Float; @b : Float; @c : Float;   New(a : Float, b : Float, c : Float) { @a := a; @b := b; @c := c; }   method : GetA() ~ Float { return @a; }   method : GetB() ~ Float { return @b; }   method : GetC() ~ Float { return @c; }   method : public : Dot(vec : Vector3D) ~ Float { return @a * vec->GetA() + @b * vec->GetB() + @c * vec->GetC(); }   method : public : Cross(vec : Vector3D) ~ Vector3D { newA := @b * vec->GetC() - @c * vec->GetB(); newB := @c * vec->GetA() - @a * vec->GetC(); newC := @a * vec->GetB() - @b * vec->GetA();   return Vector3D->New(newA, newB, newC); }   method : public : ScaleTrip(vec_b: Vector3D, vec_c : Vector3D) ~ Float { return Dot(vec_b->Cross(vec_c)); }   method : public : Print() ~ Nil { IO.Console->Print('<')->Print(@a)->Print(" ,") ->Print(@b)->Print(", ")->Print(@c)->PrintLine('>'); }   method : public : VectorTrip(vec_b: Vector3D, vec_c : Vector3D) ~ Vector3D { return Cross(vec_b->Cross(vec_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
#Perl
Perl
print "Enter a string: "; my $string = <>; print "Enter an integer: "; my $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
#Phix
Phix
?prompt_string("Enter any string:") ?prompt_number("Enter the number 75000:",{75000,75000})
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
#Ring
Ring
  <Variable Name> = <Value>  
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
#Ruby
Ruby
$a_global_var = 5 class Demo @@a_class_var = 6 A_CONSTANT = 8 def initialize @an_instance_var = 7 end def incr(a_local_var) @an_instance_var += a_local_var end end