Quote:
Original post by cmp
could you explain what closures really are?
Sure.
Edit: This is wrong. A closure is the block of code that is called, it is a method of sorts and can reference variables outside it's scope - sometimes even outside the method that it was defined in's stack frame. Closure Definition
Basically they are method acceptors. You define little blocks of code to be called by the closure. For example say you want to do something with each value in a list you can say:
list a = [1, 3, 6]a.each // now this code gets called for each element in the list with value // being the value of the element system.println(value)
The output would be:
136
As you can see this is easier than using iterators or other ways to move through a list. Even if I just implemented the each closure only, it would be a great addition.
For the map closure on a list, the inner code needs to return a value to put into the new list.
list a = [1, 3, 6]list bb = a.map // this code also gets called for each value in the list, // but it returns a new value that will be put into list b return value * 3
List a now equals [3, 9, 18].
There is also the filter closure, The bit of code also gets the value, but it returns a boolean whether to include that value in the returned list.
list a = [1, 2, 3, 4, 5, 6]list blist b = a.filter // this code gets called with the value, and returns a boolean // whether to include it in the returned list return value < 4
List b now equals [1, 2, 3]. Closures are a great way to implement iterations, and mapping functions. If anyone has used Haskell, they will find that it has this functionality as well. I think Ruby also has these blocks of code.
The good thing about closures is that the code can also reference other variables outside the closure scope. For example a sum is very easy to calculate.
list a = [1, 3, 6]
integer sum = 0
a.each
sum += value
I was even thinking about having for and while loops, if statements and other code branching keywords as closures, that it the C++ implementation of them does the actual branching - the voodoo language (at least the bytecode) doesn't need to have branches or loops. You could say something like: system.if(x < 7) x = 7
And the if closure is defined as:class system + void if(boolean b){void()}
Quote:update: i've released the micro xml to xml converter.
Cool, I will have a look next time I'm on the internet (56k, and calls can't get through).
Quote:Original post by visage
for your 1...5 argument, I would recommend you do math notation.
Will look into it. At the moment though that would be parsed a bit wrong, unmatched braces, but it looks like a good syntax.
I shy away from mathematics a bit because of useability, maths isn't the easiest thing to learn, and a lot of things that get explained using mathematics could be explained easier other ways. I'm thinking turing machines in particular, have you tried learning them straight from their mathematical notation? Our lecturer tried to teach us that way, it just doesn't work. It is often easier to use english.
But with that aside, that notation is parse-able and looks good. I would still argue it's necessity though, do we need inclusion / exclusion in a non-maths specific language?
[Edited by - umbrae on November 16, 2004 1:07:42 AM]