June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,14 +1,12 @@
if x == 0:
foo()
elif x == 1:
bar()
elif x == 2:
baz()
else:
qux()
if x == 0: foo()
elif x == 1: bar()
elif x == 2: baz()
else: qux()
x
| 0 -> foo()
| 1 -> bar()
| 2 -> baz()
| _ -> qux()
| 0 => foo()
| 1 => bar()
| 2 => baz()
| _ => qux()
(a) ? b : c

View file

@ -0,0 +1,19 @@
for i = 0 to 1
for j = 0 to 1
print i
print j
if (i) then
if (j) then
print "i is true j is true"
else
print "i is true j is false"
end if
else
if (j) then
print "i is false j is true"
else
print "i is false j is false"
end if
end if
next j
next i

View file

@ -0,0 +1,2 @@
COND=(rcval,relop,step)
relop is a relational opeator : EQ NE GT LT GE LE (= ¬= < > <= >=)

View file

@ -0,0 +1 @@
if rcval relop step.rc then not execute the current step

View file

@ -0,0 +1 @@
//STEP6 EXEC PGM=MYPROG,COND=(0,NE,STEP3)

View file

@ -0,0 +1 @@
COND=((rcval1,relop1,step1),(rcval2,relop2,step2),...)

View file

@ -0,0 +1 @@
if rcval1 relop1 step1.rc or rcval2 relop2 step2.rc or ... then not execute the current step

View file

@ -0,0 +1 @@
//STEP6 EXEC PGM=MYPROG,COND=((4,LE,STEP1),(8,LE,STEP3))

View file

@ -0,0 +1,18 @@
function test(x, y)
if x < y
println("x is less than y")
elseif x > y
println("x is greater than y")
else
println("x is equal to y")
end
end
julia> test(1, 2)
x is less than y
julia> test(2, 1)
x is greater than y
julia> test(1, 1)
x is equal to y

View file

@ -0,0 +1 @@
a ? b : c

View file

@ -1,5 +1,5 @@
given lc prompt("Done? ") {
when 'yes' { return }
when 'no' { next }
default { say "Please answer either yes or not." }
default { say "Please answer either yes or no." }
}

View file

@ -0,0 +1,2 @@
>> if 10 > 2 [print "ten is bigger"]
ten is bigger

View file

@ -0,0 +1,2 @@
>> either 3 > 2 [print "Three larger"][print "Nope!"]
Three larger

View file

@ -0,0 +1,22 @@
n: 50
case [
n < 10 [print "small number"]
n < 100 [print "medium number"]
n < 1000 [print "large number"]
true [print "none of these"]
]
medium number
;CASE/ALL Prints all that are true
n: 50
case/all [
n < 10 [print "small number"]
n < 100 [print "medium number"]
n < 1000 [print "large number"]
true [print "none of these"]
]
medium number
large number
none of these

View file

@ -0,0 +1,17 @@
switch "india" [
"a" [print "string"]
23 [print "integer"]
"India" [print "The country India"]
]
The country India
switch/default "U.S." [
"a" [print "string"]
23 [print "integer"]
"India" [print "The country India"]
][
print "no match"
]
no match

View file

