Home   Archive   Permalink



print function

Regarding the two script functions below:
I don't understand why trying to substitute 'print RPPS-REC' in the RPPS-UNSTRING-RECORD for the 'x: copy[]' shown always throws an error saying that 'print' has no value argument.
I can replace 'x: copy[]' with an 'alert msg' and that also works. I 'am' giving print an argument...the name of the record I want printed. If I move the 'print RPPS-REC' request back up into the RPPS-READ function it gives the same error ???
    
RPPS-READ: does [
     RPPS-REC-COUNT: RPPS-REC-COUNT + 1
     RPPS-REC: copy ''
     RPPS-CURRENT-TYPE: copy ''
     RPPS-REC: pick RPPS-FILE RPPS-REC-COUNT    
     if none? RPPS-REC [
         RPPS-EOF: true
     ]
     if not RPPS-EOF [
         RPPS-UNSTRING-RECORD
     ]
]
RPPS-UNSTRING-RECORD: does [
     x: copy[]
]

posted by:   John Dutcher       13-Jan-2016/9:24:58-8:00



Well, I guess I better try to answer that question since I wrote that function.
    
That module (or probably a variation of it since the one on rebol.org probably was generalized for public viewing) is in production use here every day. Just now, I copied it, plus the program that uses it, to a test area and put in "print RPPS-REC" in RPPS-UNSTRING-RECORD and...it works fine for me.    
    
Is it possible that you did what I did recently, and elsewhere in your program used the "print" function, and spaced out and put a colon after the word "print"? That would redefine the "print" function and you never would find it because your eyes would pass over that colon.    
    
If that RPPS module is of use to you, I would be happy to email you the working version from our site, There is nothing classified in it and I have checked in the past to see if giving it away is legal, and it is. Or I could paste it into a reply here; it is about 328 lines long.    
    
It is a bit of a shock to see that someone noticed something I did, especially regarding REBOL which seems to have a couple hundred followers on the entire planet.

posted by:   Steven White       13-Jan-2016/10:30:18-8:00



I was looking for a well done way to read a flat file and ultimately manipulate its records' content. Your script looked perfect and ran first time right out of the box.....I added a "while" loop to actually read the records which seems to work. But no, I haven't redefined the "print" function, and I am astounded how you could duplicate my "print RPPs-REC" and not get an error. Yes....if it works for you ....you could paste it into a reply and I would grab it. You see...... the original.....as I copied it from the script example site had no "while loop" to do the reading of the file, just a series of "does" functions (very nice ones I thought). But my "while" loop works fine (while not RPPS-EOF), I just can't get the records being read to present themselves.

posted by:   John Dutcher       13-Jan-2016/10:41:44-8:00



I wonder if it's relevant that the file I happen to be reading is an HTML file (index.html, not index.txt). Maybe it cycles thru the records but what the pick is putting into RPPS-REC is ...like 'none' or something.....so print says I have no argument ?

posted by:   John Dutcher       13-Jan-2016/10:52:14-8:00



OK, let's give this a try.    
    
I notice that the RPPS module uses another function to pick apart its fixed-format records, so I will paste that in first. This RPPS module probably is not written in a REBOL-approved manner. It also was written for a very specific use.    
    
Function to extract a substring of a larger string:
    
GLB-SUBSTRING: func [
     "Return a substring from the start position to the end position"
     INPUT-STRING [series!] "Full input string"
     START-POS    [number!] "Starting position of substring"
     END-POS     [number!] "Ending position of substring"
] [
     if END-POS = -1 [END-POS: length? INPUT-STRING]
     return skip (copy/part INPUT-STRING END-POS) (START-POS - 1)
]
    
RPPS module as currently in production use:
    
TITLE
Remote Payment and Presentation System
    
SUMMARY
This module defines a file used for reporting money sent to us
electronically by the bank. The format is the same as a NACHA
file, but the fields might be used a little differently.
    
DOCUMENTATION
Since one normally would not write to this file (it is sent to us by the
bank), the procedures provided are for reading.
    
The procedures mimic COBOL usage.
    
Before using the file, call this procedure:
    
