It is currently Fri May 24, 2013 2:16 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: MyString = ReadS
PostPosted: Fri May 11, 2012 4:25 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 794
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:
Read.s s
Debug s
; vs:
Debug ReadS


...if you have to put parens in for consistency, that's fine.
Debug ReadS()

Thanks!


Top
 Profile  
 
 Post subject: Re: MyString = ReadS
PostPosted: Fri May 11, 2012 4:29 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 1386
Location: Boston, MA
Ummm, we already have Peek() functions... :wink:
Code:
Debug PeekS(?MyString)
DataSection
  MyString:
  Data.s "Hello"
EndDataSection

_________________
To understand recursion, you must first understand recursion. ~ unknown
I never make stupid mistakes. Only very, very clever ones. ~ John Peel


Top
 Profile  
 
 Post subject: Re: MyString = ReadS
PostPosted: Fri May 11, 2012 4:35 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 794
skywalk wrote:
Ummm, we already have Peek() functions... :wink:
Code:
Debug PeekS(?MyString)
DataSection
  MyString:
  Data.s "Hello"
EndDataSection

And how do you read numerous strings of unknown length, using PeekS?


Top
 Profile  
 
 Post subject: Re: MyString = ReadS
PostPosted: Fri May 11, 2012 4:49 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jan 21, 2011 8:25 am
Posts: 549
Like this?

Code:

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


_________________
Image
ImageImageImage
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds


Top
 Profile  
 
 Post subject: Re: MyString = ReadS
PostPosted: Fri May 11, 2012 4:54 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 1386
Location: Boston, MA
Code:
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

_________________
To understand recursion, you must first understand recursion. ~ unknown
I never make stupid mistakes. Only very, very clever ones. ~ John Peel


Top
 Profile  
 
 Post subject: Re: MyString = ReadS
PostPosted: Fri May 11, 2012 4:55 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 794
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.


Top
 Profile  
 
 Post subject: Re: MyString = ReadS
PostPosted: Fri May 11, 2012 5:00 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 1386
Location: Boston, MA
Using the existing commands: Read.s and PeekS() are NOT workarounds or slow. :lol:

_________________
To understand recursion, you must first understand recursion. ~ unknown
I never make stupid mistakes. Only very, very clever ones. ~ John Peel


Top
 Profile  
 
 Post subject: Re: MyString = ReadS
PostPosted: Fri May 11, 2012 5:41 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 794
skywalk wrote:
Using the existing commands: Read.s and PeekS() are NOT workarounds or slow. :lol:

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.


Top
 Profile  
 
 Post subject: Re: MyString = ReadS
PostPosted: Fri May 11, 2012 7:22 pm 
Online
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 2401
Location: Utah, USA
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:
;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"

_________________
Image


Last edited by Demivec on Fri May 11, 2012 7:36 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: MyString = ReadS
PostPosted: Fri May 11, 2012 7:30 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 794
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.


Top
 Profile  
 
 Post subject: Re: MyString = ReadS
PostPosted: Fri May 11, 2012 7:36 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 794
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.

:mrgreen:


Top
 Profile  
 
 Post subject: Re: MyString = ReadS
PostPosted: Fri May 11, 2012 7:40 pm 
Online
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 2401
Location: Utah, USA
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.

_________________
Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye