Cool idea: define a function conditionally. Even more powerful than traits

Sure, you can construct cases where one thing can hit a heuristic limit where as the other is not. There’s no fundamental difference here with the tuple length limit. Neither proof anything.

Also, still, the main point is that it’s not even clear what you are trying to do (it’s not dispatch for sure, and it’s not condititonally defining anything either). The fact that you are constructing an API around an incorrectly perceived implementation limitation is really only a minor concern.

I’m telling you that constant propagation is disabled by recursion. You’re wrong, and you’re being mean about it too. Ask @jameson if you don’t believe me.

Well, I said it’s only a minor thing and it’s not even the thing I want to argue about even though I did got carried away on that. That’s why I’ve been asking in the last few replies why this is needed and what you are trying to do since this is neither dispatch or conditionally defining functions.


And as an aside, that I just noticed I forgot to mention. are you suggesting everyone should define a parallel set of method in additional to the methods they are already defining?

1 Like

It’s needed because you can’t index arbitrary iterators (like Generators and Zips) safely in Julia. And you should be able to and this is the best way I can think of to make that happen. Unless you have a better idea.

??? So this is not about defining a function conditionally nor is it about dispatch? And rather its about checking if a method is defined? And the whole thing is about how you can encode/express that condition so that you can essentially use it in a branch?

If that is the case,

  1. I did not see where the topic changed away from conditionally defining a function. It’s not a problem but it’s not obvious and that’s why I kept asking about dispatch.
  2. If this is not about dispatch at all and is just about how you can express a condition then sure that’s part of the implementation and it doesn’t matter at all how you implement it.
  3. If you want this replacement to be extended by the user then AFAICT that’s just defining a trait, i.e. you define methods for the sole purpose of passing information for metaprogramming. (I have not followed up on the latest trait update but this is exactly how trait works in c++ metaprogramming and I’d be surprised if this does not count as trait in julia). In another word, if this is just about define a new trait for sharing information then sure that’s fine too. I have been assuming you want something different that is “even more power than traits” and thats what I have not seen and got confused by.

Also back to the note about constant propagation, as I mentiond above, how you do computation on the result is a problem for the user (edit: of the return value). If you want better constant propagation through mapreduce, you are very much free to do hasmethod(...) ? True() : False() on the user side. It’s just that you’ll see huge penalty if the type is ever unstable and that this should not be part of the API due the this kind of penalty. Returning a simple value gives much more uniform performance in general and is a much better API. (Again, if this is internal where you have full control on the input rather than a trait where you have little control over then it doesn’t matter how you do it)

Here is some human being advice. When someone says “I have a new idea that I’m excited about” you don’t say “that’s stupid and you’re wrong”, you say “thanks for sharing that with us, I have some suggestions that might help you”. Even if they are wrong (and I wasn’t).

4 Likes

I acknowedge I wasn’t replying with all the appreciation I could have after seeing multiple red flags but I have never said these or anything close to implying you are not able to understand what I’m talking about. I’m obviously implying I disagree what you claim but I did so by giving all the reasons I believe they are wrong. I didn’t even say they are wrong as I don’t think there’s nothing incorrect. Only that what you post doesn’t seem to match up with what you claim you have and I was repeated asking for clarification on exactly that (i.e. are you trying to do dispatch or not).

3 Likes

@yuyichao, you’re a very knowledgeable and helpful person, however I think sometimes your style of writing which is quite direct and to the point can come across as aggressive and confrontational. It seems you don’t mean to come off that way, but that has been my impression a few times reading your interactions with people.

6 Likes

Worded like this, it is more dehumanizing than constructive. Please don’t do this.

3 Likes

In this case, not at all (didn’t check for other discussions)
Reading from top to bottom, as I am quite interested in these types of discussions, I was completely surprised as it comes to

ok, I thought, go back and find out, why (s)he’s got this impression… and I didn’t found anything.

Anyways, for me, I like both (technical) arguments, the OP made me learn something about macros and how to achieve things, and on the other side, what may be still an issue.
So, thanks to both of you.

3 Likes

I don’t understand when I would use this? And the following discussion got really technical really quick. I’m not an expert in compilers.

The only reason I can think of to use this would be when defining a function inside another function and that the compilation of that internal function would fail if called with the parameters that were passed in to the parent function. But then wouldn’t I want to check the parameters after they are passed in to verify that they are what I need and return or throw an exception that point. Or does the internal function get compiled before my parameter check can run? And this is a way of avoiding a compiler error?

And what about if the internal function use a local variable to the parent function. I would need to check that type as well before the internal function compiles?

Or am I totally missing the point?