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 3484006
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:44:22+00:00 2026-05-18T10:44:22+00:00

is it possible to create a set of variables from a list of values

  • 0

is it possible to create a set of variables from a list of values using a closure??
the reason for asking this is to create some recursive functionality based on a list of (say) two three four or five parts
The code here of course doesn’t work but any pointers would be helpful.then

def longthing = 'A for B with C in D on E'
//eg shopping for 30 mins with Fiona in Birmingham on Friday at 15:00
def breaks = [" on ", " in ", "with ", " for "]
def vary = ['when', 'place', 'with', 'event']

i = 0
line = place = with = event = ""
breaks.each{
shortline = longthing.split(breaks[i])
longthing= shortline[0]
//this is the line which obviously will not work
${vary[i]} = shortline[1]
rez[i] = shortline[1]
i++
 }
return place + "; " + with + "; " + event
// looking for answer of D; C; B

EDIT>>

Yes I am trying to find a groovier way to clean up this, which i have to do after the each loop

len = rez[3].trim()
if(len.contains("all")){
len = "all"
} else if (len.contains(" ")){
len = len.substring(0, len.indexOf(" ")+2 )
}
len = len.replaceAll(" ", "")
with = rez[2].trim()
place = rez[1].trim()
when = rez[0].trim()
event = shortline[0]

and if I decide to add another item to the list (which I just did) I have to remember which [i] it is to extract it successfully

This is the worker part for then parsing dates/times to then use jChronic to convert natural text into Gregorian Calendar info so I can then set an event in a Google Calendar

  • 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-18T10:44:23+00:00Added an answer on May 18, 2026 at 10:44 am

    How about:

    def longthing = 'A for B with C in D on E'
    def breaks = [" on ", " in ", "with ", " for "]
    def vary = ['when', 'place', 'with', 'event']
    rez = []
    line = place = with = event = ""
    
    breaks.eachWithIndex{ b, i ->
      shortline = longthing.split(b)
      longthing = shortline[0]
      this[vary[i]] = shortline[1]
      rez[i] = shortline[1]
    }
    return place + "; " + with + "; " + event
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to understand if it's possible to create a set of variables that
Is it possible to create a new List<T> where the T is dynamically set
Possible Duplicate: Set Locale programatically I would like to create an english/spanish option choice
Possible Duplicate: Create an Array of the Last 30 Days Using PHP I am
Possible Duplicate: Get Variable from httpcontext coming from NSUrlRequest This question will be a
We have some search functionality that can return tens of thousands of results from
Is it possible to set the result from a prepared statement into a variable?
I want to create variables inside a function from a dictionary. Let's say I
Is it possible to retrieve variable set in onreadystatechange function from outside the function?
Is possible create an extension for SQL Management Studio in Visual Studio 2010? Visual

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.