RPPS-OPEN-INPUT
This will bring the entire file into memory. If you don't like the default
file name, change it in RPPS-FILE-ID.
    
To "read" a record, do this until RPPS-EOF is true:
    
RPPS-READ
    
This will bring the next record into RPPS-REC and pick it apart into its
data items, putting each item into the words shown below, depending on
RPPS-CURRENT-TYPE.
    
SCRIPT
R E B O L [
]
    
;; [---------------------------------------------------------------------------]
;; [ This module defines a text file in the RPPS format for                    ]
;; [ getting money electronically from the bank.                             ]
;; [ RPPS stands for Remote Payment and Presentment System.                    ]
;; [ This is a "modified NACHA" format and is not quite the same             ]
;; [ as the file that WE send TO the bank for autopay.                         ]
;; [---------------------------------------------------------------------------]
    
RPPS-FILE: []                 ;; Holds the whole file in memory
RPPS-FILE-ID: %ACH.txt        ;; Default name of the file
RPPS-EOF: false             ;; End-of-file flag for reading
RPPS-REC: ""                 ;; One record, for reading or writing
RPPS-REC-COUNT: 0             ;; Counter, upped by 1 as we read or write
    
RPPS-CURRENT-TYPE: ""         ;; Type code of record in memory
    
;; [---------------------------------------------------------------------------]
;; [ When we read a record, we will take it apart in to its                    ]
;; [ fields and store the fields below. The CURRENT-TYPE field                ]
;; [ indicates which record we currently have our hands on.                    ]
;; [ For those record that contain numbers or amounts, some of the             ]
;; [ numbers or amounts are converted to appropriate data types                ]
;; [ so they can be used in appropriate ways (currency, for example).         ]
;; [---------------------------------------------------------------------------]
    
RPPS-1-RECORD-TYPE-CODE: ""
RPPS-1-PRIORITY-CODE: ""
RPPS-1-IMMEDIATE-DESTINATION: ""
RPPS-1-IMMEDIATE-ORIGIN: ""
RPPS-1-TRANSMISSION-DATE: ""
RPPS-1-TRANSMISSION-TIME: ""
RPPS-1-FILE-ID-MODIFIER: ""
RPPS-1-RECORD-SIZE: ""
RPPS-1-BLOCKING-FACTOR: ""
RPPS-1-FORMAT-CODE: ""
RPPS-1-DESTINATION-NAME: ""
RPPS-1-ORIGIN: ""
RPPS-1-REFERENCE-CODE: ""
    
RPPS-5-RECORD-TYPE-CODE: ""
RPPS-5-SERVICE-CLASS-CODE: ""
RPPS-5-BILLER-NAME: ""
RPPS-5-RESERVED: ""
RPPS-5-BILLER-ID-NUMBER: ""
RPPS-5-ENTRY-CLASS: ""
RPPS-5-ENTRY-DESCRIPTION: ""
RPPS-5-DESCRIPTIVE-DATE: ""
RPPS-5-EFFECTIVE-DATE: ""
RPPS-5-SETTLEMENT-DATE: ""
RPPS-5-CONCENTRATOR-STATUS: ""
RPPS-5-RPPS-ID-NUMBER: ""
RPPS-5-BATCH-NUMBER: ""
    
RPPS-5-EFFECTIVE-DATE-E: ""
    
RPPS-6-RECORD-TYPE-CODE: ""
RPPS-6-TRANSACTION-CODE: ""
RPPS-6-RPPS-ID-NUMBER: ""
RPPS-6-MERCHANT-ACCOUNT-NBR: ""
RPPS-6-AMOUNT: ""
RPPS-6-CONSUMER-ACCOUNT-NBR: ""
RPPS-6-CONSUMER-NAME: ""
RPPS-6-RPPS-FLAG: ""
RPPS-6-ADDENDUM-RECORD-IND: ""
RPPS-6-TRACE-NUMBER: ""
RPPS-6-SEQUENCE-NUMBER: ""
    
RPPS-6-AMOUNT-N: ""
    
RPPS-8-RECORD-TYPE-CODE: ""
RPPS-8-SERVICE-CLASS-CODE: ""
RPPS-8-ENTRY-ADDENDA-COUNT: ""
RPPS-8-ENTRY-HASH: ""
RPPS-8-TOTAL-DEBIT: ""
RPPS-8-TOTAL-CREDIT: ""
RPPS-8-BILLER-ID-NUMBER: ""
RPPS-8-MAC: ""
RPPS-8-FILLER-1: ""
RPPS-8-RPPS-ID-NUMBER: ""
RPPS-8-BATCH-NUMBER: ""
    
RPPS-8-TOTAL-DEBIT-N: ""
RPPS-8-TOTAL-CREDIT-N: ""
    
RPPS-9-RECORD-TYPE-CODE: ""
RPPS-9-BATCH-COUNT: ""
RPPS-9-BLOCK-COUNT: ""
RPPS-9-ENTRY-ADDENDA-COUNT: ""
RPPS-9-ENTRY-HASH: ""
RPPS-9-TOTAL-DEBIT: ""
RPPS-9-TOTAL-CREDIT: ""
RPPS-9-FILLER-1: ""
    
RPPS-OPEN-INPUT: does [
     RPPS-FILE: copy []
     RPPS-FILE: read/lines RPPS-FILE-ID
     RPPS-EOF: false
     RPPS-REC-COUNT: 0
     remove-each TEST-STRING RPPS-FILE [= GLB-SUBSTRING TEST-STRING 1 10 "9999999999"]
]
    
RPPS-READ: does [
     RPPS-REC-COUNT: RPPS-REC-COUNT + 1
     RPPS-REC: copy ""
     RPPS-CURRENT-TYPE: copy ""
     RPPS-REC: pick RPPS-FILE RPPS-REC-COUNT    
     if none? RPPS-REC [
         RPPS-EOF: true
     ]
     if not RPPS-EOF [
         RPPS-UNSTRING-RECORD
     ]
]
    
RPPS-CLOSE-INPUT: does [
     RPPS-FILE: copy []
     RPPS-REC: copy ""
]
    
RPPS-OPEN-OUTPUT: does [
     RPPS-FILE: copy []
     RPPS-REC: copy ""
     RPPS-REC-COUNT: 0
]
    
RPPS-WRITE: does [
     append RPPS-FILE RPPS-REC
     RPPS-REC-COUNT: RPPS-REC-COUNT + 1
]
    
RPPS-CLOSE-OUTPUT: does [
     write/lines RPPS-FILE-ID RPPS-FILE
     RPPS-FILE: copy []
     RPPS-REC: copy ""
]
    
RPPS-UNSTRING-RECORD: does [
     RPPS-CURRENT-TYPE: GLB-SUBSTRING RPPS-REC 1 1
     if RPPS-CURRENT-TYPE = "1" [
         RPPS-UNSTRING-1
     ]
     if RPPS-CURRENT-TYPE = "5" [
         RPPS-UNSTRING-5
     ]
     if RPPS-CURRENT-TYPE = "6" [
         RPPS-UNSTRING-6
     ]
     if RPPS-CURRENT-TYPE = "8" [
         RPPS-UNSTRING-8
     ]
     if RPPS-CURRENT-TYPE = "9" [
         RPPS-UNSTRING-9
     ]
]
    
