Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
11
Task/Variables/8th/variables.8th
Normal file
11
Task/Variables/8th/variables.8th
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
\ declare a variable which is initialized to the number '0'
|
||||
var x
|
||||
|
||||
\ declare a variable which is initialized to a string "cat"
|
||||
"cat" var, y
|
||||
|
||||
\ Get the value in x, add 20 and store it:
|
||||
x @ 20 n:+ x !
|
||||
|
||||
\ Change the cat to a dog:
|
||||
"dog" y !
|
||||
15
Task/Variables/Apex/variables.apex
Normal file
15
Task/Variables/Apex/variables.apex
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// If not initialized at class/member level, it will be set to null
|
||||
Integer x = 0;
|
||||
Integer y; // y is null here
|
||||
Integer p,q,r; // declare multiple variables
|
||||
Integer i=1,j=2,k=3; // declare and initialize
|
||||
|
||||
/*
|
||||
* Similar to Integer, below variables can be initialized together separated by ','.
|
||||
*/
|
||||
String s = 'a string';
|
||||
Decimal d = 0.0;
|
||||
Double dbl = 0.0;
|
||||
Blob blb = Blob.valueOf('Any String');
|
||||
Boolean b = true;
|
||||
AClassName cls = new AClassName();
|
||||
1
Task/Variables/Axe/variables-1.axe
Normal file
1
Task/Variables/Axe/variables-1.axe
Normal file
|
|
@ -0,0 +1 @@
|
|||
1→A
|
||||
1
Task/Variables/Axe/variables-2.axe
Normal file
1
Task/Variables/Axe/variables-2.axe
Normal file
|
|
@ -0,0 +1 @@
|
|||
#Realloc(L₂)
|
||||
1
Task/Variables/ChucK/variables-1.chuck
Normal file
1
Task/Variables/ChucK/variables-1.chuck
Normal file
|
|
@ -0,0 +1 @@
|
|||
int a;
|
||||
1
Task/Variables/ChucK/variables-2.chuck
Normal file
1
Task/Variables/ChucK/variables-2.chuck
Normal file
|
|
@ -0,0 +1 @@
|
|||
int b,c,d;
|
||||
1
Task/Variables/ChucK/variables-3.chuck
Normal file
1
Task/Variables/ChucK/variables-3.chuck
Normal file
|
|
@ -0,0 +1 @@
|
|||
0 => int e;
|
||||
41
Task/Variables/Lasso/variables.lasso
Normal file
41
Task/Variables/Lasso/variables.lasso
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// declare thread variable, default type null
|
||||
var(x)
|
||||
$x->type // null
|
||||
|
||||
// declare local variable, default type null
|
||||
local(x)
|
||||
#x->type // null
|
||||
|
||||
// declare thread variable, initialize with a type, in this case integer
|
||||
var(x = integer)
|
||||
|
||||
// declare local variable, initialize with a type, in this case integer
|
||||
local(x = integer)
|
||||
|
||||
// assign a value to the thread var x
|
||||
$x = 12
|
||||
|
||||
// assign a value to the local var x
|
||||
$x = 177
|
||||
|
||||
// a var always has a data type, even if not declared - then it's null
|
||||
// a var can either be assigned a type using the name of the type, or a value that is by itself the type
|
||||
local(y = string)
|
||||
local(y = 'hello')
|
||||
|
||||
'\r'
|
||||
// demonstrating asCopyDeep and relationship between variables:
|
||||
local(original) = array('radish', 'carrot', 'cucumber', 'olive')
|
||||
local(originalaswell) = #original
|
||||
local(copy) = #original->asCopyDeep
|
||||
iterate(#original) => {
|
||||
loop_value->uppercase
|
||||
}
|
||||
#original // modified
|
||||
//array(RADISH, CARROT, CUCUMBER, OLIVE)
|
||||
'\r'
|
||||
#originalaswell // modified as well as it was not a deep copy
|
||||
//array(RADISH, CARROT, CUCUMBER, OLIVE)
|
||||
'\r'
|
||||
#copy // unmodified as it used ascopydeep
|
||||
//array(RADISH, CARROT, CUCUMBER, OLIVE)
|
||||
3
Task/Variables/Lingo/variables-1.lingo
Normal file
3
Task/Variables/Lingo/variables-1.lingo
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
x = 23
|
||||
y = "Hello world!"
|
||||
z = TRUE -- same effect as z = 1
|
||||
3
Task/Variables/Lingo/variables-2.lingo
Normal file
3
Task/Variables/Lingo/variables-2.lingo
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
on foo
|
||||
put x
|
||||
end
|
||||
2
Task/Variables/Lingo/variables-3.lingo
Normal file
2
Task/Variables/Lingo/variables-3.lingo
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
put value("x")
|
||||
-- <Void> -- means: undefined
|
||||
4
Task/Variables/Lingo/variables-4.lingo
Normal file
4
Task/Variables/Lingo/variables-4.lingo
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
on foo
|
||||
x = VOID
|
||||
put x
|
||||
end
|
||||
4
Task/Variables/Lingo/variables-5.lingo
Normal file
4
Task/Variables/Lingo/variables-5.lingo
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
global x
|
||||
on foo
|
||||
put x
|
||||
end
|
||||
4
Task/Variables/Lingo/variables-6.lingo
Normal file
4
Task/Variables/Lingo/variables-6.lingo
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
on foo
|
||||
global x
|
||||
put x
|
||||
end
|
||||
1
Task/Variables/Lingo/variables-7.lingo
Normal file
1
Task/Variables/Lingo/variables-7.lingo
Normal file
|
|
@ -0,0 +1 @@
|
|||
_global.x = 23
|
||||
1
Task/Variables/Lingo/variables-8.lingo
Normal file
1
Task/Variables/Lingo/variables-8.lingo
Normal file
|
|
@ -0,0 +1 @@
|
|||
put _global.x
|
||||
11
Task/Variables/Nim/variables.nim
Normal file
11
Task/Variables/Nim/variables.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
var x: int = 3
|
||||
|
||||
var y = 3 # type inferred to int
|
||||
|
||||
var z: int # initialized to 0
|
||||
|
||||
let a = 13 # immutable variable
|
||||
|
||||
var
|
||||
b, c: int = 10
|
||||
s = "foobar"
|
||||
6
Task/Variables/Oforth/variables.oforth
Normal file
6
Task/Variables/Oforth/variables.oforth
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import: date
|
||||
|
||||
: testVariable
|
||||
| a b c |
|
||||
Date now ->a
|
||||
a println ;
|
||||
2
Task/Variables/Phix/variables-1.phix
Normal file
2
Task/Variables/Phix/variables-1.phix
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
integer x = 25, y = 25, z
|
||||
object {a, b, c} = {{}, 5, "string"}
|
||||
6
Task/Variables/Phix/variables-2.phix
Normal file
6
Task/Variables/Phix/variables-2.phix
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
type hour(integer x)
|
||||
return x >= 0 and x <= 23
|
||||
end type
|
||||
hour h1, h2
|
||||
h1 = 10 -- ok
|
||||
h2 = 25 -- error! program aborts with a message
|
||||
8
Task/Variables/Pony/variables-1.pony
Normal file
8
Task/Variables/Pony/variables-1.pony
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
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
|
||||
6
Task/Variables/Pony/variables-2.pony
Normal file
6
Task/Variables/Pony/variables-2.pony
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
var x: I32 = 10
|
||||
var y: I32 = x = 20
|
||||
try
|
||||
Fact(x == 20) // x gets the new value of 20
|
||||
Fact(y == 10) // y gets the old value of x which is 10
|
||||
end
|
||||
1
Task/Variables/Ring/variables-1.ring
Normal file
1
Task/Variables/Ring/variables-1.ring
Normal file
|
|
@ -0,0 +1 @@
|
|||
<Variable Name> = <Value>
|
||||
16
Task/Variables/Ring/variables-2.ring
Normal file
16
Task/Variables/Ring/variables-2.ring
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
x = "Hello" # x is a string
|
||||
see x + nl
|
||||
x = 5 # x is a number (int)
|
||||
see x + nl
|
||||
x = 1.2 # x is a number (double)
|
||||
see x + nl
|
||||
x = [1,2,3,4] # x is a list
|
||||
see x # print list items
|
||||
x = date() # x is a string contains date
|
||||
see x + nl
|
||||
x = time() # x is a string contains time
|
||||
see x + nl
|
||||
x = true # x is a number (logical value = 1)
|
||||
see x + nl
|
||||
x = false # x is a number (logical value = 0)
|
||||
see x + nl
|
||||
6
Task/Variables/Ring/variables-3.ring
Normal file
6
Task/Variables/Ring/variables-3.ring
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
list = [1,2,3,"four","five"]
|
||||
list2 = list
|
||||
list = []
|
||||
See list # print the first list - no items to print
|
||||
See "********" + nl
|
||||
See list2 # print the second list - contains 5 items
|
||||
2
Task/Variables/Ring/variables-4.ring
Normal file
2
Task/Variables/Ring/variables-4.ring
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
<NUMBER> + <STRING> --> <NUMBER>
|
||||
<STRING> + <NUMBER> --> <STRING>
|
||||
5
Task/Variables/Ring/variables-5.ring
Normal file
5
Task/Variables/Ring/variables-5.ring
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
x = 10 # x is a number
|
||||
y = "20" # y is a string
|
||||
sum = x + y # sum is a number (y will be converted to a number)
|
||||
Msg = "Sum = " + sum # Msg is a string (sum will be converted to a string)
|
||||
see Msg + nl
|
||||
11
Task/Variables/Set-lang/variables.set
Normal file
11
Task/Variables/Set-lang/variables.set
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
set a 0 > Useless intialization - All lowercase variables have an initial value of 0
|
||||
set b 66 > Simple variable assignment - ''b'' is now the ASCII value of 66, or the character 'B'
|
||||
[c=0] set c 5 > Conditional variable assignment - If ''c'' is 0, then set ''c'' to 5
|
||||
set ? 6 > A "goto" command; Setting the ''?'' variable defines the line of code to be executed next
|
||||
set z 1 > This line of code will never be executed, because the previous skipped it
|
||||
set c 10 > Line #5 skipped to here
|
||||
set d A > Assigning a variable to another variable - ''d'' is now ASCII 65, or the character 'A'
|
||||
set b ! > The ''!'' deals with I/O. Setting a variable to it receives an input character and assigns it to the variable
|
||||
set ! a > Setting the exclamation point to a variable outputs that variable
|
||||
set e (d+1) > Combiners are defined inside round brackets - () - and have an addition and a subtraction function
|
||||
set f (e-1) > Variable ''e'' was assigned to ''d'' + 1 (65 + 1 = 66, character B), and ''f'' was assigned to ''e'' - 1 (66 - 1 = 65, character A)
|
||||
71
Task/Variables/Swift/variables.swift
Normal file
71
Task/Variables/Swift/variables.swift
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import Foundation
|
||||
|
||||
// All variables declared outside of a struct/class/etc are global
|
||||
|
||||
// Swift is a typed language
|
||||
// Swift can infer the type of variables
|
||||
var str = "Hello, playground" // String
|
||||
let letStr:String = "This is a constant"
|
||||
|
||||
// However, all variables must be initialized
|
||||
// Intialize variable of type String to nil
|
||||
var str1:String! // str1 is nil
|
||||
|
||||
// Assign value to str1
|
||||
str1 = "foo bar" // str1 is foo bar
|
||||
|
||||
// Swift also has optional types
|
||||
// Declare optional with type of String
|
||||
var optionalString = Optional<String>("foo bar") // (Some "foo bar")
|
||||
|
||||
println(optionalString) // Optional("foo bar")
|
||||
|
||||
// Optionals can also be declared with the shorthand ?
|
||||
var optionalString1:String? = "foo bar"
|
||||
|
||||
// ! can be used to force unwrap but will throw a runtime error if trying to unwrap a nil value
|
||||
println(optionalString1!)
|
||||
|
||||
optionalString1 = nil // Is now nil
|
||||
// println(optionalString1!) would now throw a runtime error
|
||||
|
||||
// Optional chaining can be used to gracefully fail if there is a nil value
|
||||
if let value = optionalString1?.lowercaseString {
|
||||
// Is never executed
|
||||
} else {
|
||||
println("optionalString1 is nil")
|
||||
}
|
||||
|
||||
// Swift also has type aliasing
|
||||
typealias MyNewType = String // MyNewType is an alias of String
|
||||
var myNewTypeString = MyNewType("foo bar")
|
||||
|
||||
// Swift also has special types Any and AnyObject
|
||||
// Any can hold any type
|
||||
// AnyObject can hold any object type
|
||||
let myAnyObjectString:AnyObject = "foo bar"
|
||||
|
||||
// Downcast myAnyObjectString to String
|
||||
if let myString = myAnyObjectString as? String {
|
||||
println(myString) // foo bar
|
||||
} else {
|
||||
println("myString is not a string")
|
||||
}
|
||||
|
||||
// Swift treats functions as first-class
|
||||
// Declare a variable with a type of a function that takes no args
|
||||
// and returns Void
|
||||
var myFunc:(() -> Void)
|
||||
func showScopes() {
|
||||
// Variable is scoped to function
|
||||
let myFunctionVariable = "foo bar function"
|
||||
|
||||
// Nested functions inherit variables declared in enclosing scope
|
||||
func nestFunc() {
|
||||
println(myFunctionVariable)
|
||||
}
|
||||
nestFunc()
|
||||
}
|
||||
|
||||
myFunc = showScopes // myFunc is now showScopes
|
||||
myFunc() // foo bar function
|
||||
43
Task/Variables/Ursa/variables.ursa
Normal file
43
Task/Variables/Ursa/variables.ursa
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# variable declaration
|
||||
#
|
||||
# declare [type] [name]
|
||||
# -or-
|
||||
# decl [type] [name]
|
||||
decl int test
|
||||
|
||||
# initialization / assignment
|
||||
#
|
||||
# the set statement can be used to init variables and
|
||||
# assign values to them
|
||||
set test 10
|
||||
|
||||
# datatypes
|
||||
#
|
||||
# ursa currently has 10 built-in types, but
|
||||
# more may be added in the future.
|
||||
# boolean
|
||||
# double
|
||||
# file
|
||||
# function
|
||||
# int
|
||||
# iodevice
|
||||
# port
|
||||
# serverport
|
||||
# string
|
||||
# task
|
||||
#
|
||||
# also, java classes may be used as data types
|
||||
# cygnus/x ursa
|
||||
|
||||
# scope
|
||||
#
|
||||
# there is a global variable space, and functions
|
||||
# have their own scope. control statements (for,
|
||||
# if, try, while) don't have their own scope yet,
|
||||
# but this will be implemented in the near future
|
||||
|
||||
# referencing
|
||||
#
|
||||
# variables are referenced by their name
|
||||
decl port p
|
||||
out p endl console
|
||||
1
Task/Variables/jq/variables-1.jq
Normal file
1
Task/Variables/jq/variables-1.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
jq -n '1 as $x | (2 as $x | $x) | $x'
|
||||
1
Task/Variables/jq/variables-2.jq
Normal file
1
Task/Variables/jq/variables-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
EXPRESSION as $NAME
|
||||
2
Task/Variables/jq/variables-3.jq
Normal file
2
Task/Variables/jq/variables-3.jq
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
def test: $x;
|
||||
test
|
||||
1
Task/Variables/jq/variables-4.jq
Normal file
1
Task/Variables/jq/variables-4.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
jq --arg x 123 -n -f test.jq
|
||||
Loading…
Add table
Add a link
Reference in a new issue