TSE: String arrays possible?

7 views
Skip to first unread message

knud van eeden

unread,
Mar 15, 2023, 11:35:41 PM3/15/23
to SemWare TSE Pro Text Editor
Hello (Sammy, ...)

1. So to create INTEGER arrays, this works OK 

(note: you *must* save it with the extension .si)

INTEGER a[ 10 ]
//
PROC Main()
 Warn( a[ 1 ] )
 Warn( a[ 10 ] )
 a[ 1 ] = 3
 a[ 10 ] = 5
 Warn( a[ 1 ] )
 Warn( a[ 10 ] )
END

2. Now the question is, I want to create something similar for STRING arrays (e.g. again saving with the .si extension).

Like:

STRING s[ 10 ][ ]
//
PROC Main()
END

or similar

STRING s[10][255]
//
PROC Main()
END

in order to create e.g. a 10 string array of e.g. length 255 characters maximally.

3. Note thus that I would explicitly like to use that save as .si file method in order to achieve it.

Question: Is that possible in the current implementation of TSE? 

Thanks
with friendly greetings
Knud van Eeden

Rick Hodgin

unread,
Mar 16, 2023, 6:50:15 AM3/16/23
to sem...@googlegroups.com
Knud,

Just like how we stored floating point values in integers, use the malloc() function to allocate blocks of memory which can be used to store strings.  The returned pointer value can be used as an integer.

Pass in to standard text processing functions:
sprintf()
memcpy()
memcmp()
_memicmp()
free()
realloc()
calloc()
etc()

in order to use.  You can allocate strings up to the machine's memory this way.  2GB per process.  Use those functions to copy data to/from TSE SAL strings directly.

I can extend bignums.dll to add these facilities to the API if you would like.

-- 
Rick C. Hodgin


--

---
You received this message because you are subscribed to the Google Groups "SemWare TSE Pro text editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to semware+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/semware/1218010417.827559.1678937739218%40mail.yahoo.com.

knud van eeden

unread,
Mar 16, 2023, 7:40:02 AM3/16/23
to sem...@googlegroups.com
Rick,

> I can extend bignums.dll to add these facilities to the API if you would like.

It should probably require a separate DLL in order to keep things separated. If STRING arrays can be created then in a clean and simple way
after including that DLL would be the preferred way.

Thus something like

STRING s[ ... ] [ ... ] 

or similar

STRING s[ ..., ... ]

It would be nice thus if STRING arrays are thus available out of the box in native TSE.

Note: There are thus already other methods available to create STRING arrays, typically using SetGlobalStr() and GetGlobalStr(). 
One basically builds each STRING array name e.g. by concatenation of an array name, followed by "[", followed by array index numbers and followed by "]" using
set the value and get to retrieve the value. E.g. something like 

SetGlobalStr( Format( "s", "[", 1, "]" ), "16 March 2023" )

and 

Warn( GetGlobalStr( Format( "s", "[", 1, "]" ) ) )

Note: A use case would be creating RosettaCode TSE programs, so then intention of keeping it as clean and lean as possible there. Also e.g. testing ChatGPT generated TSE source code where one can expect many declarations of STRING arrays out of the box. E.g. thus when resolving RosettaCode TSE programs.

with friendly greetings
Knud van Eeden

knud van eeden

unread,
Mar 16, 2023, 7:55:09 AM3/16/23
to sem...@googlegroups.com
> Note: A use case would be creating RosettaCode TSE programs, so then intention of keeping it as clean and lean as possible there. Also e.g. testing ChatGPT generated TSE source code where one can expect many declarations of STRING arrays out of the box. E.g. thus when resolving RosettaCode TSE programs.

The idea is then to copy/paste the programming task into ChatGPT and to ask to create a TSE Semware SAL program automatically.
That will at least give a start.

I tried it e.g. with this task


Then called ChatGPT
and asked
"Write a Semware SAL program that does the following:"
then pasted the whole task description verbatim into ChatGPT.
...
For this task, the following command table will be used:
 Add ALTer  BAckup Bottom  CAppend Change SCHANGE  CInsert CLAst COMPress COpy
...

It came then back with a TSE SAL program like result + algorithm

...
PROC ValidateWords( STRING words[])
  INTEGER i, j, k
  INTEGER valid = FALSE
  STRING commands[] = {
    "Add", "ALTer", "BAckup", "Bottom", "CAppend", "Change", "SCHANGE", "CInsert", "CLAst", "COMPress", "COpy",
    "COUnt", "COVerlay", "CURsor", "DELete", "CDelete", "Down", "DUPlicate", "Xedit", "EXPand", "EXTract", "Find",
    "NFind", "NFINDUp", "NFUp", "CFind", "FINdup", "FUp", "FOrward", "GET", "Help", "HEXType", "Input", "POWerinput",
    "Join", "SPlit", "SPLTJOIN", "LOAD", "Locate", "CLocate", "LOWercase", "UPPercase", "LPrefix", "MACRO",
    "MErge", "MODify", "MOve", "MSG", "Next", "Overlay", "PARSE", "PREServe", "PURge", "PUT", "PUTD", "Query", "QUIT",
    "READ", "REcover", "REFRESH", "RENum", "REPeat", "Replace", "CReplace", "RESet", "RESTore", "RGTLEFT",
    "RIght", "LEft", "SAVE", "SET", "SHift", "SI", "SORT", "SOS", "STAck", "STATus", "TOP", "TRAnsfer", "Type", "Up"
  }
  FOR i = 0 TO Length(words) - 1
...
 
Which gave at least an alternative view and idea about how to do similar with TSE source code...

In general creating STRING arrays is a very often occurring programming task further.

===

Carlo Hogeveen

unread,
Mar 16, 2023, 8:00:13 AM3/16/23
to sem...@googlegroups.com

@Knud,
> [Summarized: Like integer arrays in .si files, are string arrays possible in the current implementation of TSE?]
No.

@Everybody else,
1.
Using .si files is dangerous, because it disables some of the macro's syntax and run-time checking.
2.
The integer array method only works for "small" arrays and does no boundary checking, meaning it can overwrite other variables and maybe even program code.
3.
The TSE work-around for arrays, matrices, tensors, hashes, etcetera, is to use its {Get|Set}{Buffer}{Int|Str}() functions.
They work in all TSE versions and variants, including Linux TSE, making the macro portable.

Carlo



Reply all
Reply to author
Forward
0 new messages