Quote:
Original post by umbrae 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.
The key phrase here being if a feature is almost free. A lot of what PHP can do doesn't come for free. In the case of methods, on the other hand, the data must already be stored. It's only a question of making it available to the scripter, and I think that makes it almost free.
For all its minimalism, Scheme has a problem: its minimalism. Because it lacks any kind of user-defined types, a module system, or exception handling, amongst other things, each Scheme implementation provides these terribly important things in a slightly different, and therefore incompatible, manner.
A good way to design a language is to make a minimalist core; something semantically similar to Scheme would be ideal, although it need not be syntactically similar. Then define a 'standard prelude'; this is automatically included in all programs. The prelude defines common control structures, data types and shorthand notation for useful declarations (of classes or multimethods, for example). Layered on top of that are the various components of the 'standard library', which are included only when requested.
Quote:
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 courseclass 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.
I think you have me confused.
Firstly, think about what would be in the method bodies of the two versions of list.each. They'd be exactly the same. In fact, if they weren't exactly the same, people would complain loudly, because the class would never behave as expected. If two functions must contain the same code, that's often a clue that there should only be one function.
Secondly, I don't suggest putting the code in the function call. Instead, I'd put it after the function call, in the manner of a normal indented block.
class base // a closure accepting method void method(integer i, boolean b, object() m)// calling that methodbase bb.method(4,true) if (i > 7) return new integer else return new decimal
This gets weird if you have something like the following:
bool is_it? (object() m)if is_it?() return true print "It is."else print "It isn't."