Quote:Original post by Mayrel Well, no. Closures are a kind of object, whilst a parameter is a kind of variable. So clearly they aren't the same. But integers are objects and they can be passed in a parameter. So there's no reason you shouldn't do the same to closures.
I will note that every language that I am aware of that uses closures treats them as just another object. |
My bad, I was referring to the half-hearted closures that I was planning to implement - they aren't objects.
Quote:If a feature is almost free, doesn't use up syntax that would be better used for something else, and isn't actively dangerous, you should put it in. In those kinds of cases, wondering whether or not people will want to use them is silly.
People who don't want to use them won't, and people who do want to use them will. If it turned out that nobody used them, which I very much doubt would be the case, you've hardly wasted any work, since all you've had to do is expose the method type that must already exist inside the engine. |
I agree with you on some level, but what I don't want in a language is a cacophony of features. When I was reading about
scheme I really liked it's philosophy. It's very minimalistic and doesn't add features even if they might be a bit useful. As I remember php started out as a very fast, small scripting language. But it has now grown, and uses up more resources. A lot of languages start small, but then they start to gather more features, and before you know it - they are java. :P But seriously, I think a small subset of features is good, with more functionality built on top of that.
That said, I think method variables are very good - and I will have a go at putting them in the language.
The point in question is whether to allow closures as a parameter for a method.
class list // a normal function void each(void(object value) m)// calling code, this is okaylist a = [1,2,3]a.each(an_object.a_method)// is this okay? (closures a replacement for a method?)a.each system.println(value)
I'm in two minds about this, I think it is good, and makes sense - but I also think there needs to be a difference in syntax when defining closures. You could define both, and let overloading take it's course
class list // this takes a function void each(void(object value)) // this takes a closure void each()(void(object value) m)
I think that there is too much ambiguity when defining closure accepting methods just by having the function definitions as the closure. Because this language is currently lined up to be a tabbed block language, it makes it harder because I think that something like this doesn't look right:
class base // a closure accepting method void method(integer i, object() m, boolean b)// calling that methodbase bb.method(4, if (i > 7) return new integer else return new decimal , true)
How to indent it is not well defined, and it is hard to see what is happening. You could make a rule that method parameters always have to be at the back, but then you still need the ending ")". It is for this reason that I think that closure accepting methods need to have a different syntax, and I am considering only allowing one closure per method.
[Edited by - umbrae on November 17, 2004 9:15:15 PM]