@ -1,21 +1,21 @@
trait PrintType {
fn print_type();
fn print_type(&self);
}
impl PrintType for char {
fn print_type() {
fn print_type(&self) {
println!("char");
}
}
impl PrintType for f64 {
fn print_type() {
fn print_type(&self) {
println!("64-bit float");
}
}
fn prints_type_of_args<T,U>(arg1: T, arg2: U)
where T: PrintType
fn prints_type_of_args<T, U>(arg1: &T, arg2: &U)
where T: PrintType,
U: PrintType
{
arg1.print_type();
@ -23,6 +23,6 @@ fn prints_type_of_args<T,U>(arg1: T, arg2: U)
}
fn main() {
prints_type_of_args('a', 2.0);
prints_type_of_args('a', 'b');
prints_type_of_args(&'a', &2.0);
prints_type_of_args(&'a', &'b');
}

View file

@ -1,6 +1,6 @@
if some_conditional {
do_stuff();
} else if some_other_conditional
} else if some_other_conditional {
do_other_stuff();
} else {
destroy_humanity();

View file

@ -2,8 +2,8 @@ fn some_other_function(p: Option<Point>) {
match p {
Some(Point { x: 0, y: 0 }) => println!("Point is on origin"),
Some(Point { x: 0, y: _ }) | Some(Point { x: _, y: 0 }) => println!("Point is on an axis"),
Some(Point {x: a, y: b}) if a == b println!("x and y are the same value"),
Some(Point {x: ref mut a, y: ref b}) if x > 4 && y < 2 => println!("we got a mutable reference to x-value and an immutable reference to y-value."),
Some(Point {x: a, y: b}) if a == b => println!("x and y are the same value"),
Some(Point {x: ref mut a, y: ref b}) if *a > 4 && *b < 2 => println!("we got a mutable reference to x-value and an immutable reference to y-value."),
op @ Some(p) => println!("op is the Option<Point> while p is the contained Point"),
None => println!("We didn't get a point"),
}

View file

@ -0,0 +1,11 @@
clear
set obs 4
gen a = cond(mod(_n, 2)==1, "A", "B")
list, noobs noheader
+---+
| A |
| B |
| A |
| B |
+---+

View file

@ -0,0 +1,34 @@
program isprime
sca n = `0'
sca p = 1
if n<5 {
if n!=2 & n!=3 {
sca p = 0
}
}
else {
if mod(n, 2)==0 {
sca p = 0
}
else {
sca k=3
while k*k<=n {
if mod(n, k)==0 {
sca p = 0
continue, break
}
sca k = k+2
}
}
}
if p {
di "`n' is prime."
}
else {
di "`n' is not prime."
}
end
isprime `=10^12-11'
999999999989 is prime.

View file

@ -0,0 +1,6 @@
clear
set obs 100
count
100
count if mod(_n, 3)==0
33

View file

@ -0,0 +1,13 @@
function isprime(n) {
if (n<5) return(n==2 | n==3)
else if (mod(n, 2)==0) return(0)
else {
for (k=3; k*k<=n; k=k+2) {
if (mod(n, k)==0) return(0)
}
return(1)
}
}
isprime(10^12-11)
1

View file

@ -0,0 +1,6 @@
function fib(n) {
return(n<2 ? n : fib(n-1)+fib(n-2))
}
fib(10)
55

View file

@ -0,0 +1,25 @@
Sub C_S_If()
Dim A$, B$
A = "Hello"
B = "World"
'test
If A = B Then Debug.Print A & " = " & B
'other syntax
If A = B Then
Debug.Print A & " = " & B
Else
Debug.Print A & " and " & B & " are differents."
End If
'other syntax
If A = B Then
Debug.Print A & " = " & B
Else: Debug.Print A & " and " & B & " are differents."
End If
'other syntax
If A = B Then Debug.Print A & " = " & B _
Else Debug.Print A & " and " & B & " are differents."
'other syntax
If A = B Then Debug.Print A & " = " & B Else Debug.Print A & " and " & B & " are differents."
If A = B Then Debug.Print A & " = " & B Else: Debug.Print A & " and " & B & " are differents."
End Sub

View file

@ -0,0 +1,16 @@
Sub C_S_ElseIf()
Dim A$, B$
A = "Hello"
B = "World"
'test
If A = B Then Debug.Print A & " = " & B
'other syntax
If A = B Then
Debug.Print A & " = " & B
ElseIf A > B Then
Debug.Print A & " > " & B
Else
Debug.Print A & " < " & B
End If
End Sub

View file

@ -0,0 +1,52 @@
Sub C_S_Select_Case()
'With Strings
Dim A$, C&
A = "Hello"
Select Case A
Case "World"
Debug.Print "A = World"
Case "Hello"
Debug.Print "A = Hello"
Case Else
Debug.Print "You make a mistake"
End Select
'With numerics
C = 11
Select Case C
Case Is <= 10
Debug.Print "C <= 10"
Case Is < 20, Is > 10
Debug.Print "10 < C < 20"
Case Is >= 20
Debug.Print "C >= 20"
End Select
'Select Case Boolean
'With Strings
Select Case False
Case A <> "Hello"
Debug.Print "A = Hello"
Case A Like "*orl*"
Debug.Print "A Not Like *orl*"
Case Else
Debug.Print "You make a mistake"
End Select 'return : "A = Hello"
'Other conditions's order
Select Case False
Case A Like "*orl*"
Debug.Print "A Not Like *orl*"
Case A <> "Hello"
Debug.Print "A = Hello"
Case Else
Debug.Print "You make a mistake"
End Select 'return : "A Not Like *orl*"
'With numerics
Select Case True
Case C <= 10
Debug.Print "C <= 10"
Case C < 20, C > 10
Debug.Print "10 < C < 20"
Case C >= 20
Debug.Print "C >= 20"
End Select
End Sub

View file

@ -0,0 +1,6 @@
Sub C_S_IIF()
Dim myName
myName = 2
Debug.Print IIf(myName = 1, "Bryan", "Justin")
'return : Justin
End Sub

View file

@ -0,0 +1,6 @@
Sub C_S_Switch()
Dim myName
myName = 2
Debug.Print Switch(myName = 1, "Bryan", myName = 2, "Justin", myName = 3, "John")
'return : Justin
End Sub

View file

@ -0,0 +1,20 @@
If condition Then
statement
End If
If condition Then
statement
Else
statement
End If
If condition1 Then
statement
ElseIf condition2 Then
statement
...
ElseIf conditionN Then
statement
Else
statement
End If

View file

@ -0,0 +1,3 @@
If condition Then statement
If condition Then statement Else statement

View file

@ -0,0 +1,19 @@
Select Case Expression
Case Value1: statement
Case Value2: statement
...
Case ValueN: statement
Case Else: statement
End Select
Select Case Expression
Case Value1
statements
Case Value2
statements
...
Case ValueN
statements
Case Else
statements
End Select

View file

@ -0,0 +1 @@
IIf(expr, then-value, else-value)

View file

@ -0,0 +1,3 @@
myName = 2
Debug.Print IIf(myName = 1, "John", "Jack")
'return : "Jack")

View file

@ -0,0 +1 @@
Switch(expr-1, value-1[, expr-2, value-2 [, expr-n,value-n]])

View file

@ -0,0 +1,3 @@
myName = 2
Debug.Print Switch(myName = 1, "James", myName = 2, "Jacob", myName = 3, "Jeremy")
'return : "Jacob"