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/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Nanoquery
Nanoquery
println ord("a") println chr(97)   println ord("π") println chr(960)
http://rosettacode.org/wiki/Collections
Collections
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Collections are abstractions to represent sets of values. In statically-typed languages, the values are typically of a common data type. Task Create a collection, and add a few values to it. See also Array Associative array: Creation, Iteration Collections Compound data type Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal Linked list Queue: Definition, Usage Set Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal Stack
#Tcl
Tcl
set c [list] ;# create an empty list # fill it lappend c 10 11 13 set c [linsert $c 2 "twelve goes here"] # iterate over it foreach elem $c {puts $elem}   # pass to a proc proc show_size {l} { puts [llength $l] } show_size $c
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#QB64
QB64
$NOPREFIX PRINT DIREXISTS("docs") PRINT DIREXISTS("\docs") PRINT FILEEXISTS("input.txt") PRINT FILEEXISTS("\input.txt")
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#R
R
file.exists("input.txt") file.exists("/input.txt") file.exists("docs") file.exists("/docs")   # or file.exists("input.txt", "/input.txt", "docs", "/docs")
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Neko
Neko
// An 'a' and a 'b' var s = "a"; var c = 98; var h = " ";   $print("Character code for 'a': ", $sget(s, 0), "\n");   $sset(h, 0, c); $print("Character code ", c, ": ", h, "\n");
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#NESL
NESL
char_code(`a);   it = 97 : int
http://rosettacode.org/wiki/Collections
Collections
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Collections are abstractions to represent sets of values. In statically-typed languages, the values are typically of a common data type. Task Create a collection, and add a few values to it. See also Array Associative array: Creation, Iteration Collections Compound data type Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal Linked list Queue: Definition, Usage Set Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal Stack
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT   collection=* DATA apple DATA banana DATA orange   morestuff=* DATA peaches DATA apple   collection=APPEND(collection,morestuff) TRACE *collection  
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Racket
Racket
  #lang racket   ;; here (file-exists? "input.txt") (file-exists? "docs")   ;; in the root (file-exists? "/input.txt") (file-exists? "/docs")   ;; or in the root with relative paths (parameterize ([current-directory "/"]) (and (file-exists? "input.txt") (file-exists? "docs")))  
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Raku
Raku
  my $path = "/etc/passwd"; say $path.IO.e ?? "Exists" !! "Does not exist";   given $path.IO { when :d { say "$path is a directory"; } when :f { say "$path is a regular file"; } when :e { say "$path is neither a directory nor a file, but it does exist"; } default { say "$path does not exist" } }
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols nobinary   runSample(arg) return   -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method runSample(arg) private static -- create some sample data: character, hex and unicode samp = ' ' || 'a'.sequence('e') || '$' || '\xa2'.sequence('\xa5') || '\u20a0'.sequence('\u20b5') -- use the C2D C2X D2C and X2C built-in functions say "'"samp"'" say ' | Chr C2D C2X D2C X2C' say '---+ --- ------ ---- --- ---' loop ci = 1 to samp.length cc = samp.substr(ci, 1) cd = cc.c2d -- char to decimal cx = cc.c2x -- char to hexadecimal dc = cd.d2c -- decimal to char xc = cx.x2c -- hexadecimal to char say ci.right(3)"| '"cc"'" cd.right(6) cx.right(4, 0) "'"dc"' '"xc"'" end ci return
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Nim
Nim
echo ord('a') # echoes 97 echo chr(97) # echoes a   import unicode   echo int("π".runeAt(0)) # echoes 960 echo Rune(960) # echoes π
http://rosettacode.org/wiki/Collections
Collections
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Collections are abstractions to represent sets of values. In statically-typed languages, the values are typically of a common data type. Task Create a collection, and add a few values to it. See also Array Associative array: Creation, Iteration Collections Compound data type Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal Linked list Queue: Definition, Usage Set Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal Stack
#UNIX_Shell
UNIX Shell
a_index=(one two three) # create an array with a few elements a_index+=(four five) # append some elements a_index[9]=ten # add a specific index for elem in "${a_index[@]}"; do # interate over the elements echo "$elem" done for idx in "${!a_index[@]}"; do # interate over the array indices printf "%d\t%s\n" $idx "${a_index[idx]}" done
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Raven
Raven
'input.txt' exists if 'input.txt exists' print '/input.txt' exists if '/input.txt exists' print 'docs' isdir if 'docs exists and is a directory' print '/docs' isdir if '/docs exists and is a directory' print
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#REBOL
REBOL
exists? %input.txt exists? %docs/   exists? %/input.txt exists? %/docs/
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#NS-HUBASIC
NS-HUBASIC
10 PRINT CODE "A" 20 PRINT CHR$(38)
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Oberon-2
Oberon-2
MODULE Ascii; IMPORT Out; VAR c: CHAR; d: INTEGER; BEGIN c := CHR(97); d := ORD("a"); Out.Int(d,3);Out.Ln; Out.Char(c);Out.Ln END Ascii.
http://rosettacode.org/wiki/Collections
Collections
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Collections are abstractions to represent sets of values. In statically-typed languages, the values are typically of a common data type. Task Create a collection, and add a few values to it. See also Array Associative array: Creation, Iteration Collections Compound data type Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal Linked list Queue: Definition, Usage Set Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal Stack
#Ursala
Ursala
x = <1,5,6> y = <'foo','bar'> z = 3:<6,8>
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Red
Red
exists? %input.txt exists? %docs/ exists? %/c/input.txt exists? %/c/docs/ exists? %//input.txt exists? %//docs/   >> exists? %`Abdu'l-Bahá.txt == true
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#REXX
REXX
/*REXX program creates a new empty file and directory in current directory and root dir.*/ fn= 'input.txt' /*default name of a file. */ dn= 'docs' /*default name of a directory (folder).*/ @.1= 'current directory'; @.2= 'root directory' /*messages used to indicate which pass.*/ parse upper version v /*obtain name of the REXX being used. */ regina= pos('REGINA' , v)\==0 /*is this the Regina REXX being used? */ r4 = pos('REXX-R4' , v)\==0 /*is this the R4 REXX being used? */ @doesnt= "doesn't exist in the" @does = "does exist in the"   do j=1 for 2; say /* [↑] perform these statements twice.*/ if stream(fn, 'C', "QUERY EXISTS")=='' then say 'file ' fn @doesnt @.j else say 'file ' fn @does @.j   if j==2 then iterate if stream(dn, 'C', "QUERY EXISTS")=='' then say 'directory' dn @doesnt @.j else say 'directory' dn @does @.j if j==1 then select when regina then call chdir '\' /*use Regina's version of CHDIR. */ when r4 then call stream '\', "C", 'CHDIR' /*R4's version. */ otherwise call doschdir '\' /*PC/REXX & Personal REXX version.*/ end /*select*/ end /*j*/ /*stick a fork in it, we're all done. */
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Objeck
Objeck
'a'->As(Int)->PrintLine(); 97->As(Char)->PrintLine();
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Object_Pascal
Object Pascal
Printf.printf "%d\n" (int_of_char 'a'); (* prints "97" *) Printf.printf "%c\n" (char_of_int 97); (* prints "a" *)
http://rosettacode.org/wiki/Collections
Collections
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Collections are abstractions to represent sets of values. In statically-typed languages, the values are typically of a common data type. Task Create a collection, and add a few values to it. See also Array Associative array: Creation, Iteration Collections Compound data type Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal Linked list Queue: Definition, Usage Set Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal Stack
#V
V
[4 3 2 1] 5 swap cons =[5 4 3 2 1]
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Ring
Ring
  aFile = "C:\Ring\ReadMe.txt" see aFile if Fexists(aFile) see " exists" + nl else see " doesn't exist" + nl ok  
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#RLaB
RLaB
  >> isdir("docs") 0 >> isfile("input.txt") 0  
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#OCaml
OCaml
Printf.printf "%d\n" (int_of_char 'a'); (* prints "97" *) Printf.printf "%c\n" (char_of_int 97); (* prints "a" *)
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Oforth
Oforth
'a' println
http://rosettacode.org/wiki/Collections
Collections
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Collections are abstractions to represent sets of values. In statically-typed languages, the values are typically of a common data type. Task Create a collection, and add a few values to it. See also Array Associative array: Creation, Iteration Collections Compound data type Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal Linked list Queue: Definition, Usage Set Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal Stack
#VBA
VBA
Dim coll As New Collection coll.Add "apple" coll.Add "banana"
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Ruby
Ruby
File.file?("input.txt") File.file?("/input.txt") File.directory?("docs") File.directory?("/docs")
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#OpenEdge.2FProgress
OpenEdge/Progress
MESSAGE CHR(97) SKIP ASC("a") VIEW-AS ALERT-BOX.
http://rosettacode.org/wiki/Collections
Collections
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Collections are abstractions to represent sets of values. In statically-typed languages, the values are typically of a common data type. Task Create a collection, and add a few values to it. See also Array Associative array: Creation, Iteration Collections Compound data type Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal Linked list Queue: Definition, Usage Set Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal Stack
#Vim_Script
Vim Script
Dim toys As New List(Of String) toys.Add("Car") toys.Add("Boat") toys.Add("Train")
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Run_BASIC
Run BASIC
files #f,"input.txt" if #f hasanswer() = 1 then print "File does not exist" files #f,"docs" if #f hasanswer() = 1 then print "File does not exist" if #f isDir() = 0 then print "This is a directory"  
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Rust
Rust
use std::fs;   fn main() { for file in ["input.txt", "docs", "/input.txt", "/docs"].iter() { match fs::metadata(file) { Ok(attr) => { if attr.is_dir() { println!("{} is a directory", file); }else { println!("{} is a file", file); } }, Err(_) => { println!("{} does not exist", file); } }; } }  
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Oz
Oz
{System.show &a} %% prints "97" {System.showInfo [97]} %% prints "a"
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#PARI.2FGP
PARI/GP
print(Vecsmall("a")[1]); print(Strchr([72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]))
http://rosettacode.org/wiki/Collections
Collections
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Collections are abstractions to represent sets of values. In statically-typed languages, the values are typically of a common data type. Task Create a collection, and add a few values to it. See also Array Associative array: Creation, Iteration Collections Compound data type Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal Linked list Queue: Definition, Usage Set Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal Stack
#Visual_Basic_.NET
Visual Basic .NET
Dim toys As New List(Of String) toys.Add("Car") toys.Add("Boat") toys.Add("Train")
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Scala
Scala
import java.nio.file.{ Files, FileSystems }   object FileExistsTest extends App {   val defaultFS = FileSystems.getDefault() val separator = defaultFS.getSeparator()   def test(filename: String) { val path = defaultFS.getPath(filename)   println(s"The following ${if (Files.isDirectory(path)) "directory" else "file"} called $filename" + (if (Files.exists(path)) " exists." else " not exists.")) }   // main List("output.txt", separator + "output.txt", "docs", separator + "docs" + separator).foreach(test) }
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Pascal
Pascal
writeln(ord('a')); writeln(chr(97));
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Perl
Perl
use strict; use warnings; use utf8; binmode(STDOUT, ':utf8'); use Encode; use Unicode::UCD 'charinfo'; use List::AllUtils qw(zip natatime);   for my $c (split //, 'AΑА薵') { my $o = ord $c; my $utf8 = join '', map { sprintf "%x ", ord } split //, Encode::encode("utf8", $c); my $iterator = natatime 2, zip @{['Character', 'Character name', 'Ordinal(s)', 'Hex ordinal(s)', 'UTF-8', 'Round trip']}, @{[ $c, charinfo($o)->{'name'}, $o, sprintf("0x%x",$o), $utf8, chr $o, ]}; while ( my ($label, $value) = $iterator->() ) { printf "%14s: %s\n", $label, $value } print "\n"; }
http://rosettacode.org/wiki/Collections
Collections
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Collections are abstractions to represent sets of values. In statically-typed languages, the values are typically of a common data type. Task Create a collection, and add a few values to it. See also Array Associative array: Creation, Iteration Collections Compound data type Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal Linked list Queue: Definition, Usage Set Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal Stack
#Visual_FoxPro
Visual FoxPro
  LOCAL loColl As Collection, o, a1, a2, a3 a1 = CREATEOBJECT("animal", "dog", 4) a2 = CREATEOBJECT("animal", "chicken", 2) a3 = CREATEOBJECT("animal", "snake", 0) loColl = NEWOBJECT("Collection") loColl.Add(a1) loColl.Add(a2) loColl.Add(a3)   FOR EACH o IN loColl FOXOBJECT  ? o.Name, o.Legs ENDFOR   DEFINE CLASS animal As Custom Legs = 0   PROCEDURE Init(tcName, tnLegs) THIS.Name = tcName THIS.Legs = tnLegs ENDPROC   ENDDEFINE  
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Scheme
Scheme
(file-exists? filename)
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Seed7
Seed7
$ include "seed7_05.s7i";   const proc: main is func begin writeln(fileType("input.txt") = FILE_REGULAR); writeln(fileType("/input.txt") = FILE_REGULAR); writeln(fileType("docs") = FILE_DIR); writeln(fileType("/docs") = FILE_DIR); end func;
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Phix
Phix
?'A' puts(1,65)
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Phixmonti
Phixmonti
'a' print nl 97 tochar print
http://rosettacode.org/wiki/Collections
Collections
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Collections are abstractions to represent sets of values. In statically-typed languages, the values are typically of a common data type. Task Create a collection, and add a few values to it. See also Array Associative array: Creation, Iteration Collections Compound data type Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal Linked list Queue: Definition, Usage Set Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal Stack
#Wren
Wren
var list = [] // Empty Array list = [1, 2, 3, 4] list.add(5) list.clear() list = [0] * 10 list.count // 10   var map = {} map["key"] = "value" map[3] = 31 map.count // 2 map.clear()   for (e in map.keys) { // Do stuff }
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#SenseTalk
SenseTalk
  put file "input.txt" exists put folder "docs" exists   put file "/input.txt" exists put there is a folder "/docs"  
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Sidef
Sidef
# Here say (Dir.cwd + %f'input.txt' -> is_file); say (Dir.cwd + %d'docs' -> is_dir);   # Root say (Dir.root + %f'input.txt' -> is_file); say (Dir.root + %d'docs' -> is_dir);
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#PHP
PHP
echo ord('a'), "\n"; // prints "97" echo chr(97), "\n"; // prints "a"
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Picat
Picat
main => println(chr(97)), println(ord('a')), println(ord(a)).
http://rosettacode.org/wiki/Collections
Collections
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Collections are abstractions to represent sets of values. In statically-typed languages, the values are typically of a common data type. Task Create a collection, and add a few values to it. See also Array Associative array: Creation, Iteration Collections Compound data type Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal Linked list Queue: Definition, Usage Set Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal Stack
#Z80_Assembly
Z80 Assembly
List: byte 1,2,3,4,5
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Slate
Slate
(File newNamed: 'input.txt') exists (File newNamed: '/input.txt') exists (Directory root / 'input.txt') exists (Directory newNamed: 'docs') exists (Directory newNamed: '/docs') exists
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Smalltalk
Smalltalk
FileDirectory new fileExists: 'c:\serial'. (FileDirectory on: 'c:\') directoryExists: 'docs'.
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#PicoLisp
PicoLisp
: (char "a") -> 97 : (char "字") -> 23383 : (char 23383) -> "字" : (chop "文字") -> ("文" "字") : (mapcar char @) -> (25991 23383)
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#PL.2FI
PL/I
declare 1 u union, 2 c character (1), 2 i fixed binary (8) unsigned; c = 'a'; put skip list (i); /* prints 97 */ i = 97; put skip list (c); /* prints 'a' */
http://rosettacode.org/wiki/Collections
Collections
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task. Collections are abstractions to represent sets of values. In statically-typed languages, the values are typically of a common data type. Task Create a collection, and add a few values to it. See also Array Associative array: Creation, Iteration Collections Compound data type Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal Linked list Queue: Definition, Usage Set Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal Stack
#zkl
zkl
Lists: L(1,2,3).append(4); //-->L(1,2,3,4), mutable list Read only list: ROList(1,2,3).append(4); // creates two lists   Bit bucket: Data(0,Int,1,2,3) // three bytes The "Int" means treat contents as a byte stream Data(0,Int,"foo ","bar") //-->7 bytes Data(0,Int,"foo ").append("bar") //ditto Data(0,Int,"foo\n","bar").readln() //-->"foo\n" Data(0,String,"foo ","bar") //-->9 bytes (2 \0s) Data(0,String,"foo ").append("bar").readln() //-->"foo "
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Standard_ML
Standard ML
OS.FileSys.access ("input.txt", []); OS.FileSys.access ("docs", []); OS.FileSys.access ("/input.txt", []); OS.FileSys.access ("/docs", []);
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Stata
Stata
mata fileexists("input.txt") direxists("docs") end
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#PowerShell
PowerShell
$char = [convert]::toChar(0x2f) #=> /
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Tcl
Tcl
if { [file exists "input.txt"] } { puts "input.txt exists" }   if { [file exists [file nativename "/input.txt"]] } { puts "/input.txt exists" }   if { [file isdirectory "docs"] } { puts "docs exists and is a directory" }   if { [file isdirectory [file nativename "/docs"]] } { puts "/docs exists and is a directory" }
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Prolog
Prolog
?- char_code(a, X). X = 97. ?- char_code(X, 97). X = a.
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Toka
Toka
[ "R" file.open dup 0 <> [ dup file.close ] ifTrue 0 <> ] is exists? " input.txt" exists? . " /input.txt" exists? . " docs" exists? . " /docs" exists? .
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#True_BASIC
True BASIC
SUB opener (a$) WHEN EXCEPTION IN OPEN #1: NAME f$ PRINT f$; " exists" USE PRINT f$; " not exists" END WHEN CLOSE #1 END SUB   LET f$ = "input.txt" CALL opener (f$) LET f$ = "\input.txt" CALL opener (f$) LET f$ = "docs\nul" CALL opener (f$) LET f$ = "\docs\nul" CALL opener (f$)   LET f$ = "empty.tru" CALL opener (f$) LET f$ = "`Abdu'l-Bahá.txt" CALL opener (f$) END
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#PureBasic
PureBasic
If OpenConsole() ;Results are the same when compiled for Ascii or Unicode charCode.c = 97 Char.s = "a" PrintN(Chr(charCode)) ;prints a PrintN(Str(Asc(Char))) ;prints 97   Print(#CRLF$ + #CRLF$ + "Press ENTER to exit") Input() CloseConsole() EndIf
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT file="input.txt",directory="docs" IF (file=='file') THEN PRINT file, " exists" ELSE PRINT/ERROR file," not exists" ENDIF IF (directory=='project') THEN PRINT directory," exists" ELSE PRINT/ERROR "directory ",directory," not exists" ENDIF  
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#UNIX_Shell
UNIX Shell
test -f input.txt test -f /input.txt test -d docs test -d /docs
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Python
Python
print ord('a') # prints "97" print chr(97) # prints "a"
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Ursa
Ursa
def exists (string filename) decl file f try f.open filename return true catch ioerror return false end try end exists
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Quackery
Quackery
Welcome to Quackery. Enter "leave" to leave the shell. /O> char a ... Stack: 97 /O> emit ... a Stack empty.
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#R
R
ascii <- as.integer(charToRaw("hello world")); ascii text <- rawToChar(as.raw(ascii)); text
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Vala
Vala
int main (string[] args) { string[] files = {"input.txt", "docs", Path.DIR_SEPARATOR_S + "input.txt", Path.DIR_SEPARATOR_S + "docs"}; foreach (string f in files) { var file = File.new_for_path (f); print ("%s exists: %s\n", f, file.query_exists ().to_string ()); } return 0; }
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#VBA
VBA
  Option Explicit   Sub Main_File_Exists() Dim myFile As String, myDirectory As String   myFile = "Abdu'l-Bahá.txt" myDirectory = "C:\" Debug.Print File_Exists(myFile, myDirectory) End Sub   Function File_Exists(F As String, D As String) As Boolean If F = "" Then File_Exists = False Else D = IIf(Right(D, 1) = "\", D, D & "\") File_Exists = (Dir(D & F) <> "") End If End Function  
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Racket
Racket
#lang racket   (define (code ch) (printf "The unicode number for ~s is ~a\n" ch (char->integer ch))) (code #\a) (code #\λ)   (define (char n) (printf "The unicode number ~a is the character ~s\n" n (integer->char n))) (char 97) (char 955)
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Raku
Raku
for 'AΑА𪚥🇺🇸👨‍👩‍👧‍👦'.comb { .put for [ 'Character', 'Character name', 'Unicode property', 'Unicode script', 'Unicode block', 'Ordinal(s)', 'Hex ordinal(s)', 'UTF-8', 'UTF-16LE', 'UTF-16BE', 'Round trip by name', 'Round trip by ordinal' ]».fmt('%21s:') Z [ $_, .uninames.join(', '), .uniprops.join(', '), .uniprops('Script').join(', '), .uniprops('Block').join(', '), .ords, .ords.fmt('0x%X'), .encode('utf8' )».fmt('%02X'), .encode('utf16le')».fmt('%02X').join.comb(4), .encode('utf16be')».fmt('%02X').join.comb(4), .uninames».uniparse.join, .ords.chrs ]; say ''; }
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#VBScript
VBScript
Set FSO = CreateObject("Scripting.FileSystemObject")   Function FileExists(strFile) If FSO.FileExists(strFile) Then FileExists = True Else FileExists = False End If End Function   Function FolderExists(strFolder) If FSO.FolderExists(strFolder) Then FolderExists = True Else Folderexists = False End If End Function   '''''Usage (apostrophes indicate comments-this section will not be run)''''' 'If FileExists("C:\test.txt") Then ' MsgBox "It Exists!" 'Else ' Msgbox "awww" 'End If ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''   'Shorter version   If CreateObject("Scripting.FileSystemObject").FileExists("d:\test.txt") Then Wscript.Echo "File Exists" Else Wscript.Echo "File Does Not Exist") End If      
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Vedit_macro_language
Vedit macro language
// In current directory if (File_Exist("input.txt")) { M("input.txt exists\n") } else { M("input.txt does not exist\n") } if (File_Exist("docs/nul", NOERR)) { M("docs exists\n") } else { M("docs does not exist\n") }   // In the root directory if (File_Exist("/input.txt")) { M("/input.txt exists\n") } else { M("/input.txt does not exist\n") } if (File_Exist("/docs/nul", NOERR)) { M("/docs exists\n") } else { M("/docs does not exist\n") }
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#RapidQ
RapidQ
  Print Chr$(97) Print Asc("a")  
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Red
Red
Red [] print to-integer first "a" ;; -> 97 print to-integer #"a"  ;; -> 97 print to-binary "a"  ;; -> #{61} print to-char 97  ;; -> a  
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Visual_Basic
Visual Basic
  'declarations: Public Declare Function GetFileAttributes Lib "kernel32" _ Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long Public Const INVALID_FILE_ATTRIBUTES As Long = -1 Public Const ERROR_SHARING_VIOLATION As Long = 32&   'implementation: Public Function FileExists(ByVal Filename As String) As Boolean Dim l As Long l = GetFileAttributes(Filename) If l <> INVALID_FILE_ATTRIBUTES Then FileExists = ((l And vbDirectory) = 0) ElseIf Err.LastDllError = ERROR_SHARING_VIOLATION Then FileExists = True End If End Function  
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Retro
Retro
'c putc
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#REXX
REXX
/*REXX program displays a char's ASCII code/value (or EBCDIC if run on an EBCDIC system)*/ yyy= 'c' /*assign a lowercase c to YYY. */ yyy= "c" /* (same as above) */ say 'from char, yyy code=' yyy   yyy= '63'x /*assign hexadecimal 63 to YYY. */ yyy= '63'X /* (same as above) */ say 'from hex, yyy code=' yyy   yyy= x2c(63) /*assign hexadecimal 63 to YYY. */ say 'from hex, yyy code=' yyy   yyy= '01100011'b /*assign a binary 0011 0100 to YYY. */ yyy= '0110 0011'b /* (same as above) */ yyy= '0110 0011'B /* " " " */ say 'from bin, yyy code=' yyy   yyy= d2c(99) /*assign decimal code 99 to YYY. */ say 'from dec, yyy code=' yyy   say /* [↓] displays the value of YYY in ··· */ say 'char code: ' yyy /* character code (as an 8-bit ASCII character).*/ say ' hex code: ' c2x(yyy) /* hexadecimal */ say ' dec code: ' c2d(yyy) /* decimal */ say ' bin code: ' x2b( c2x(yyy) ) /* binary (as a bit string) */ /*stick a fork in it, we're all done with display*/
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Visual_Basic_.NET
Visual Basic .NET
'Current Directory Console.WriteLine(If(IO.Directory.Exists("docs"), "directory exists", "directory doesn't exists")) Console.WriteLine(If(IO.Directory.Exists("output.txt"), "file exists", "file doesn't exists"))   'Root Console.WriteLine(If(IO.Directory.Exists("\docs"), "directory exists", "directory doesn't exists")) Console.WriteLine(If(IO.Directory.Exists("\output.txt"), "file exists", "file doesn't exists"))   'Root, platform independent Console.WriteLine(If(IO.Directory.Exists(IO.Path.DirectorySeparatorChar & "docs"), _ "directory exists", "directory doesn't exists")) Console.WriteLine(If(IO.Directory.Exists(IO.Path.DirectorySeparatorChar & "output.txt"), _ "file exists", "file doesn't exists"))
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Ring
Ring
  see ascii("a") + nl see char(97) + nl  
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Ruby
Ruby
> "a".ord => 97 > 97.chr => "a"
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Vlang
Vlang
// Check file exists in V // Tectonics: v run check-that-file-exists.v module main import os   // starts here pub fn main() { // file and directory checks _ := os.execute("touch input.txt") println("os.is_file('input.txt'): ${os.is_file('input.txt')}")   // make doc directory in current dir if it doesn't exist _ := os.execute("mkdir -p doc") println("os.is_dir('doc'): ${os.is_dir('doc')}")   // check in the root dir println("os.is_file('/input.txt'): ${os.is_file('/input.txt')}") println("os.is_dir('/doc'): ${os.is_dir('/doc')}")   // check for file, with empty file _ := os.execute("truncate -s 0 empty.txt") println("os.is_file('empty.txt'): ${os.is_file('empty.txt')}")   // check for file, with exotic name wfn := "`Abdu'l-Bahá.txt" efn := wfn.replace_each(["'", r"\'", "`", r"\`"]) _ := os.execute('touch $efn') println('os.is_file("$wfn"): ${os.is_file(wfn)}') }
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Wren
Wren
import "io" for Directory, File   for (name in ["input.txt", "`Abdu'l-Bahá.txt"]) { if (File.exists(name)) { System.print("%(name) file exists and has a size of %(File.size(name)) bytes.") } else { System.print("%(name) file does not exist.") } }   var dir = "docs" // if it exists get number of files it contains if (Directory.exists(dir)) { var files = Directory.list(dir).count System.print("%(dir) directory exists and contains %(files) files.") } else { System.print("%(dir) directory does not exist.") }
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Run_BASIC
Run BASIC
print chr$(97) 'prints a print asc("a") 'prints 97
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Rust
Rust
use std::char::from_u32;   fn main() { //ascii char println!("{}", 'a' as u8); println!("{}", 97 as char);   //unicode char println!("{}", 'π' as u32); println!("{}", from_u32(960).unwrap()); }
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#XPL0
XPL0
  int FD; \file descriptor [Trap(false); \prevent errors from aborting program FD:= FOpen("input.txt", 0); if GetErr then Text(0, "input.txt doesn't exist^m^j"); FD:= FOpen("dir", 0); if GetErr then Text(0, "dir doesn't exist^m^j"); FD:= FOpen("/input.txt", 0); if GetErr then Text(0, "/input.txt doesn't exist^m^j"); FD:= FOpen("/dir", 0); if GetErr then Text(0, "/dir doesn't exist^m^j"); ]
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#Yabasic
Yabasic
open "foo.bar" for writing as #1 print #1 "Hallo !" close #1 if (not open(1,"foo.bar")) print "Could not open 'foo.bar' for reading" close #1 if (not open(1,"buzz.bar")) print "Could not open 'buzz.bar' for reading"  
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Sather
Sather
class MAIN is main is #OUT + 'a'.int + "\n"; -- or #OUT + 'a'.ascii_int + "\n"; #OUT + CHAR::from_ascii_int(97) + "\n"; end; end;
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Scala
Scala
scala> 'a' toInt res2: Int = 97   scala> 97 toChar res3: Char = a   scala> '\u0061' res4: Char = a   scala> "\uD869\uDEA5" res5: String = 𪚥
http://rosettacode.org/wiki/Check_that_file_exists
Check that file exists
Task Verify that a file called     input.txt     and   a directory called     docs     exist. This should be done twice:     once for the current working directory,   and   once for a file and a directory in the filesystem root. Optional criteria (May 2015):   verify it works with:   zero-length files   an unusual filename:   `Abdu'l-Bahá.txt
#zkl
zkl
File.exists("input.txt") //--> True (in this case a sym link) File.exists("/input.txt") //-->False File.isDir("/") //-->True File.isDir("docs") //-->False  
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Scheme
Scheme
(display (char->integer #\a)) (newline) ; prints "97" (display (integer->char 97)) (newline) ; prints "a"
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Seed7
Seed7
writeln(ord('a')); writeln(chr(97));
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#SenseTalk
SenseTalk
put CharToNum("a") put NumToChar(97)
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#SequenceL
SequenceL
cmd:>asciiToInt('a') 97 cmd:>intToAscii(97) 'a'
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Sidef
Sidef
say 'a'.ord; # => 97 say 97.chr; # => 'a'
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Slate
Slate
$a code. 97 as: String Character.
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#Smalltalk
Smalltalk
($a asInteger) displayNl. "output 97" (Character value: 97) displayNl. "output a"
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#SmileBASIC
SmileBASIC
PRINT CHR$(97) 'a PRINT ASC("a") '97
http://rosettacode.org/wiki/Character_codes
Character codes
Task Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses). Example The character   'a'   (lowercase letter A)   has a code of 97 in ASCII   (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
#SNOBOL4
SNOBOL4
define('chr(n)') :(chr_end) chr &alphabet tab(n) len(1) . chr :s(return)f(freturn) chr_end   define('asc(str)c') :(asc_end) asc str len(1) . c &alphabet break(c) @asc :s(return)f(freturn) asc_end   * # Test and display output = char(65) ;* Built-in output = chr(65) output = asc('A') end