Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1057477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:52:29+00:00 2026-05-16T17:52:29+00:00

Let’s say I want to generate this output: public String toString() { return this.getFirstName()

  • 0

Let’s say I want to generate this output:

  public  String toString() {
         return this.getFirstName() + "," + this.getLastName() + "," + this.getAge();
  }

from the template below and a custom recursive build-markup function:

  template-toString: {this.get<%property%>() <%either not context.build-markup/EOB [{+ "," +}][""]%> }

  build-markup/vars template-toString [property] ["FirstName" "LastName" "Age"]

My problem is to avoid the last element to be concatenate with {+ “,” +}

My idea was to use a context.build-markup with an EOB property (End Of Block) that would be set to true when last element is processed. Then I could use in template-toString above either not context.build-markup/EOB [{+ “,” +}][“”] to concatenate or not with {+ “,” +} :

context.build-markup: context [

  EOB: false

  set 'build-markup func [
      {Return markup text replacing <%tags%> with their evaluated results.} 
      content [string! file! url!] 
      /vars block-fields block-values
      /quiet "Do not show errors in the output." 
      /local out eval value n max i
  ][

    out: make string! 126 

    either not vars [
        content: either string? content [copy content] [read content] 

        eval: func [val /local tmp] [
            either error? set/any 'tmp try [do val] [
                if not quiet [
                    tmp: disarm :tmp 
                    append out reform ["***ERROR" tmp/id "in:" val]
                ]
            ] [
                if not unset? get/any 'tmp [append out :tmp]
            ]
        ] 
        parse/all content [
            any [
                end break 
                | "<%" [copy value to "%>" 2 skip | copy value to end] (eval value) 
                | copy value [to "<%" | to end] (append out value)
            ]
        ]
      ][          


          n: length? block-fields

          self/EOB: false

          actions: copy []

          repeat i n [



            append actions compose/only [

              ;set in self 'EOB (i = n)
              set in system/words (to-lit-word pick (block-fields) (i)) get pick (block-fields) (i)
            ]

          ]
          append actions compose/only [            
              append out build-markup content            
          ]
          foreach :block-fields block-values actions



          if any [(back tail out) = "^/" (back tail out) = " " (back tail out) = "," (back tail out) = ";" (back tail out) = "/" (back tail out) = "\"] [
            remove back tail out
          ]        
      ] 
      out
  ]

]

But my attempt failed (so I commented ;set in self ‘EOB (i = n) because it doesn’t work). How to correct the code to get what I want ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:52:29+00:00Added an answer on May 16, 2026 at 5:52 pm

    I’m quite certain you could be achieving your goal in a cleaner way than this. Regardless, I can tell you why what you’re doing isn’t working!

    Your n is the expression length? block-fields, and your repeat loop goes up to n. But block-fields contains the single parameter [property]! Hence, it loops from 1 to 1.

    You presumably wanted to test against something enumerating over block-values (in this example a range from 1 to 3) and then handle it uniquely if the index reached 3. In other words, your set in self 'EOB expression needs to be part of your enumeration over block-values and NOT block-fields.

    This would have given you the behavior you wanted:

    n: length? block-values
    i: 1
    foreach :block-fields block-values compose/only [
        set in self 'EOB equal? i n
        do (actions)
        ++ i
    ]
    

    This absolutely won’t work:

    append actions compose/only [
        set in self 'EOB (i = n)
        set in system/words (to-lit-word pick (block-fields) (i)) get pick (block-fields) (i)
    ]
    

    …because you are dealing with a situation where i and n are both 1, for a single iteration of this loop. Which means (i = n) is true. So the meta-code you get for “actions” is this:

    [
        set in self 'EOB true 
        set in system/words 'property get pick [property] 1
    ]
    

    Next you run the code with a superfluous composition (because there are no PAREN!s, you could just omit COMPOSE/ONLY):

    append actions compose/only [
        append out build-markup content
    ]
    

    Which adds a line to your actions meta-code, obviously:

    [
        set in self 'EOB true 
        set in system/words 'property get pick [property] 1 
        append out build-markup content
    ]
    

    As per usual I’ll suggest you learn to use PROBE and PRINT to look and check your expectations at each phase. Rebol is good about dumping variables and such…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a drive such as C:\ , and I want to
Let's say you create a wizard in an HTML form. One button goes back,
Let's say I'm building a data access layer for an application. Typically I have
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,
Let me preface this question by saying I use TextMate on Mac OSX for
Let me try to explain what I need. I have a server that is
Let's aggregate a list of free quality web site design templates. There are a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.