RPPS-UNSTRING-1: does [
     RPPS-1-RECORD-TYPE-CODE: copy ""
     RPPS-1-PRIORITY-CODE: copy ""
     RPPS-1-IMMEDIATE-DESTINATION: copy ""
     RPPS-1-IMMEDIATE-ORIGIN: copy ""
     RPPS-1-TRANSMISSION-DATE: copy ""
     RPPS-1-TRANSMISSION-TIME: copy ""
     RPPS-1-FILE-ID-MODIFIER: copy ""
     RPPS-1-RECORD-SIZE: copy ""
     RPPS-1-BLOCKING-FACTOR: copy ""
     RPPS-1-FORMAT-CODE: copy ""
     RPPS-1-DESTINATION-NAME: copy ""
     RPPS-1-ORIGIN: copy ""
     RPPS-1-REFERENCE-CODE: copy ""
     RPPS-1-RECORD-TYPE-CODE: GLB-SUBSTRING RPPS-REC 1 1
     RPPS-1-PRIORITY-CODE: GLB-SUBSTRING RPPS-REC 2 3
     RPPS-1-IMMEDIATE-DESTINATION: GLB-SUBSTRING RPPS-REC 4 13
     RPPS-1-IMMEDIATE-ORIGIN: GLB-SUBSTRING RPPS-REC 14 23
     RPPS-1-TRANSMISSION-DATE: GLB-SUBSTRING RPPS-REC 24 29
     RPPS-1-TRANSMISSION-TIME: GLB-SUBSTRING RPPS-REC 30 33
     RPPS-1-FILE-ID-MODIFIER: GLB-SUBSTRING RPPS-REC 34 34
     RPPS-1-RECORD-SIZE: GLB-SUBSTRING RPPS-REC 35 37
     RPPS-1-BLOCKING-FACTOR: GLB-SUBSTRING RPPS-REC 38 39
     RPPS-1-FORMAT-CODE: GLB-SUBSTRING RPPS-REC 40 40
     RPPS-1-DESTINATION-NAME: GLB-SUBSTRING RPPS-REC 41 63
     RPPS-1-ORIGIN: GLB-SUBSTRING RPPS-REC 64 86
     RPPS-1-REFERENCE-CODE: GLB-SUBSTRING RPPS-REC 87 94
]
    
RPPS-UNSTRING-5: does [
     RPPS-5-RECORD-TYPE-CODE: copy ""
     RPPS-5-SERVICE-CLASS-CODE: copy ""
     RPPS-5-BILLER-NAME: copy ""
     RPPS-5-RESERVED: copy ""
     RPPS-5-BILLER-ID-NUMBER: copy ""
     RPPS-5-ENTRY-CLASS: copy ""
     RPPS-5-ENTRY-DESCRIPTION: copy ""
     RPPS-5-DESCRIPTIVE-DATE: copy ""
     RPPS-5-EFFECTIVE-DATE: copy ""
     RPPS-5-SETTLEMENT-DATE: copy ""
     RPPS-5-CONCENTRATOR-STATUS: copy ""
     RPPS-5-RPPS-ID-NUMBER: copy ""
     RPPS-5-BATCH-NUMBER: copy ""
     RPPS-5-RECORD-TYPE-CODE: GLB-SUBSTRING RPPS-REC 1 1
     RPPS-5-SERVICE-CLASS-CODE: GLB-SUBSTRING RPPS-REC 2 4
     RPPS-5-BILLER-NAME: GLB-SUBSTRING RPPS-REC 5 20
     RPPS-5-RESERVED: GLB-SUBSTRING RPPS-REC 21 40
     RPPS-5-BILLER-ID-NUMBER: GLB-SUBSTRING RPPS-REC 41 50
     RPPS-5-ENTRY-CLASS: GLB-SUBSTRING RPPS-REC 51 53
     RPPS-5-ENTRY-DESCRIPTION: GLB-SUBSTRING RPPS-REC 54 63
     RPPS-5-DESCRIPTIVE-DATE: GLB-SUBSTRING RPPS-REC 64 69
     RPPS-5-EFFECTIVE-DATE: GLB-SUBSTRING RPPS-REC 70 75
     RPPS-5-SETTLEMENT-DATE: GLB-SUBSTRING RPPS-REC 76 78
     RPPS-5-CONCENTRATOR-STATUS: GLB-SUBSTRING RPPS-REC 79 79
     RPPS-5-ID-NUMBER: GLB-SUBSTRING RPPS-REC 80 87
     RPPS-5-BATCH-NUMBER: GLB-SUBSTRING RPPS-REC 88 94
     RPPS-5-EFFECTIVE-DATE-E: rejoin [
         GLB-SUBSTRING RPPS-5-EFFECTIVE-DATE 3 4
         "/"
         GLB-SUBSTRING RPPS-5-EFFECTIVE-DATE 5 6
         "/"
         "20"
         GLB-SUBSTRING RPPS-5-EFFECTIVE-DATE 1 2
     ]
]
    
