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,16 @@
fun main(args): ## Array[Str]
let a = "astro"
let b = "astro"
print
..("Case sensitive comparisons:\n")
..("astro and astro are equal = $(a == b)")
..("astro and astro are not equal = $(a != b)")
..("astro comes before astro = $(a < b)")
..("astro comes after astro = $(a > b)")
..("\nCase insensitive comparisons:\n")
..("astro and astro are equal = $(a == b.lower())")
..("astro and astro are not equal = $(a != b.lower())")
..("astro comes before astro = $(a < b.lower())")
..("astro comes after astro = $(a > b.lower())")
fun compare(a, b):
print("\n$a is of type $(typeof(a)) and $b is of type $(typeof(b))")
if a < b: print("$a is strictly less than $b")
if a <= b: print("$a is less than or equal to $b")
if a > b: print("$a is strictly greater than $b")
if a >= b: print("$a is greater than or equal to $b")
if a == b: print("$a is equal to $b")
if a != b: print("$a is not equal to $b")
if a is b: print("$a has object identity with $b")
if a is not b: print("$a has negated object identity with $b")
compare("YUP", "YUP")
compare('a', 'z')
compare("24", "123")
compare(24, 123)
compare(5.0, 5)

View file

@ -0,0 +1,18 @@
USING: ascii math.order sorting.human ;
IN: scratchpad "foo" "bar" = . ! compare for equality
f
IN: scratchpad "foo" "bar" = not . ! compare for inequality
t
IN: scratchpad "foo" "bar" before? . ! lexically ordered before?
f
IN: scratchpad "foo" "bar" after? . ! lexically ordered after?
t
IN: scratchpad "Foo" "foo" <=> . ! case-sensitive comparison
+lt+
IN: scratchpad "Foo" "foo" [ >lower ] bi@ <=> . ! case-insensitive comparison
+eq+
IN: scratchpad "a1" "a03" <=> . ! comparing numeric strings
+gt+
IN: scratchpad "a1" "a03" human<=> . ! comparing numeric strings like a human
+lt+

View file

@ -0,0 +1,35 @@
/* created by Aykayayciti Earl Lamont Montgomery
April 9th, 2018 */
e = "early"
l = "toast"
g = "cheese"
b = "cheese"
e2 = "early"
num1 = 123
num2 = 456
> e == e2 ? @ "$e equals $e2" : @ "$e does not equal $e2"
> e != e2 ? @ "$e does not equal $e2": @ "$e equals $e2"
// produces -1 for less than
> b.cmpi(l) == 1 ? @ "$b is grater than $l" : @ "$l is grater than $b"
// produces 1 for greater than
> l.cmpi(b) == 1 ? @ "$l is grater than $b" : @ "$b is grater than $l"
// produces 0 for equal (but could be greater than or equal)
> b.cmpi(g) == 1 or b.cmpi(g) == 0 ? @ "$b is grater than or equal to $g" : @ "$b is not >= $g"
// produces 0 for equal (but could be less than or equal)
>b.cmpi(g) == -1 or b.cmpi(g) == 0 ? @ "$b is less than or equal to $g" : @ "$b is not <= $g"
function NumCompare(num1, num2)
if num1 < num2
ans = " < "
elif num1 > num2
ans = " > "
else
ans = " = "
end
return ans
end
result = NumCompare(num1, num2)
> @ "$num1 $result $num2"