Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,12 @@
# declare a string variable and assign an empty string to it #
STRING s := "";
# test the string is empty #
IF s = "" THEN write( ( "s is empty", newline ) ) FI;
# test the string is not empty #
IF s /= "" THEN write( ( "s is not empty", newline ) ) FI;
# as a string is an array of characters, we could also test for emptyness by #
# checking for lower bound > upper bound #
IF LWB s > UPB s THEN write( ( "s is still empty", newline ) ) FI

View file

@ -0,0 +1,30 @@
-- assign empty string to str
set str to ""
-- check if string is empty
if str is "" then
-- str is empty
end if
-- or
if id of str is {} then
-- str is empty
end if
-- or
if (count of str) is 0 then
-- str is empty
end if
-- check if string is not empty
if str is not "" then
-- string is not empty
end if
-- or
if id of str is not {} then
-- str is not empty
end if
-- or
if (count of str) is not 0 then
-- str is not empty
end if

View file

@ -0,0 +1,6 @@
blsq ) ""
""
blsq ) ""nu
1
blsq ) "a"nu
0

View file

@ -5,8 +5,12 @@ empty_string == ""
# => true
String.length(empty_string) == 0
# => true
byte_size(empty_string) == 0
# => true
not_empty_string == ""
# => false
String.length(not_empty_string) == 0
# => false
byte_size(not_empty_string) == 0
# => false

View file

@ -1,3 +1,6 @@
: empty? ( c-addr u -- ? ) nip 0= ;
\ string words operate on the address and count left on the stack by a string
\ ? means the word returns a true/false flag on the stack
s" " dup . empty? . \ 0 -1
: empty? ( c-addr u -- ? ) nip 0= ;
: filled? ( c-addr u -- ? ) empty? 0= ;
: ="" ( c-addr u -- ) drop 0 ; \ It's OK to copy syntax from other languages

View file

@ -0,0 +1,11 @@
SUBROUTINE TASTE(T)
CHARACTER*(*) T !This form allows for any size.
IF (LEN(T).LE.0) WRITE(6,*) "Empty!"
IF (LEN(T).GT.0) WRITE(6,*) "Not empty!"
END
CHARACTER*24 TEXT
CALL TASTE("")
CALL TASTE("This")
TEXT = "" !Fills the entire variable with space characters.
CALL TASTE(TEXT) !Passes all 24 of them. Result is Not empty!
END

View file

@ -0,0 +1,11 @@
blank = ""
nonblank = "!"
println("The length of blank is ", length(blank))
println("That blank is empty is ", isempty(blank))
println("That blank is not empty is ", !isempty(blank))
println()
println("The length of nonblank is ", length(nonblank))
println("That nonblank is empty is ", isempty(nonblank))
println("That nonblank is not empty is ", !isempty(nonblank))

View file

@ -1,3 +1,3 @@
my $s = '';
say 'String is empty' unless $s.chars;
say 'String is not empty' if $s.chars;
say 'String is empty' unless $s;
say 'String is not empty' if $s;

View file

@ -0,0 +1,2 @@
[string]::IsNullOrEmpty("")
[string]::IsNullOrEmpty("a")

View file

@ -0,0 +1,8 @@
"Put an empty string in a slot called 'str'"
str: ''.
"Check that string is empty"
str isEmpty.
"Check that string is not empty"
str isEmpty not.

View file

@ -1,6 +1,9 @@
@(do (defvar *a* "")
(if (equal *a* "")
(format t "empty string\n"))
(set *a* "nonempty")
(if (zerop (length *a*))
(format t "guess what?\n")))
(defvarl a "")
(if (equal a "")
(format t "empty string\n"))
(set a "nonempty")
(if (zerop (length a))
(format t "guess what?\n"))