Page 1 of 1

Read() as a procedure

Posted: Fri Jul 08, 2005 6:42 pm
by PB&J Lover
In keeping with the PB language format of Result = Procedure(arguments) you really need to make READ() a procedure.

That would allow:

Code: Select all

restore MyData

IF FindString(Read(),".",1)

do something.

EndIf
This way data can be directly piped into some process.

In fact it would be good to go: Result = READ(MyData1) where "MyData is the DATA section. That way you could nest READ statements that reference different DATA section in the same line.

Thanks.

Posted: Mon Jul 11, 2005 3:22 pm
by DoubleDutch
You could do it yourself...

Code: Select all

Procedure.s ReadS()
	Read result$
	ProcedureReturn result$
EndProcedure

Procedure ReadI()
	Read result
	ProcedureReturn result
EndProcedure

Procedure.f ReadF()
	Read result.f
	ProcedureReturn result
EndProcedure

If OpenConsole()
	PrintN("Using procedure read")
	
	Restore TextData
	For n=1 To 3
		PrintN(ReadS())
	Next
	
	PrintN("Press return to exit")
	Input()
	CloseConsole()
EndIf
End

DataSection
TextData:	Data$	"This is a test","Another test","Test #3"
EndDataSection
The above code could easily be made into a library.

-Anthony

Posted: Mon Jul 11, 2005 3:25 pm
by Fred
That's right, 'Read' is a bit an oddity as it's coming from the old Basic langages which had such behaviour..