Re : [haXe] Re: Typing optional rule idea.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re : [haXe] Re: Typing optional rule idea.

Nicolas Cannasse
It's supported in 2.08 (for macros only)

----- Reply message -----
De : "Cauê Waneck" <[hidden email]>
Pour : "The haXe compiler list" <[hidden email]>
Objet : [haXe] Re: Typing optional rule idea.
Date : sam., oct. 1, 2011 05:05


well, about that, I've been thinking about making a macro for that and for having the facility of the anonymous structures for library parsing with the speed of strongly typed classes for the strongly typed targets.
It would be a first step for huge file formats, even though how haxe handles enums on the backend (array of dynamics) isn't also very ideal.

Anyway, what you're aiming for would be doable (I think) with macro autobuild and

@:structure(
{
someting:Int,
?optional:String
})
class PlaceHolder extends MyAutoBuildStructureClass {}

Of course that the native support for that would be fantastic!

-- On a side note, Nicolas, is there any way for you to support this so we can use with macros:
@:build(my.path.to.build())
class OtherBuildClass
{
var nonStaticVar:String = "oneExpressionHere";
}

Currently, even though the structure supports it, I get an error before being able to change it to a valid haxe expression with the build function

2011/9/30 Heinz Hölzer <[hidden email]>
Your idea in other words ;)

http://haxe.org/com/features?lang=en

see optional structure fields.

best,
h

Am <a href="tel:30.09.2011%2021" value="+553009201121" target="_blank">30.09.2011 21:44, schrieb sledorze:

Oh sorry; I meant

typedef Options = {
  minHeight : Int,
  ?maxHeight : Int // Optional..
};

(wow, must be tired)

Stéphane

--
View this message in context: http://haxe.1354130.n2.nabble.com/Typing-optional-rule-idea-tp6848922p6849066.html
Sent from the Haxe mailing list archive at Nabble.com.



--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Re : [haXe] Re: Typing optional rule idea.

Cauê W.
That's great, Nicolas! : )

Thanks!

2011/10/1 Nicolas Cannasse <[hidden email]>
It's supported in 2.08 (for macros only)

----- Reply message -----
De : "Cauê Waneck" <[hidden email]>
Pour : "The haXe compiler list" <[hidden email]>
Objet : [haXe] Re: Typing optional rule idea.
Date : sam., oct. 1, 2011 05:05


well, about that, I've been thinking about making a macro for that and for having the facility of the anonymous structures for library parsing with the speed of strongly typed classes for the strongly typed targets.
It would be a first step for huge file formats, even though how haxe handles enums on the backend (array of dynamics) isn't also very ideal.

Anyway, what you're aiming for would be doable (I think) with macro autobuild and

@:structure(
{
someting:Int,
?optional:String
})
class PlaceHolder extends MyAutoBuildStructureClass {}

Of course that the native support for that would be fantastic!

-- On a side note, Nicolas, is there any way for you to support this so we can use with macros:
@:build(my.path.to.build())
class OtherBuildClass
{
var nonStaticVar:String = "oneExpressionHere";
}

Currently, even though the structure supports it, I get an error before being able to change it to a valid haxe expression with the build function

2011/9/30 Heinz Hölzer <[hidden email]>
Your idea in other words ;)

http://haxe.org/com/features?lang=en

see optional structure fields.

best,
h

Am <a href="tel:30.09.2011%2021" value="+553009201121" target="_blank">30.09.2011 21:44, schrieb sledorze:

Oh sorry; I meant

typedef Options = {
  minHeight : Int,
  ?maxHeight : Int // Optional..
};

(wow, must be tired)

Stéphane

--
View this message in context: http://haxe.1354130.n2.nabble.com/Typing-optional-rule-idea-tp6848922p6849066.html
Sent from the Haxe mailing list archive at Nabble.com.



--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Re : [haXe] Re: Typing optional rule idea.

singmajesty
In reply to this post by Nicolas Cannasse
Enyo requires a lot of optional parameters, because it follows a factory  
method for generating "classes"

I was able to create strongly typed objects with only optional parameters  
by using some untyped Javascript. Yes, it is a bit of a hack, but it  
works, and the workflow improvements for having strong-typed objects  
instead of dealing with generics, in mind, is certainly worth it.

The basic structure looks something like this:


public class DataObject {

        public var alpha:Float;
        public var height:Float;
        public var width:Float;
       
        public function new () {
               
                untyped __js__ ("this.alpha = undefined;");
                untyped __js__ ("this.height = undefined;");
                untyped __js__ ("this.width = undefined;");
               
        }
       
}



When the object is first created, each of the properties are available as  
null values. Since the properties are defined, it can mess with libraries  
who are expecting them to be defined with values you want, or to be  
undefined. Once the object is created, the first thing it does is undefine  
these values. The object is returned to a blank slate. From then on,  
setting the properties will redefine them if they are actually used.

The smarts for undefining a function that is not extended by a child class  
is a bit different, because setting it to undefined will occur after the  
definition of the function, but I can share that later if anyone is really  
interested. The above is the basic idea.

You would use it like this:


var object = new DataObject ();
object.alpha = 1;


...would equal something like { alpha: 1 }, not { alpha: 1, height: null,  
width: null }




On Sat, 01 Oct 2011 02:06:09 -0700, Nicolas Cannasse  
<[hidden email]> wrote:

> It's supported in 2.08 (for macros only)
>
> ----- Reply message -----
> De : "Cauê Waneck" <[hidden email]>
> Pour : "The haXe compiler list" <[hidden email]>
> Objet : [haXe] Re: Typing optional rule idea.
> Date : sam., oct. 1, 2011 05:05
> well, about that, I've been thinking about making a macro for that and  
> for having the facility of the anonymous structures for library parsing  
> with the speed of strongly typed classes for the strongly typed targets.
>
> It would be a first step for huge file formats, even though how haxe  
> handles enums on the backend (array of dynamics) isn't also very ideal.
> Anyway, what you're aiming for would be doable (I think) with macro  
> autobuild and
>
>
> @:structure({someting:Int,?optional:String})class PlaceHolder extends  
> MyAutoBuildStructureClass {}
> Of course that the native support for that would be fantastic!
>
>
> -- On a side note, Nicolas, is there any way for you to support this so  
> we can use with macros:@:build(my.path.to.build())class OtherBuildClass{
>
>
> var nonStaticVar:String = "oneExpressionHere";}
> Currently, even though the structure supports it, I get an error before  
> being able to change it to a valid haxe expression with the build  
> function
>
>
> 2011/9/30 Heinz Hölzer <[hidden email]>
>
>
> Your idea in other words ;)
>
>
>
> http://haxe.org/com/features?lang=en
>
>
>
> see optional structure fields.
>
>
>
> best,
>
> h
>
>
>
> Am 30.09.2011 21:44, schrieb sledorze:
>
>
> Oh sorry; I meant
>
>
>
> typedef Options = {
>
>   minHeight : Int,
>
>   ?maxHeight : Int // Optional..
>
> };
>
>
>
> (wow, must be tired)
>
>
>
> Stéphane
>
>
>
> --
>
> View this message in context:  
> http://haxe.1354130.n2.nabble.com/Typing-optional-rule-idea-tp6848922p6849066.html
>
>
>
> Sent from the Haxe mailing list archive at Nabble.com.
>
>
>
>
>
>
>
>


--
Using Opera's revolutionary email client: http://www.opera.com/mail/

--
haXe - an open source web programming language
http://haxe.org