1. Standard Lib Func for string type?
- Posted by euphoric (admin) Apr 20, 2009
- 814 views
Is there a function or type definition in the standard library for a string type? Basically, I just want to distinguish between "this is a string" and { "this is a string" }, one of which is a string and the other is a sequence of strings.
If there is not yet one, I would suggest at least an all_atoms() function, which returns True if all elements of the sequence are atoms.
2. Re: Standard Lib Func for string type?
- Posted by unkmar Apr 20, 2009
- 874 views
Is there a function or type definition in the standard library for a string type? Basically, I just want to distinguish between "this is a string" and { "this is a string" }, one of which is a string and the other is a sequence of strings.
If there is not yet one, I would suggest at least an all_atoms() function, which returns True if all elements of the sequence are atoms.
I don't know if there is one in the standard libs. Might be. But I know I wrote one many years ago. In fact, something very close is in my math lib. bigfixed - http://malcom.unkmar.com/hol/FilesEu/bigfixed-0.6704.zip
global type string(object x) -- check for flatness. -- Any embedded sequences? if atom(x) then return 0 end if for index = 1 to length(x) do if sequence(x[index]) or not integer(x[index]) or (0 > x[index])or (x[index] > 255) then return 0 end if end for return 1 end type
The code above was modified from the bigfixed lib to add the restriction of integer values between 0 and 255.
Unkmar
3. Re: Standard Lib Func for string type?
- Posted by DerekParnell (admin) Apr 20, 2009
- 861 views
Is there a function or type definition in the standard library for a string type?
In the V4 standard library (std/types.e) there are currently the types ...
- t_ascii - All elements must be integers in the range 0-127 inclusive.
- t_bytearray - All elements must be integers in the range 0-255 inclusive.
I will add a couple more later today ...
- t_intarray - All elements must be integers.
- t_atomarray - All elements must be atoms.
- t_seqarray - All elements must be sequences.
-- example include std/types.e t_bytearray myString myString = "abc def" -- ok myString = {"abc def"} -- fails
4. Re: Standard Lib Func for string type?
- Posted by DerekParnell (admin) Apr 20, 2009
- 855 views
I will add a couple more later today ...
- t_intarray - All elements must be integers.
- t_atomarray - All elements must be atoms.
- t_seqarray - All elements must be sequences.
I should have matched the library API and your requirements more carefully ... the t_ascii and t_bytearray types are not what you need after all. And there is already the types ...
- t_text - data must be a sequence of non-negative integers (this allows for Unicode characters)
- integer_array - data must be a sequence of integers.
- number_array - data must be a sequence of numbers (atoms).
So I won't add the types I said I would but instead add ...
- ascii_string - data must be an array of integers in the range [0 .. 127]
- string - data must be an array of integers in the range [0 .. 255]
In future there will also be ...
- utf8 - data is a sequence of UTF8 code points.
- utf16 - data is a sequence of UTF16 code points.
- utf32 - data is a sequence of UTF32 code points.
5. Re: Standard Lib Func for string type?
- Posted by DerekParnell (admin) Apr 20, 2009
- 833 views
Ok, the v4 standard library (std/types.e) now also has the types ...
- ascii_string
- string
- sequence_array
-- examples ascii_string AS AS = "abc" -- ok AS = {65, 89, 201} -- fails as 201 is not an ASCII character. AS = 'a' -- fails (not a sequence) AS = {65, 89, 100.2} -- fails as 100.2 is not a character. AS = {"abc"} -- fails string STR STR = "abc" -- ok STR = {65, 89, 201} -- ok STR = 'a' -- fails (not a sequence) STR = {65, 89, 100.2} -- fails as 100.2 is not a character. STR = {"abc"} -- fails
6. Re: Standard Lib Func for string type?
- Posted by bernie Apr 20, 2009
- 850 views
Is there a function or type definition in the standard library for a string type? Basically, I just want to distinguish between "this is a string" and { "this is a string" }, one of which is a string and the other is a sequence of strings.
If there is not yet one, I would suggest at least an all_atoms() function, which returns True if all elements of the sequence are atoms.
-- Thats easy to determine include std/sequence.e procedure check(sequence s) if atom(s[$]) then puts(1,"It is a sequence\n") elsif sequence(s[$]) then puts(1,"It is a sequence in a sequence\n") else puts(1,"Do not know ?\n") end if end procedure sequence s1 = {"abcdefghi"}, s2 = "abcdefghi" check(s1) check(s2) if getc(0) then end if -- pause
7. Re: Standard Lib Func for string type?
- Posted by euphoric (admin) Apr 20, 2009
- 847 views
Ok, the v4 standard library (std/types.e) now also has the types ...
- ascii_string
- string
- sequence_array
Thanks Derek.
8. Re: Standard Lib Func for string type?
- Posted by euphoric (admin) Apr 20, 2009
- 839 views
Ok, the v4 standard library (std/types.e) now also has the types ...
- ascii_string
- string
- sequence_array
Those can be used like standard functions, right?
if string(s) then s = {s} end if
9. Re: Standard Lib Func for string type?
- Posted by DerekParnell (admin) Apr 20, 2009
- 828 views
- Last edited Apr 21, 2009
Ok, the v4 standard library (std/types.e) now also has the types ...
- ascii_string
- string
- sequence_array
Those can be used like standard functions, right?
Yep, that's 100% correct.
-- example object s = funcX() if string(s) then s = {s} end if
10. Re: Standard Lib Func for string type?
- Posted by DerekParnell (admin) Apr 20, 2009
- 851 views
- Last edited Apr 21, 2009
Is there a function or type definition in the standard library for a string type? Basically, I just want to distinguish between "this is a string" and { "this is a string" }, one of which is a string and the other is a sequence of strings.
If there is not yet one, I would suggest at least an all_atoms() function, which returns True if all elements of the sequence are atoms.
-- Thats easy to determine include std/sequence.e procedure check(sequence s) if atom(s[$]) then puts(1,"It is a sequence\n") elsif sequence(s[$]) then puts(1,"It is a sequence in a sequence\n") else puts(1,"Do not know ?\n") end if end procedure sequence s1 = {"abcdefghi"}, s2 = "abcdefghi" check(s1) check(s2) if getc(0) then end if -- pause
Hmmm... but that is not going to check all possiblities. For example ...
check({"abcdef", 'a'}) -- Says this is a sequence.
But the procedure only accepts sequences anyway. It does not report that there is a sequence within the sequence.
It really does need to check every element not just the last one.
11. Re: Standard Lib Func for string type?
- Posted by SDPringle Apr 22, 2009
- 791 views
- Last edited Apr 23, 2009
Horray!