Improve this list splitter

I've come up with this to split a list into two

(end goal is to perform a map/filter on 1st item in the split list and then recombine it with the 2nd item)

But I'm struglling to come up with only having to specify the "is x a number" predicate once instead of twice)

e.g this doesn't work

I have come up with this

With respect to your end goal ...
If you're looking to do a map over numbers only, why don't you use ... ?

Programming tools DEVLAB script pic
(with (neg) OF () as an example mapping operation).

Or if you are looking to filter numbers only, you could use something like:

Programming tools DEVLAB script pic (1)
(with () < (0) as an example filter operation).

If however you really really want to create a list with two sublists without having to do the selection operation twice you could also use MAP to produce a list of TRUE and FALSE, and then two filters. This is nonsense in the case of IS () A (number) of course, but may be useful if your selection operation is e.g. very time-consuming:

Programming tools DEVLAB script pic (2)

Yet another approach, using FOR EACH:

Programming tools DEVLAB script pic (3)

Which approach you choose (including your own #3) is up to you. Yours is very compact, yet less readable than my suggestions, IMO. And perhaps one of the approaches yields faster execution, that's something you would have to try and measure if it matters to you.

I find it interesting how much forum people have started using metaprogramming features to solve problems that shouldn't really require them. This is not a criticism of forum people; it reflects the fact that the ordinary-programming ways to do things are syntactically more complicated.

(An interesting deep question I'm too tired to think about right now is whether this reflects some inherent weakness in block language syntax. I'll think about that tomorrow.)

So, here's the official non-meta way to do what you're doing with that JOIN block:

The reason you had trouble finding this solution is that you got confused about whether input #1 is a predicate or a Boolean. That's why I gave the inputs meaningful names in my version. The input to NOT must be a Boolean, so it's a domain error to say untitled script pic (1). You are trying to work in the algebra of functions. So another way to accomplish this task would be

Just to make the crucial part bigger so you can see it:
untitled script pic (4)
The inputs to COMPOSE are functions, and it reports a function, which is what KEEP expects as input. So it's important to unringify that COMPOSE expression, so that the input to KEEP is a function of Booleans, rather than a function of predicates.

But the real problem in this exercise isn't just that you had to put the function in the program twice (a problem that procedure inputs solve nicely), but also that the computer has to test the function twice for each item of the list. Really you should invent a new SPLIT higher order function for this situation:

... except that we should really allow compiling in FOR EACH ITEM so this can run at something like the speed of MAP and so on.

Your naming and explanation is excellent :slight_smile: I'll hopefully remember about this the next time :slight_smile:

I'll have to re-read several times I think before I'll comprehend it :slight_smile:

Good point :slight_smile: (And just noticed that @qw23 came up with same solution)

The "is an number" and the data set were just a simple example :slight_smile:

I'm actually trying to find duplicates of certain types of blocks in a script
So 1st operation is to split my master list into possible candidates and then I'm going thru the 1st list and removing duplicates and then re-assembling the list again

It's only since I started meta-programming a few weeks ago and had been doing it a lot, that it occurred to me to try it

It seems to be a simplified version of

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.