jemc changed the topic of #ponylang to: Welcome! Please check out our Code of Conduct => https://github.com/ponylang/ponyc/blob/master/CODE_OF_CONDUCT.md | Public IRC logs are available => http://irclog.whitequark.org/ponylang | Please consider participating in our mailing lists => https://pony.groups.io/g/pony
atk has quit [Quit: Well this is unexpected.]
atk has joined #ponylang
khan has quit [Quit: khan]
khan has joined #ponylang
khan has quit [Client Quit]
khan has joined #ponylang
jemc has joined #ponylang
khan has quit [Quit: khan]
khan has joined #ponylang
khan has quit [Client Quit]
khan has joined #ponylang
jemc has quit [Ping timeout: 248 seconds]
khan has quit [Quit: khan]
khan has joined #ponylang
khan has quit [Client Quit]
khan has joined #ponylang
khan_ has joined #ponylang
khan has quit [Ping timeout: 248 seconds]
khan_ is now known as khan
khan has quit [Quit: khan]
khan has joined #ponylang
khan has quit [Client Quit]
khan has joined #ponylang
Shorttail has joined #ponylang
<Shorttail> How do I get the square root of a U64?
khan has quit [Quit: khan]
khan has joined #ponylang
khan has quit [Quit: khan]
khan has joined #ponylang
<Candle> Shorttail: There's a 'sqrt' function on a F64.
inoas has joined #ponylang
khan has quit [Quit: khan]
khan has joined #ponylang
khan has quit [Client Quit]
khan has joined #ponylang
<Shorttail> Thanks, I figured it out. Conversion was f64, not F64
khan has quit [Quit: khan]
Shorttail has quit [Ping timeout: 260 seconds]
inoas has quit [Quit: inoas]
SenasOzys has quit [Ping timeout: 240 seconds]
SenasOzys has joined #ponylang
SenasOzys has quit [Read error: Connection reset by peer]
SenasOzys has joined #ponylang
kempe has quit [Quit: WeeChat 1.8]
kempe has joined #ponylang
_andre has joined #ponylang
inoas has joined #ponylang
mikeyhew has quit [Quit: Connection closed for inactivity]
dlowe has quit [Quit: ZNC - http://znc.sourceforge.net]
aturley has joined #ponylang
dlowe has joined #ponylang
aturley has quit [Quit: aturley]
SenasOzys has quit [Remote host closed the connection]
SenasOzys has joined #ponylang
SenasOzys has quit [Remote host closed the connection]
SenasOzys has joined #ponylang
nisanharamati has joined #ponylang
khan has joined #ponylang
SenasOzys has quit [Remote host closed the connection]
SenasOzys has joined #ponylang
aturley has joined #ponylang
khan has quit [Quit: khan]
khan has joined #ponylang
aturley has quit [Client Quit]
khan has quit [Quit: khan]
khan has joined #ponylang
khan has quit [Client Quit]
khan has joined #ponylang
SenasOzys has quit [Ping timeout: 240 seconds]
khan has quit [Client Quit]
khan has joined #ponylang
SenasOzys has joined #ponylang
inoas has quit [Ping timeout: 256 seconds]
brainpro1 has quit [Read error: Connection reset by peer]
brainpro1 has joined #ponylang
khan has quit [Read error: Connection reset by peer]
khan has joined #ponylang
khan has quit [Client Quit]
khan has joined #ponylang
khan has quit [Quit: khan]
khan has joined #ponylang
khan has quit [Client Quit]
khan has joined #ponylang
acarrico has quit [Ping timeout: 240 seconds]
_whitelogger has joined #ponylang
_andre has quit [Quit: leaving]
<vassilvk> I am trying to wrap my mind around primitives and I have a question. If a primitive has no fields and there can only be one instance of a user-defined primitive, what is the purpose of a user-defined primitive constructor?
<slfritchie> vassilvk: If I understand your question correctly (that you mean "constructor" to be the "apply()" function) is that Pony convention of calling `PrimitiveName(args)` is shorthand for `PrimitiveName.apply(args)`
<vassilvk> slfritchie: Actually by "constructor" I meant a constructor defined with the "new" keyword - i.e. "new create() => None".
<slfritchie> I'm trying to think of an instance of `PrimitiveName.create()` but failing ... do you have an example in mind?
<vassilvk> See that's the thing, I am trying to figure out what is the applicability of such a constructor. I tried it out -- I can define a parameterless constructor on a user-defined primitive type. Not only that, but my tests show that the constructor is called every time a value is assigned to that primitive.
<vassilvk> As for an example of a primitive constructor, see the definition of builtin Bool, which has some really interesting constructor that looks like this: "new create(from: Bool) => from". This looks like a trick to me and I don't think it is at all applicable to user-defined primitives, because I see no way to pass in a value of user-defined value of type MyPrimitive to the constructor of type MyPrimitive.
<vassilvk> So bottom line is, I was wondering, why are user-defined primitives allowed to have constructors to begin with, if they cannot be "constructed", so to speak. And if the thinking is that although they behave like singletons they are still constructed once, then why isn't the constructor called only once? Plus, they already have a singleton constructor so to speak, in the form of the initialization function _init. Just
<vassilvk> wondering if I'm missing something...
<slfritchie> "[...] I see no way to pass [...] to the constructor of type MyPrimitive". But a primitive isn't an an object, so I'm puzzled by what you mean by "constructor" in that sentence, sorry. (for reference: https://tutorial.ponylang.org/types/primitives.html)
<slfritchie> Can you put a small example into https://playground.ponylang.org ?
<vassilvk> See first paragraph below the numbered list at the top of the document you linked to: "...if your code calls a constructor on a primitive type...".
<vassilvk> Give me a sec -- I'll put together an example
SenasOzys has quit [Read error: Connection reset by peer]
<vassilvk> Also, I'm not sure I understand what you mean by "primitives are not objects". No types are objects. Maybe you mean they are not classes? But they are "similar to classes" as the doc you sent to me points out. And they clearly have constructors, just like classes do.
<slfritchie> Yes, sorry, I meant "not classes".
<vassilvk> Right, but they are "similar to classes" (first sentence from that doc you sent to me).
<slfritchie> Perhaps "similar" isn't a great choice of words.
<slfritchie> ^^ shows that `MyPrimitive(...)` and `MyPrimitive(...)(...)` are short-cuts for calls to `create()` and `apply()`
zetashift has joined #ponylang
<vassilvk> I'm sorry, I don't see what you are referring to -- this is the gist I sent to you...
<vassilvk> Also, I understand how apply() works. My question is about primitive constructors, not about the apply() sugar.
<slfritchie> I forgot to create a new sharable link, this should be better, I hope: https://playground.ponylang.org/?gist=728c2ee69c676e1264a594fde88fee5f
<vassilvk> Yes, thank you -- I understand all that.
<vassilvk> My question is, what is the purpose of a constructor if there is no state to be initialized by that constructor.
<slfritchie> There isn't any construction happening when `MyPrimitive.create()` is called because there's no object associated with it.
<vassilvk> The language allows you to declare a constructor on a primitive using the "new" keyword.
<slfritchie> I've written Erlang code for over 15 years and Pony for about 1/2 year, so my object oriented mind is not well developed.
<vassilvk> Lol :)
<slfritchie> You can try s/new create/fun create/ on that example, but the compiler won't like it
<vassilvk> Exactly -- it complains that there is no constructor defined.
<slfritchie> Hmmm, here's where my lack of OO vocabulary is a problem.
<slfritchie> There's definitely type information associated with a primitive that has been created by `MyPrimitive.create()`, regardless of whether the `create` is explicit or implicit.
<slfritchie> But the value of the type is a constant. x is equal to y is equal to w is equal to z.
<slfritchie> Kind of like a tag refcap: test for equality is about all you can do with a tag
<slfritchie> Usually it's the type info that your code will care about, for use as an enumeration type
<slfritchie> The value info ... who cares? (I think)
<slfritchie> Hrm. Not sure if that's helpful or not.
<vassilvk> Yes, the "value" of a primitive is a constant (or rather an immutable instance) -- all the "is" tests prove it. But that still doesn't help me understand what do I need a primitive constructor for (but the language provides for defining one and even demands for one to be there when performing primitive assignments sich as the one in my gist). And most of all, why is the constructor called every time I acquire that same
<vassilvk> instance.
jbk_ has joined #ponylang
jbk has quit [Ping timeout: 264 seconds]
<slfritchie> Perhaps you want a side-effect (e.g. C FFI call) when "creating" a new primitive instance?
<vassilvk> But you are not creating a new primitive instance -- there is only one.
<slfritchie> In the code I've been working on this afternoon ... for enumeration purposes, I don't care about a `create` method at all, I don't have one. https://github.com/WallarooLabs/wallaroo/blob/8ff465b0fa6e2cd42db20cff8bb6bfe55122911f/lib/wallaroo/core/routing/_test.pony#L291-L297
<vassilvk> Of course - you absolutely don't need one. Most primitives I've seen so far have no constructors.
<slfritchie> Perhaps a notion of preserving symmetry between object instantiation and primitive looks-like-instantiation is the reason? And/or it makes some compiler task easier? I don't know.
<vassilvk> Umm, I think that's not it -- I mean, the designers of the language did not attempt to preseve symmetry between classes and actors, why do it for primitives and classes.
<vassilvk> I have another theory...
<vassilvk> The builtin primitives - they are the reason to have constructors. They actually need constructors as evident by the Bool primitive.
atk has quit [Quit: Well this is unexpected.]
<vassilvk> They need constructors, because they have state.
<vassilvk> So, I think the designers of the language *had* to maintain the presence of constructors in user-defined primitives, because they had to have constructors for the builtin primitives.
<vassilvk> Just a theory, which I'm trying to prove wrong by finding a good use case where constructors make sense for user-defined primitives.
<slfritchie> Perhaps if you really desired to keep stateless primitives and stateful "machine word" thingies as similar as possible? Could be.
<vassilvk> Or maybe they are based on the same underlying fundamental structures? Could be..
<vassilvk> Anyways, thanks for trying to hash this out with me, @slfritchie
<slfritchie> Thanks for suffering through my questions. ^_^
<vassilvk> lol :) same
nisanharamati has quit []