Skip to main content

How to convert var: self

6 replies [Last post]
av_ivashka
Offline
Joined: 2008-04-27

I try to convert a javafx-code with "var: self" in a compiled code - like in

var p1 = Person {
var: me
name: "av_ivashka"
};

But the parser says:

<>

How to organize "this"-like constructions in the compiled code?
Thanks in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexsch
Offline
Joined: 2007-07-12

For example:

[code]
var me: Person;

me = Person {
name: "av_ivashka"
};
var p1 = me;
[/code]

av_ivashka
Offline
Joined: 2008-04-27

Thanks. But I need this for internal bindings, like here:

var p: Person =
Person {
var: self
name: "John"
surname: "Smith"
fullname: bind "{self.name} {self.surname}"
};

I know how to do this in class declarations:

class Person {
attribute name: String;
attribute surname: String;
attribute fullname: String = bind "{this.name} {this.surname}";
}

But "var: self" made it possible to do the same in object generators.

alexsch
Offline
Joined: 2007-07-12

You can use variable for these purposes:

[code]
var p: Person;
p = Person {
name: "John"
surname: "Smith"
fullname: bind "{p.name} {p.surname}"
};
[/code]

av_ivashka
Offline
Joined: 2008-04-27

ok, thanks. It is a solution though less convenient in case of nested constructions.

By the way, the code in your message is nicely highlighted and formatted. Can I do the same? Have more questions...

alexsch
Offline
Joined: 2007-07-12

You are right. This solution does not look very good for nested constructions.
[code]
Frame{
var label = Label{ text: "Hello World!"}
content: label
visible: true
}
[/code]

You can use [ code ] [ /code ] tags to format code.

av_ivashka
Offline
Joined: 2008-04-27

Yes, in some cases it seriously affects compactness and readability of the language. E.g.
for the interpreter I can define

[code]
Frame {
var: f
width: 300
height: 70
title: "Press me again"
content: Button {text: bind f.title action: operation() {f.title = ".{f.title}.";} }
visible: true
}
[/code]

Here every button's click changes simultaneously the frame's and button's titles. In the compiled version I must have something awkward instead:

[code]
var f:Frame = Frame {
width: 300
height: 70
title: "Press me again"
content: Button {text: bind f.title action: function() {f.title = ".{f.title}."} }
visible: true
}
[/code]

And if the outer object (Frame in this example) is nested into another object, then we have something like

[code]
Outer1 {
....
var f:Outer2 = Outer2 {... f.title=...}
someattribute: f

}
[/code]

Not elegant, at least...