RPPS-UNSTRING-6: does [
     RPPS-6-RECORD-TYPE-CODE: copy ""
     RPPS-6-TRANSACTION-CODE: copy ""
     RPPS-6-RPPS-ID-NUMBER: copy ""
     RPPS-6-MERCHANT-ACCOUNT-NBR: copy ""
     RPPS-6-AMOUNT: copy ""
     RPPS-6-CONSUMER-ACCOUNT-NBR: copy ""
     RPPS-6-CONSUMER-NAME: copy ""
     RPPS-6-RPPS-FLAG: copy ""
     RPPS-6-ADDENDUM-RECORD-IND: copy ""
     RPPS-6-TRACE-NUMBER: copy ""
     RPPS-6-SEQUENCE-NUMBER: copy ""
     RPPS-6-RECORD-TYPE-CODE: GLB-SUBSTRING RPPS-REC 1 1
     RPPS-6-TRANSACTION-CODE: GLB-SUBSTRING RPPS-REC 2 3
     RPPS-6-RPPS-ID-NUMBER: GLB-SUBSTRING RPPS-REC 4 12
     RPPS-6-MERCHANT-ACCOUNT-NBR: GLB-SUBSTRING RPPS-REC 13 29
     RPPS-6-AMOUNT: GLB-SUBSTRING RPPS-REC 30 39
     RPPS-6-CONSUMER-ACCOUNT-NBR: GLB-SUBSTRING RPPS-REC 40 54
     RPPS-6-CONSUMER-NAME: GLB-SUBSTRING RPPS-REC 55 76
     RPPS-6-RPPS-FLAG: GLB-SUBSTRING RPPS-REC 77 78
     RPPS-6-ADDENDUM-RECORD-IND: GLB-SUBSTRING RPPS-REC 79 79
     RPPS-6-TRACE-NUMBER: GLB-SUBSTRING RPPS-REC 80 87
     RPPS-6-SEQUENCE-NUMBER: GLB-SUBSTRING RPPS-REC 88 94
     RPPS-6-AMOUNT-N: to-decimal divide to-decimal RPPS-6-AMOUNT 100
]
    
RPPS-UNSTRING-8: does [
     RPPS-8-RECORD-TYPE-CODE: copy ""
     RPPS-8-SERVICE-CLASS-CODE: copy ""
     RPPS-8-ENTRY-ADDENDA-COUNT: copy ""
     RPPS-8-ENTRY-HASH: copy ""
     RPPS-8-TOTAL-DEBIT: copy ""
     RPPS-8-TOTAL-CREDIT: copy ""
     RPPS-8-BILLER-ID-NUMBER: copy ""
     RPPT-8-MAC: copy ""
     RPPS-8-FILLER-1: copy ""
     RPPS-8-RPPS-ID-NUMBER: copy ""
     RPPS-8-BATCH-NUMBER: copy ""
     RPPS-8-RECORD-TYPE-CODE: GLB-SUBSTRING RPPS-REC 1 1
     RPPS-8-SERVICE-CLASS-CODE: GLB-SUBSTRING RPPS-REC 2 4
     RPPS-8-ENTRY-ADDENDA-COUNT: GLB-SUBSTRING RPPS-REC 5 10
     RPPS-8-ENTRY-HASH: GLB-SUBSTRING RPPS-REC 11 20
     RPPS-8-TOTAL-DEBIT: GLB-SUBSTRING RPPS-REC 21 32
     RPPS-8-TOTAL-CREDIT: GLB-SUBSTRING RPPS-REC 33 44
     RPPS-8-BILLER-ID-NUMBER: GLB-SUBSTRING RPPS-REC 45 54
     RPPS-8-MAC: GLB-SUBSTRING RPPS-REC 55 73
     RPPS-8-FILLER-1: GLB-SUBSTRING RPPS-REC 74 79
     RPPS-8-RPPS-ID-NUMBER: GLB-SUBSTRING RPPS-REC 80 87
     RPPS-8-BATCH-NUMBER: GLB-SUBSTRING RPPS-REC 88 94
     RPPS-8-TOTAL-DEBIT-N: divide to-decimal RPPS-8-TOTAL-DEBIT 100
     RPPS-8-TOTAL-CREDIT-N: divide to-decimal RPPS-8-TOTAL-CREDIT 100    
]
    
