INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Make regex captures persistent...  (Read 2577 times)

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1854
Make regex captures persistent...
« on: December 11, 2011, 04:01:10 am »

One of the major things I need in MC is persistent variables.  I have a bunch of smartlist/view ideas that can only work with such information.  Looking at regex and its Rn variables it seems we're almost there.  But the problem currently is that the Rn variables only persist until the end of the current expression?  Making them available until the next regex function resets them would provide persistent variables...

So the idea is that you use regex to capture a variable R1, for instance.  Then R1 remains available to all functions/smartlists/searches/views etc from that point on until the next regex is run, when it is reset.

This would enable us to perform, for example, a regex on a smartlist limited to one entry designed to pull a specific R1 from that entry and then apply [R1] to new rules across the entire database allowing us to build searches/smartlists/etc tied to that first entry and it's [R1] value.

This one change would open up a whole new world of smartlist functionality.

Cheers,

Mark
Logged

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: Make regex captures persistent...
« Reply #1 on: December 11, 2011, 11:55:22 am »

Hmm. I am not sure what you mean. You can have several custom fields and panes/columns with different regex expressions executing constantly. Which one can be said to provide the latest capture?

You could use a custom field with your regex and use that field across the database.

(In one and the same expression you can use the capture from one regex until another regex in that very same expression executes.)
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Make regex captures persistent...
« Reply #2 on: December 11, 2011, 12:02:57 pm »

This is tantamount to a request for persistent global variables, as all functions return a value which could be used elsewhere.  Nothing magical about regex() here, other than more than a single return value is possible.
Logged
The opinions I express represent my own folly.

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1854
Re: Make regex captures persistent...
« Reply #3 on: December 11, 2011, 12:06:51 pm »

This is tantamount to a request for persistent global variables, as all functions return a value which could be used elsewhere.  Nothing magical about regex() here, other than more than a single return value is possible.

That's exactly what the request is, and I've made it previously elsewhere.  What struck me is that it wouldn't be difficult to extend the regex functionality with regards it's variables to make them global and persistent... thus providing the functionality.

Cheers,

Mark
Logged

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1854
Re: Make regex captures persistent...
« Reply #4 on: December 11, 2011, 12:10:09 pm »

Hmm. I am not sure what you mean. You can have several custom fields and panes/columns with different regex expressions executing constantly. Which one can be said to provide the latest capture?

Clearly care would need to be taken to avoid overwriting variables, but I take your point, eg an Rn is only overwritten next time it is used in a capture.  It would allow views or smartlists the opportunity to use the data before being overwritten by other views/smartlists etc.

Quote
You could use a custom field with your regex and use that field across the database.

I tried that but the [Rn] variables don't persist beyond the life of the regex and thus cannot be used independently elsewhere?

Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Make regex captures persistent...
« Reply #5 on: December 11, 2011, 12:13:25 pm »

I tried that but the [Rn] variables don't persist beyond the life of the regex and thus cannot be used independently elsewhere?

The [Rn] values persist in the expression, until a new regex() overwrites them.  They live within the context of the expression, and die when evaluation is complete.

You can assign any value to a custom field - it will continue to live of course like all fields, until you change it.
Logged
The opinions I express represent my own folly.

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1854
Re: Make regex captures persistent...
« Reply #6 on: December 11, 2011, 12:17:16 pm »

The [Rn] values persist in the expression, until a new regex() overwrites them.  They live within the context of the expression, and die when evaluation is complete.

Yes, that's the limitation that restricts it.

Here is my previous request for globals: http://yabb.jriver.com/interact/index.php?topic=62019.0

Cheers,

Mark
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Make regex captures persistent...
« Reply #7 on: December 11, 2011, 12:24:53 pm »

Ok, read it.  I'm having trouble understanding the ultimate goal (the request focuses on implementation rather than end goal).

Do you have a specific example of something?  I'm only asking so as to see if there is a way to accomplish your goal now.
Logged
The opinions I express represent my own folly.

vagskal

  • Citizen of the Universe
  • *****
  • Posts: 1227
Re: Make regex captures persistent...
« Reply #8 on: December 11, 2011, 12:40:53 pm »

MrC already answered you.

The [Rn] values persist in the expression, until a new regex() overwrites them.  They live within the context of the expression, and die when evaluation is complete.

Just a clarification (also my post needs this clarification): In one and the same MC expression the capture of a regex can be used as (the whole or part of) the input string in a subsequent regex, but when the whole MC expression is evaluated the capture in itself will no longer be available (although the outcome of the MC expression can be stored in a custom field).
Logged

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1854
Re: Make regex captures persistent...
« Reply #9 on: December 12, 2011, 01:37:19 am »

MrC already answered you.

Just a clarification (also my post needs this clarification): In one and the same MC expression the capture of a regex can be used as (the whole or part of) the input string in a subsequent regex, but when the whole MC expression is evaluated the capture in itself will no longer be available (although the outcome of the MC expression can be stored in a custom field).

Yes, I understand this restriction, hence my request for the Rn values to persist AFTER the expression completion.
Logged

mark_h

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1854
Re: Make regex captures persistent...
« Reply #10 on: December 12, 2011, 01:49:52 am »

Ok, read it.  I'm having trouble understanding the ultimate goal (the request focuses on implementation rather than end goal).

The goal is global variables.  Who wouldn't want that?  We know have math(), regex() and many powerful things in MC.  One remaining bit of the functionality puzzle is persistent variables so that we can apply data from one record across others in the database.

Quote
Do you have a specific example of something?  I'm only asking so as to see if there is a way to accomplish your goal now.

I do  ;D

I track chart data in my library.  I track each chart song and the weeks that it was in the charts and the position.  The data might look like this:

Chart History: 1985\03\16>62;1985\03\23>48;1985\03\30>39;1985\04\06>35;1985\04\13>36;1985\04\20>37

Chart History, as you can see, is a ; delimited list of dates followed by > and the chart position for that week.

I also have a field called Chart Entry which is one date and tracks when a song enters the chart, eg

Chart Entry: 1985\03\23

What I want to do is create a smartlist that takes a single Chart Entry date from a random track and then pulls out the top 10 for that week from the Chart History data to create a playlist of the top ten tracks of any random week in chart history.

How I'd achieve this with variables is.

Playlist 1: Pull 1 random track.  Copy the Chart Entry in Memory 1
Playlist 2: Pull all tracks where Memory 1 exists in the Chart History field and whose chart position at that date  < 11

Random Top 10 Smartlist: Playlist 1 and Playlist 2 sort by chart position data

I cannot see how to achieve this without variables.

Regardless,  who wouldn't want persistent variables if they were available?  Every time we get a new piece of functionality it opens up multiple opportunities.  This one I can see opening up many more.  And it struck me how similar my variables are to the regex Rn values.  The missing step is that the Rn values don't persist beyond the life of the expression they are contained within.  If that could be modified, we could get global variables...
Logged
Pages: [1]   Go Up