Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: string concatenation of constants #5282

Closed
R32 opened this issue May 26, 2016 · 4 comments
Closed

feature request: string concatenation of constants #5282

R32 opened this issue May 26, 2016 · 4 comments

Comments

@R32
Copy link
Contributor

R32 commented May 26, 2016

same as math expressions, it make the output look cleaner

class Main{
    static inline var PREF = "#";
    static function main() {
        trace(PREF + "foo");
    }
}

js output:

console.log("#" + "foo");

but i would like to get:

console.log("#foo");
@kevinresol
Copy link
Contributor

Check out the discussions here #4706

@R32
Copy link
Contributor Author

R32 commented May 31, 2016

Well, I just hope that can only be applied to JavaScript

@Simn Simn added this to the 3.4 milestone Jun 2, 2016
@nadako
Copy link
Member

nadako commented Jun 8, 2016

I also want this, if not for all strings, then at least for those I specify explicitly with a metadata. With Haxe's rich type system we are able to wrap really crazy string-based extern APIs in a properly typed interface, and that would benefit very much from string constant concat.

Here's a cool example from my hxdefold extern library experiment:

abstract Property<T>(String) from String {}

extern class Go {
    static function get<T>(prop:Property<T>):T;
}


extern class Vector {
    var x:Float;
    var y:Float;
}

abstract VectorProperty(Property<Vector>) from String to Property<Vector> {
    public var x(get,never):Property<Float>;
    inline function get_x():Property<Float> return '$this.x';
}


class Main {
    static inline var SizeProperty:VectorProperty = "size";

    static function main() {
        var vec = Go.get(SizeProperty); // get the whole Vector
        var x = Go.get(SizeProperty.x); // get just the x part
    }
}

What it currently generates is obviously this:

Main.main = function() {
    Go.get("size");
    Go.get("size" + ".x");
};

Obviously, if one would write it directly in a target language, they would just write Go.get("size.x"); and this concatenation looks pretty stupid.

@Simn Simn modified the milestones: 3.4, 4.0 Jan 9, 2017
@Simn Simn removed this from the Release 4.0 milestone Apr 17, 2018
@Simn
Copy link
Member

Simn commented Apr 19, 2018

#4706

@Simn Simn closed this as completed Apr 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants