Page 1 of 1
MyString = ReadS
Posted: Fri May 11, 2012 4:25 pm
by Tenaja
I would like to request the Read functions (all var types) get a version with the same format as the Peek functions. Look how much cleaner this can be...
Code: Select all
Read.s s
Debug s
; vs:
Debug ReadS
...if you have to put parens in for consistency, that's fine.
Debug ReadS()
Thanks!
Re: MyString = ReadS
Posted: Fri May 11, 2012 4:29 pm
by skywalk
Ummm, we already have Peek() functions...
Code: Select all
Debug PeekS(?MyString)
DataSection
MyString:
Data.s "Hello"
EndDataSection
Re: MyString = ReadS
Posted: Fri May 11, 2012 4:35 pm
by Tenaja
skywalk wrote:Ummm, we already have Peek() functions...
Code: Select all
Debug PeekS(?MyString)
DataSection
MyString:
Data.s "Hello"
EndDataSection
And how do you read numerous strings of unknown length, using PeekS?
Re: MyString = ReadS
Posted: Fri May 11, 2012 4:49 pm
by Shield
Like this?
Code: Select all
Procedure.s ReadS()
Protected string.s
Read.s string
ProcedureReturn string
EndProcedure
Restore StringStuff
Debug ReadS()
Debug ReadS()
Debug ReadS()
Debug ReadS()
Debug ReadS()
DataSection
StringStuff:
Data.s "Hello"
Data.s "Wolrd"
Data.s "How"
Data.s "Are"
Data.s "You?"
EndDataSection
Re: MyString = ReadS
Posted: Fri May 11, 2012 4:54 pm
by skywalk
Code: Select all
Macro NEXTDATA_Str(DataLabel)
*DataLabel + (MemoryStringLength(*DataLabel) + 1) * SizeOf(Character)
EndMacro
Define.i *p = ?MyString
Define.s s$
Repeat
s$ = PeekS(*p): NEXTDATA_Str(p)
Debug s$
Until s$ = "Q"
DataSection
MyString:
Data.s "Hello"
Data.s "Hello2", "Hello33"
Data.s "Hello444"
Data.s "Q"
EndDataSection
Re: MyString = ReadS
Posted: Fri May 11, 2012 4:55 pm
by Tenaja
I recognize those are both useable workarounds, but I was requesting new PB commands that operate at the speed of PB, not the speed of workarounds.
Re: MyString = ReadS
Posted: Fri May 11, 2012 5:00 pm
by skywalk
Using the existing commands: Read.s and PeekS() are NOT workarounds or slow.

Re: MyString = ReadS
Posted: Fri May 11, 2012 5:41 pm
by Tenaja
skywalk wrote:Using the existing commands: Read.s and PeekS() are NOT workarounds or slow.

No, read.s is not a workaround, but is not a "function" that allows assigning a var its
return value. But is IS cumbersome coding because it requires a "temporary" variable.
PeekS IS a workaround, because it does not read data sequentially.
Using a handwritten ReadS() function works, but has a lot of unnecessary overhead. If Fred were to implement it as a native function, I'd bet 100% of that overhead would go away. It IS a workaround, and a
reasonable workaround until we get a native command, if we ever do. This is the wishlist forum, and I am just expressing a simple wish. It can't be a time consuming implementation.
Re: MyString = ReadS
Posted: Fri May 11, 2012 7:22 pm
by Demivec
Tenaja wrote:No, read.s is not a workaround, but is not a "function" that allows assigning a var its return value. But is IS cumbersome coding because it requires a "temporary" variable.
I gather that you are requesting a function that modifies the data pointer and returns a type of data read from the data pointer. I agree that that would be a useful thing.
Contrary to your comment you currently can use 'Read' to place data directly in a variable without the need for a temporary variable, you just can't use it in an any kind of expression or as a literal (without being placed in a variable). You would just use: Read.s MyString.
As stated PeekS() and it's relatives are functions and return data of a specific type but do not update a data pointer. I suggest that instead of adding a group of new 'Read' functions that a 'Peek' type of function be implemented that updates a data pointer.
Perhaps something like IPeekS(*dataPtr), IPeekD(*dataPtr), and etc. The 'I' stands for increment. It would return the data from the memory location and update the pointer by the size of the data.
It would look something like:
Code: Select all
;here are two stand-in macros representing the functionality desired
Macro IPeekB(ptr)
PeekB(ptr): ptr + SizeOf(Byte)
EndMacro
;a version that handles the specification of length or flags is desired but is not shown here
Macro IPeekS(ptr)
PeekS(ptr): ptr + (MemoryStringLength(ptr) + 1) * SizeOf(Character)
EndMacro
DataSection
stuff:
Data.b 5
Data.s "first", "second", "third", "fourth", "fifth"
EndDataSection
*dataPtr = ?stuff
count = IPeekB(*dataPtr) ;pointer will be incremented by 1 for the size of a byte
For i = 1 To count
Debug IPeekS(*dataPtr) ;pointer will be incremented by the memory length of the string + Null
Next
I think such a think would be useful because it would complement the 'Read' functionality with direct access to memory. As a plus it would allow several simultaneous reads from different locations.
If implemented it would also would beg the question, "Neglecting the origins of BASIC, why would you need 'Read' for anything anymore?"
It should be noted that the current function of Data/Read does not allow the use of fixed length strings.
@Edit: corrected typo from "just can use" to "just can't use"
Re: MyString = ReadS
Posted: Fri May 11, 2012 7:30 pm
by Tenaja
Demivec wrote:Contrary to your comment you currently can use 'Read' to place data directly in a variable without the need for a temporary variable, you just can use it in an any kind of expression or as a literal (without being placed in a variable). You would just use: Read.s MyString.
This does NOT work as a function parameter for calling another function. Like I said, it requires a temporary variable.
Re: MyString = ReadS
Posted: Fri May 11, 2012 7:36 pm
by Tenaja
Demivec wrote:If implemented it would also would beg the question, "Neglecting the origins of BASIC, why would you need 'Read' for anything anymore?"
Conversely, if Read were implemented with full access, why would one need Peek/Poke??? Peek is more of an antiquated command that was implemented due to lack of pointers etc. No other language uses it, other than languages trying to workaround their lack of string and or data handling.

Re: MyString = ReadS
Posted: Fri May 11, 2012 7:40 pm
by Demivec
Tenaja wrote:Demivec wrote:Contrary to your comment you currently can use 'Read' to place data directly in a variable without the need for a temporary variable, you just can use it in an any kind of expression or as a literal (without being placed in a variable). You would just use: Read.s MyString.
This does NOT work as a function parameter for calling another function. Like I said, it requires a temporary variable.
I agree, and I corrected the typo in the previous message.