[sac-user] Strings and StringArrays

Daniel Rolls daniel.rolls.27 at googlemail.com
Wed May 5 14:03:57 CEST 2010


On 4 May 2010, at 23:54, Bullington, Michael wrote:

> To whom it shall concern:
>
> May anybody explain to me the difference between the string "type"  
> and the stringArray "type"?

stringArray, maybe rather unsurprisingly, represents an array of  
strings. There is no support for shape information about stringArray  
in the typesystem. One stringArray represents an array of any shape  
and dimensionally of strings so whereas "int[2]" denotes an array or 2  
integers an array of 2 strings is simply denoted "stringArray". Also  
stringArray was not built to be fast so don't expect blazing speed  
when manipulating stringArrays.

> I am trying to build a string tokenizer.  So far, I have been able  
> to build one in SAC that resembles more of C code than SAC (see  
> attached).  Also, the code does not generate an array of strings.  I  
> would like to use either the set notation or with-loop notation to  
> create an array of strings.

Unfortunately you cannot do this due to the lack of support for  
stringArray in the type system. stringArray's can be accessed and  
modified only with the functions in StringArray.sac.

> The restrictions on this code is that the string must have exactly  
> one blank space both before and after the string and exactly one  
> blank space between words in the string.  Also, no punctuation and  
> no other whitespace (for example, tabs) are allowed to be in the  
> string.

Functions exist in sac for converting a string into an array of chars.  
With this array you can do this manipulation with with-loops, set  
notation or in whatever way you wish to do it. Bare in mind though  
that array in sac must be homogeneously nested so using 2 dimensional  
arrays with the second dimension representing strings doesn't always  
work out in practice.

> I reviewed through the SAC stdlib modules for String.sac and  
> StringArray.sac for ideas.  Also, I cannot find any information on  
> the String and StringArray topics in the Tutorial PDFs.
>
> Finally, unless I restrict the "use" statement to specific function  
> names, any attempts at using the String or StringArray modules tend  
> to cause errors in compilation because of duplicate declarations or  
> complications with the Array or StdIO modules.  For the Array  
> module, one possible idea could be to omit the "use Array:..."  
> statement and then code "Array::..." where needed in the program.   
> Does the "use" statement have any other syntax besides "use  
> <moduleName>: all;" and "use <moduleName>: {<functionList>};" to  
> make module usage easier? 
> <tokenizer.sac>_______________________________________________

You can also write use <moduleName>: {<functionList>} except  
{<functionList>} to remove duplicates. Or you can not have a use line  
at all and write <moduleName>::<functionName>( <functionArgs> ) in  
your code.

Hope that helps,
Dan

> sac-user mailing list
> sac-user at sac-home.org
> http://lists.sac-home.org/mailman/listinfo.cgi/sac-user



More information about the sac-user mailing list