Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
tjrhodes
@tjrhodes
for all three lines when I expect this to be String
compiler says it wnts String but found GmailAccount
Rudy Ges
@kLabz
Yeah, in the cases
Because you're switching on a String
You either need to String or switching on a GmailAccount
tjrhodes
@tjrhodes
Hmmm, but the error says it wants a String, if this is a String then no error?
now in haxe 4, this appears to be a GmailAccount?
Rudy Ges
@kLabz
No
switch(this) is String
case GmailAccount.Testing: is GmailAccount
Both need to be of the same type, either add to String to your abstract to use String for both, or switch on GmailAccount with the examples I sent earlier
This used to work because of some type hole in abstracts or something, which has been fixed in haxe 4
tjrhodes
@tjrhodes
ok, so if GmailAccount.Testing.toString(), then it'll work
Rudy Ges
@kLabz
Should be easier to declare your abstract as enum abstract GmailAccount(String) to String {...}
tjrhodes
@tjrhodes
ah yes of course
thankyou
Kevin Bloch
@kevin.bloch_gitlab
Hi everyone...quick question, I see -D jvm was added in one of Haxe 4's RCs, yet wasn't highlighted in the main What's New doc for Haxe 4's big release. Was there any reason not to, or was it simply overlooked?
Kevin Leung
@kevinresol
Screenshot 2019-11-14 at 9.36.59 AM.png
Perhaps it is still experimental/beta
Emugel
@emugel
on latest video at blog.haxe.org Simn talks about it, towards the last 4/5 of the video
IIRC Simn said jvm target compiles much faster than java but some transformation functions are not yet as optimized(?) as those he calls the "Waneck functions" in the java target. I'm not sure what that means but if you use that target I encourage you to watch
Emugel
@emugel
this way when you understand it perhaps you can explain it better :D
he said (again) "don't underestimate java"
Emugel
@emugel
if I understood correctly you can draw a parallel between 1. java and hashlink/C and 2. jvm and hashlink/vm. One runs fast and compiles slowly, the other runs slowler and compiles very fast
Peter Achberger
@Antriel
I don't think that's correct. java is simply a Java output that needs to be compiled into something JVM can run. Whereas jvm target goes there directly. Which is faster to compile, and also possibly faster to run, as there could be optimizations that aren't doable from the Java code.
Although iirc in that video he talked about which approach works better in which circumstances, as the JVM target isn't optimized entirely yet.
In either case hashlink/C vs vm one is not a good analogy. VM will be JIT I think, whereas C won't, as it doesn't need to be. With JAVA it's always just VM, there's no native compilation anywhere.
Kevin Bloch
@kevin.bloch_gitlab
Interesting! It seems it was true about run-time performance...I'm not sure which video I watched yesterday, but it was from a pre-4-release time, and there the speaker had claimed that the JVM target was faster both at compile time and at run-time. Maybe that was incorrect or maybe things have changed since then as the feature was worked on further. Thanks for pointing to the new video ( https://haxe.org/videos/conferences/haxeup-sessions-2019/simon-krajewski-haxe-status-report.html if anyone's looking for this later ) OK, good to know...thanks, everyone! :)
Peter Achberger
@Antriel
It should be faster, just maybe not in everything yet, but eventually it should be at least as fast or faster.
It's basically skipping the .java abstraction layer and going directly to bytecode.
Kevin Bloch
@kevin.bloch_gitlab
:+1:
Emugel
@emugel
thanks @Antriel ! yes I think it makes more sense like that
Emugel
@emugel
In my 2 lines notes about that part I wrote " -D jvm produces a .jar with .class bytecode. No need for javac = much faster compilation time", I think I misunderstood javac. So if I understand what you said with -D jvm it should skip the step of producing the java sources, directly writing java bytecode
hence the part about the 'Waneck functions', apparently they're a mess but provide some optimizations not yet available with -D jvm
Peter Achberger
@Antriel
Yeah, that's it.
Mel Massadian
@melMass

Hi, I'm having a hard time wraping my head around enum abstracts use cases.
With this simple example:

enum abstract EConfiguration(String) from String to String{
    var Debug;
    var Shipping;
    var Test;
}

I want to be able to do:

var config:EConfiguration = "Debug";

Which works, but the following works aswel...:

var config:EConfiguration = "Debugtypo";

How can I restrict it to declared fields, throwing on value error ?

Kevin Leung
@kevinresol
You can remove from String and use a custom @:from cast to check the values
Peter Achberger
@Antriel
I just want to add that such approach is only useful if you have input unknown-at-compile-time and indeed want to check it for validity. If you just want to use it as Enum, and for some reason need it to be String, var config:EConfiguration = Debug; will work best. Without using from String.
Mel Massadian
@melMass
@kevinresol Thanks I thought it was just an alternate way to do the same thing !
@Antriel Yep it's the former, runtime string -> valid enum
Kevin Leung
@kevinresol
@melMass it is not the same
Mel Massadian
@melMass
@kevinresol Thanks, I'm not sure what do to in the @:from function to check for valid enum to be honest 🙈
Kevin Leung
@kevinresol
I usually write this:
@:from static function fromString(v:String):EConfiguration {
  return switch v {
    case Debug | Shipping | Test: cast v;
    case _: throw 'error';
  }
}
Mel Massadian
@melMass
<3 Thanks it works as expected
Emugel
@emugel
Any idea/recipe how in unit test to easily test whether a return is equal to certain AST? The enum can contain some Array, e.g. Alt([Seq([Text("Bla"), Opt([Text("Bla")])])]) (not sure if this is even correct ^^). Or should I write something from scratch?
hum I wonder if switch case would not be enough
how to write unit tests for simple AST parsers would be the underlying question I guess
Juraj Kirchheim
@back2dos
pattern matching is probably the easiest way to go
or you make a printer for your AST and then you compare expected vs actual string representation
Emugel
@emugel
alright! yes I tried with pattern matching already and it seems the easiest, at least if there is no error
Axel Huizinga
@axelhuizinga
anyone used d3 time format?
var formatTime = D3.time.format;
compiles but gives the runtime error:
TypeError: d3.time is undefined Charts.hx:229
Philippe
@elsassph
How do you import D3?
Makhor
@Makhor
Hey there! Has anyone gotten a Json parser error: invalid char 0 at position 0 when compiling the hxelectron demo? I'm using haxe 4.0.3, and I am not exactly sure how I could fix this issue.