Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,55 @@
main => % - String assignment
S1 = "binary_string",
println(s1=S1),
% Picat has re-assignments (:=/2) as well,
S1 := "another string",
println(s1=S1),
% - String comparison
if S1 == "another string" then
println(same)
else
println(not_same)
end,
% - String cloning and copying
S2 = S1,
println(s2=S2),
S3 = copy_term(S1), % for strings it's the same as =/2
println(s3=S3),
% - Check if a string is empty
if S3 == "" then
println(is_empty)
else
println(not_empty)
end,
% - Append a byte to a string
S3 := S3 ++ "s",
println(s3=S3),
% - Extract a substring from a string
println(substring=S3[5..7]),
println(slice=slice(S1,5,7)),
println(slice=slice(S1,5)),
% - Replace every occurrence of a byte (or a string) in a string with another string
S4 = replace(S3,'s','x'),
println(s4=S4),
% - Join strings
S5 = S1 ++ " " ++ S2,
println(s5=S5),
% using append/4
append(S1," ", S2,S6),
println(s6=S6),
% find positions of substrings
println(find=findall([From,To],find(S5,"str",From,To))),
% split a string
println(split=split(S1," st"))

View file

@ -0,0 +1,16 @@
main =>
println(member=findall(C,(member(C,S1), C @< 'l') )),
% find substrings using append/3
S = "string",
println(append=findall([A,B],append(A,B,S))),
% split around "r"
println(append=findall([A,B],append(A,"r",B,S))),
% select a character and returns the list without that character
println(select=findall([C,NewS],select(C,S,NewS))),
% list comprehension
println(list_comprehension=[ C : C in S5, membchk(C,"aeiou")]),
% sort and remove duplicates
println(sort_remove_dups=sort_remove_dups(S5)).