1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Block Comments

Discussion in 'T&T - Aliases' started by Rick Reinckens, Feb 12, 2015.

  1. Rick Reinckens

    Joined:
    Oct 18, 2009
    Messages:
    96
    Likes Received:
    4
    The latest version of Take Command will include block comment functionality.

    An easy way to add that to older versions is with two aliases:

    ALIAS BLOCK_COMMENT_START=IFF 0 EQ 1 THEN

    ALIAS BLOCK_COMMENT_END=ENDIFF
     
    hughntx likes this.
  2. w_krieger

    Joined:
    Nov 2, 2008
    Messages:
    176
    Likes Received:
    0
    I write big batches and connected files in weave, where you extract the code out of the comment. The barch has one short comment saying where it was produced from,
     
  3. dcantor

    Joined:
    May 29, 2008
    Messages:
    507
    Likes Received:
    3
    Unfortunately, that approach will fail if the block comments include an unpaired ENDIFF, or an unpaired IFF, or something that looks like one of those to the parser.
     
  4. w_krieger

    Joined:
    Nov 2, 2008
    Messages:
    176
    Likes Received:
    0
    Weave means that you create the batch from a source file, and then untangle the batch from it. The simplest form is simply to turn the print processor on and off, rather like

    Code:
    set batch=batchname
    echo REM made from %_batchname > %batch%
    begin comment
      Comments go here
    end comment
    begin text > %batch
      Code goes here
    end text
    rem and so forth
    
    I wrote a really advanced form of weave, which allows you to make several files up, and use native rexx variables and operations in the script. You can do things like produce rows of data from a table etc.

    Here's how one might approach an IFF statement in 4NT. It's a fairly complex thing, and we really have to make sure it's all kept together. It's pretty easy to see how the payees are selected here.

    !src and !lbl are labels, while !lbl and !end are implicit returns. !src and !end mark an active block of code, so the line at 'Here is... ' is not loaded into memory. !inc LBL runs the code from a label LBL to its implicit return. Nesting is limited by REXX's arrays (ie very large).

    Code:
    !src switchpayee
    iff condition1 then
    !inc condition1               ;  Payee male
    elseiff condition2 then
    !inc condition2              ; Payee female
    elseiff condition3 then
    !inc condition3             ; Payee company
    else
    !inc condition0           
    endiff
    !end
    
    Here is what happens at each case.
    
    !src condition1
    code for condition 1 goes here
    !lbl condition2
      code for condition 2 goes here
    !lbl condition3
    ...
    !end
    
    The feature here is that the whole ENDIFF is given here clearly, with no further need of documentation. The includes can point to the same set of code, or of it's modular, you can include several !inc between the lines, or point several conditions to the same block (ie condition3 could have been 'condition1'.

    Once this is written, the actual conditional codes are then documented separately.

    None of this documentation appears in the actual code, and redundant code can be bypassed and still left in the source code (i put debug statements in like this).

    Using ! to open commands comes from editing the JP software 4DOS.HLP file too much. Many of my text editors fold on !topic, which i use as a way to create a live index for the file, as well as keeping a tab on the current point.

    I've used this sort of stuff to write blank floppy diskette images, which involve repeated writing of the same code.
     
    #4 w_krieger, Feb 19, 2015
    Last edited: Feb 19, 2015
  5. Rick Reinckens

    Joined:
    Oct 18, 2009
    Messages:
    96
    Likes Received:
    4
    I realize that. But even a built-in true COMMENT ... ENDCOMMENT would cause similar problems.


    Previously, I would "comment" out code by actually adding IFF 1 EQ 0 THEN ... and ENDIFF to blocks. But the alias technique makes the code a lot more readable. Plus, I often put test code to do things like deliberately introduce an error, and in those cases it's not a block comment.
     
  6. dcantor

    Joined:
    May 29, 2008
    Messages:
    507
    Likes Received:
    3
    I actually do use IFF 1 EQ 0 THEN ... and ENDIFF, and I agree that your approach is more readable, but my approach makes it clearer that I cannot have unmatched IFF or ENDIFF or ELSEIFF lines. I'm thinking of using
    Code:
    IFF THIS==IS.A.BLOCK.COMMENT THEN
     ...
     ENDIFF 
    Another approach is
    Code:
    TEXT > NUL
      Comments can be entered here
    ENDTEXT
    
     
    #6 dcantor, Mar 15, 2015
    Last edited: Mar 15, 2015
  7. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    564
    Likes Received:
    8
    Use a heredoc?
    Code:
    echo << ThisIsAComment > nul
    Lorem ipsum dolor sit amet, consectetur adipiscing elit,
    sed do eiusmod tempor incididunt ut labore et dolore magna
    aliqua. Ut enim ad minim veniam, quis nostrud exercitation
    ullamco laboris nisi ut aliquip ex ea commodo consequat.
    Duis aute irure dolor in reprehenderit in voluptate velit
    esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
    occaecat cupidatat non proident, sunt in culpa qui officia
    deserunt mollit anim id est laborum.
    ThisIsAComment
    
     
  8. djspits

    Joined:
    Apr 13, 2010
    Messages:
    189
    Likes Received:
    2
    dcantor's solution works, but not in an alias. The TEXT statement makes the parser scan for ENDTEXT which fails if "hidden" in an alias.

    John's solution needs unique delimiters for each block, which makes the use of aliases problematic too.

    I wonder if there is a (albeit small) performance hit when using solutions based on redirecting to the nul device. Does any transfer actually take place, internally? I have no idea. If so, I would expect the IFF/ENDIFF solution the be faster.

    DJ.
     

Share This Page