fix: lambda now have correct closure
This commit is contained in:
1 parent
306a7f26ef
commit
c0cf190452
8 files changed
+239
-57
No files matched your search
+15
@@ -70,3 +70,18 @@ Regular methods are called on instances as usual `instance.method()`. The method
|
||||
1. this instance methods;
|
||||
2. parents method: no guarantee but we enumerate parents in order of appearance;
|
||||
3. possible extension methods (scoped)
|
||||
|
||||
# Defining a new class
|
||||
|
||||
The class is a some data record with named fields and fixed order, in fact. To define a class,
|
||||
just Provide a name and a record like this:
|
||||
|
||||
class Vec2(x,y)
|
||||
|
||||
This way, you have created a _constructor_, so calling `Vec2( 10, 20 )` would create an _instane_ of `Vec2` class:
|
||||
|
||||
class Vec2(x,y)
|
||||
Vec2(10,20)
|
||||
>> eee
|
||||
|
||||
TBD
|
||||
+13
-1
@@ -47,7 +47,7 @@ One interesting way of using closure isolation is to keep state of the functions
|
||||
>>> 0
|
||||
>>> 1
|
||||
>>> 2
|
||||
>>> void
|
||||
>> void
|
||||
|
||||
Inner `counter` is not accessible from outside, no way; still it is kept
|
||||
between calls in the closure, as inner function `doit`, returned from the
|
||||
@@ -75,3 +75,15 @@ The example above could be rewritten using inner lambda, too:
|
||||
>>> 1
|
||||
>>> 2
|
||||
>>> void
|
||||
|
||||
Lambda functions remember their scopes, so it will work the same as previous:
|
||||
|
||||
var counter = 200
|
||||
fun createLambda() {
|
||||
var counter = 0
|
||||
{ counter += 1 }
|
||||
}
|
||||
val c = createLambda()
|
||||
println(c)
|
||||
>> 1
|
||||
>> void
|
||||
@@ -0,0 +1,24 @@
|
||||
# Classes
|
||||
|
||||
## Declaring
|
||||
|
||||
class Foo1
|
||||
class Foo2() // same, empty constructor
|
||||
class Foo3() { // full
|
||||
}
|
||||
class Foo4 { // Only body
|
||||
}
|
||||
|
||||
```
|
||||
class_declaration = ["abstract",] "class" [, constructor] [, body]
|
||||
constructor = "(", [field [, field]] ")
|
||||
field = [visibility ,] [access ,] name [, typedecl]
|
||||
body = [visibility] ("var", vardecl) | ("val", vardecl) | ("fun", fundecl)
|
||||
visibility = "private" | "protected" | "internal"
|
||||
```
|
||||
|
||||
### Abstract classes
|
||||
|
||||
Contain one pr more abstract methods which must be implemented; though they
|
||||
can have constructors, the instances of the abstract classes could not be
|
||||
created independently
|
||||
Reference in new issue
Block a user