RPPS-UNSTRING-9: does [
     RPPS-9-RECORD-TYPE-CODE: copy ""
     RPPS-9-BATCH-COUNT: copy ""
     RPPS-9-BLOCK-COUNT: copy ""
     RPPS-9-ENTRY-ADDENDA-COUNT: copy ""
     RPPS-9-ENTRY-HASH: copy ""
     RPPS-9-TOTAL-DEBIT: copy ""
     RPPS-9-TOTAL-CREDIT: copy ""
     RPPS-9-FILLER-1: copy ""
     RPPS-9-RECORD-TYPE-CODE: GLB-SUBSTRING RPPS-REC 1 1
     RPPS-9-BATCH-COUNT: GLB-SUBSTRING RPPS-REC 2 7
     RPPS-9-BLOCK-COUNT: GLB-SUBSTRING RPPS-REC 8 13
     RPPS-9-ENTRY-ADDENDA-COUNT: GLB-SUBSTRING RPPS-REC 14 21
     RPPS-9-ENTRY-HASH: GLB-SUBSTRING RPPS-REC 22 31
     RPPS-9-TOTAL-DEBIT: GLB-SUBSTRING RPPS-REC 32 43
     RPPS-9-TOTAL-CREDIT: GLB-SUBSTRING RPPS-REC 44 55
     RPPS-9-FILLER-1: GLB-SUBSTRING RPPS-REC 56 94
]
    
;; -----------------------------------------------------------------------------
    
    


posted by:   Steven White       13-Jan-2016/11:49:48-8:00



By the way, the program that uses the RPPS module uses it in a rather COBOL-like way, for various reasons not relevant at this time. In COBOL, there are a couple ways of structuring a loop to read through a file. You can read a record at the beginning of the loop and check for end-of-file at that point, and then NOT proceed if you are at the end, OR, you can do an initial read BEFORE you enter the loop and then read the next record at the END of the loop, as shown below:
    
;; -- Extract all detail records.
RPPS-READ                                        ;; Get first bank record
while [not RPPS-EOF] [                         ;; Process until end of file
     if = RPPS-CURRENT-TYPE "6" [EXTRACT-THIS-PAYMENT]
     RPPS-READ
]
    
You might have a point of confusion in that area.
    


posted by:   Steven White       13-Jan-2016/12:03:46-8:00



Yee ha......problem solved in an unexpected way (to me) !! I had previously added to your original script at the bottom this code:
    
do RPPS-OPEN-INPUT    
do RPPS-READ
while [not RPPS-EOF][    
     do RPPS-READ
]
alert "End of File"
    
Once I saw your own version of the 'while' loop....I noticed that using the "do" as a way to call the other functions is not correct apparently. Once I removed them and my code now looks like this:
    
RPPS-OPEN-INPUT    
RPPS-READ
while [not RPPS-EOF][    
     RPPS-READ
]
alert "End of File"    
    
The print function call works fine and displays the records exactly !!!
    
Thanks much.......so I guess you don't think
Rebol 3 or Red are gonna set the world on fire now that they are open sourced ??    

posted by:   John Dutcher       13-Jan-2016/13:30:49-8:00



I am not qualified to have a valid opinion about REBOL 3 or Red. But looking at Linux, where there is some person "in charge" and a lot of people working on it, a couple items come to mind about REBOL and Red. For REBOL, it has been released "into the wild" as open source, but it seems more like Carl has "washed his hands" of it and REBOL now is sort on its own without any direction. I worry that without any leader, nothing will come of it. For Red, it seems like a vastly ambitious project run by one, but only one, very smart guy. I worry that he won't be able to pull it off, not because he isn't qualified, but because he is only one person. And as for REBOL 2, I worry that since it not supported, the time will come when we will get Windows 11, 12,13...nn, and REBOL 2 will quit working. Where I work, REBOL 2 can't be sold as a solution to anything because of its lack of support and because everyone is in love with Microsoft.    
    
So I worry that REBOL will be like the Amiga, Control Data, Burroughs. Genius...lost.

posted by:   Steven White       13-Jan-2016/14:02:46-8:00