Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Formatting a display line

 [1/8] from: Steven:White:ci:bloomington:mn:us at: 4-Nov-2003 15:57


This must be something really dumb, but I am wondering if perhaps I am not understanding how something works. The purpose of the script below is to go through a block of blocks (a little "file" of "records" in my native tongue) and, for each record, rearrange the "fields" with some spaces in them, suitable for displaying. It builds up this displayable line in the item called FORMATTED-LINE. On line 1111 of the script, the first item (number four = "THIS") is added to FORMATTED-LINE, and on line 2222 the FORMATTED-LINE is displayed to show that it is correct. On line 3333, a procedure is called to fill the line out to 10 spaces. In the procedure to add the spaces, at line 4444, suddenly FORMATTED-LINE is different; it contains the field just added, PLUS the data the is not due to be added until line 5555. In other words, on line 2222 FORMATTED-LINE is "THIS" and on line 4444 it is "THISIS", but the IS is not supposed to be added until line 5555, AFTER the script has returned from adding the spaces after THIS. Am I losing my mind or what? Thank you. Steven White [steven--white--ci--bloomington--mn--us] script follows--may be cut, pasted, and run: REBOL [ ] DATA-SELECTED: [ [ "TEST" "A" "IS" "THIS" ] [ "WORK" "THIS" "WON'T" "WHY" ] ] DATA-FORMATTED: none FORMATTED-LINE: none TEST-PROCEDURE: does [ DATA-FORMATTED: copy "" foreach DATA-RECORD DATA-SELECTED [ FORMATTED-LINE: copy "" PRINT ["APPENDING " FOURTH DATA-RECORD] append FORMATTED-LINE fourth DATA-RECORD ;; 1111 PRINT ["FORMATTED LINE NOW IS " FORMATTED-LINE] ;; 2222 ADD-FILLER (10 - length? FORMATTED-LINE) ;; 3333 ;;;;;;;; PRINT ["APPENDING " THIRD DATA-RECORD] ;; UNCOMMENTING GIVES ERROR append FORMATTED-LINE third DATA-RECORD ;; 5555 PRINT ["FORMATTED LINE NOW IS " FORMATTED-LINE] ADD-FILLER (20 - length? FORMATTED-LINE) append FORMATTED-LINE second DATA-RECORD ADD-FILLER (30 - length? FORMATTED-LINE) append FORMATTED-LINE first DATA-RECORD append FORMATTED-LINE newline append DATA-FORMATTED FORMATTED-LINE ] ] ADD-FILLER: func [ "Add a specified number of blanks to FORMATTED-LINE" SPACE-COUNT integer! ] [ PRINT ["NOW WE WILL ADD " SPACE-COUNT " SPACES"] loop SPACE-COUNT [ append FORMATTED-LINE " " ;; 4444 PRINT ["FORMATTED LINE IS " LENGTH? FORMATTED-LINE " BYTES:" FORMATTED-LINE] ] ] TEST-PROCEDURE PRINT DATA-FORMATTED

 [2/8] from: andrew:martin:colenso:school at: 24-Dec-2003 22:44


Steve wrote:
> Am I losing my mind or what?
No, just suffering from an overuse of COBOL... :) :D Try adding square brackets around the "integer!" function argument data-type specifier in 'ADD-FILLER. For example: ADD-FILLER: func [ "Add a specified number of blanks to FORMATTED-LINE" SPACE-COUNT [integer!] ] [ PRINT ["NOW WE WILL ADD " SPACE-COUNT " SPACES"] loop SPACE-COUNT [ append FORMATTED-LINE " " ;; 4444 PRINT ["FORMATTED LINE IS " LENGTH? FORMATTED-LINE BYTES: FORMATTED-LINE] ] ] Here's how I'd do the job: print map DATA-SELECTED func [Line [block!]] [ rejoin [ map Line func [Item] [ pad form Item 9 ] newline ] ] Of course that does involve using my 'map and 'pad functions, and assumes the same horizontal spacing per item in each line. Andrew J Martin Attendance Officer Speaking in tongues and performing miracles. Colenso High School Arnold Street, Napier. Tel: 64-6-8310180 ext 826 Fax: 64-6-8336759 http://colenso.net/scripts/Wiki.r?AJM http://www.colenso.school.nz/ DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally liable) for materials distributed to or acquired from user e-mail accounts. You can report any misuse of an e-mail account to our ICT Manager and the complaint will be investigated. (Misuse can come in many forms, but can be viewed as any material sent/received that indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate language and/or other issues described in our Acceptable Use Policy.) All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0 Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]

 [3/8] from: SunandaDH::aol::com at: 4-Nov-2003 17:37


Steve:
> This must be something really dumb, but I am wondering if perhaps I am > not understanding how something works.
Looks to me you've simply need to change the parameter definition for ADD-FILLER. that line: SPACE-COUNT integer! should be SPACE-COUNT [integer!] Written with the [] it means the function takes one parameter, that must be an integer. Without the [] it looks like the interpreter is assuming ADD-FILLER takes two parameters. That's eating up your lines of code in ways you didn't expect -- hence that strange message if you uncomment a line. Fix that, and I think all the problems go away. Nice to see another (in my case ex) COBOLer having a go at REBOL, Sunanda.

 [4/8] from: tomc:darkwing:uoregon at: 4-Nov-2003 14:49


works with this tiny change from ADD-FILLER (10 - length? FORMATTED-LINE) ;; 3333 to ADD-FILLER 10 - (length? FORMATTED-LINE) this is because 10 - length? is being asked to happen before length? FORMATTED-LINE and is not evaulating to an integer! so ADD-FILLER does not see it's argument hope that helps On Tue, 4 Nov 2003, Steven White wrote:

 [5/8] from: andrew:martin:colenso:school at: 24-Dec-2003 22:44


Tom wrote:
> works with this tiny change > from
<<quoted lines omitted: 4>>
> is being asked to happen before length? FORMATTED-LINE > and is not evaulating to an integer! so ADD-FILLER does not see it's
argument Not quite. As shown here:
>> 10 - probe length? "123"
3 == 7
>> length? "123" + 3
** Script Error: Cannot use add on string! value ** Near: length? "123" + 3
>> (length? "123") + 3
== 6 Rebol is "peculiar" like that. Andrew J Martin Attendance Officer Speaking in tongues and performing miracles. Colenso High School Arnold Street, Napier. Tel: 64-6-8310180 ext 826 Fax: 64-6-8336759 http://colenso.net/scripts/Wiki.r?AJM http://www.colenso.school.nz/ DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally liable) for materials distributed to or acquired from user e-mail accounts. You can report any misuse of an e-mail account to our ICT Manager and the complaint will be investigated. (Misuse can come in many forms, but can be viewed as any material sent/received that indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate language and/or other issues described in our Acceptable Use Policy.) All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0 Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]

 [6/8] from: tomc:darkwing:uoregon at: 4-Nov-2003 15:02


On Tue, 4 Nov 2003, Tom Conlin wrote: never mind it was the [] not the ()

 [7/8] from: joel:neely:fedex at: 4-Nov-2003 17:04


Hi, Steven, The typing of the parameter has already been pointed out, but let me give you a speed improvement as well. Using SOURCE shows us that APPEND is essentially INSERT TAIL (just what you'd expect), and INSERT has a /DUP refinement that duplicates the insertion, so instead of ... Steven White wrote:
> ADD-FILLER: func [ > "Add a specified number of blanks to FORMATTED-LINE"
<<quoted lines omitted: 7>>
> ] > ]
... just define ... add-filler: func [ "add specified number of spaces to formatted-line" space-count [integer!] ][ insert/dup tail formatted-line " " space-count ] -- ---------------------------------------------------------------------- Joel Neely joelDOTneelyATfedexDOTcom 901-263-4446 Enron Accountingg in a Nutshell: 1c=$0.01=($0.10)**2=(10c)**2=100c=$1

 [8/8] from: amicom:sonic at: 5-Nov-2003 23:27


Steven, OR, you could simply download my align.r function from the Rebol library: http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=align.r It has optional alignment (center, right, etc.) and is very easy to use. Have fun! Bohdan "Bo" Lechnowsky Lechnowsky Technical Consulting At 05:04 PM 11/4/03 -0600, you wrote:

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted