<emilbayes>
Seems a bit more "dangerous" than what we talked about yesterday with generics
<emilbayes>
Oh right, that's what you do with _make_buffer in pony-sodium
<Candle>
Got my head in a twist wrt json parsing; My aim is to pass the JsonObjects to constructors so that I have short easily comprehendable functions. I could use the 'create' constructors in the data structures, but that would lead to quite a complex looking bit of code in the Main actor; http://pony-playpen.lietar.net/?gist=0d8d5b98d0f4ec895c06de778ffb27fd
<emilbayes>
SeanTAllen: So at the end it says "These are ref for classes, val for primitives (i.e. immutable references) and tag for actors."
<emilbayes>
SeanTAllen: Is there a easy way to get an overview of this?
<SeanTAllen>
I dont see what you are referring to emilbayes
<SeanTAllen>
I'm still not sure what you are asking and don't want to make an assumption and tell you the wrong thing
<emilbayes>
SeanTAllen: Hehe all good
<SeanTAllen>
im not finding "ref for classes" in that page
<emilbayes>
SeanTAllen: I mean that ie. when I defined functions on classes (methods?) I always write `fun tag ...`, but tag is the default reference capability for this, no?
<emilbayes>
SeanTAllen: So I was wondering whether there was a place to get a good overview of what the defaults are
<SeanTAllen>
no tag is not the default
<SeanTAllen>
box is
<emilbayes>
SeanTAllen: On the page I linked, it's the very last paragraph under the headline "What does it mean when a type doesn't specify a reference capability?"
<emilbayes>
SeanTAllen: Oh!
<emilbayes>
SeanTAllen: Goes to show how much I still have to learn
<tokenrove>
yeah, a list of those default reference capabilities would be a nice thing on a pony cheatsheet
<SeanTAllen>
So I think you are mixing two ideas together, maybe intentionally, maybe not
<SeanTAllen>
You can assign a default reference type for a type/class
<emilbayes>
SeanTAllen: Probably not intentional :)
<SeanTAllen>
so for example is an instance of class should generally be `val` based on usage you can do
<SeanTAllen>
class val MyClass
<SeanTAllen>
so you don't have to do to
<SeanTAllen>
let my_class: MyClass val = recover val ... end
<SeanTAllen>
instead you can do
<SeanTAllen>
let my_class = MyClass
<SeanTAllen>
its a convenience really
<emilbayes>
SeanTAllen: Oh ok!
<SeanTAllen>
in a "fun" definition like
<SeanTAllen>
"fun my_method"
<SeanTAllen>
that is shorthand for
<SeanTAllen>
"fun box my_method"
<SeanTAllen>
it was found when working on the early standard library to be the most common so that was done as a shorthand
<SeanTAllen>
NOW
<SeanTAllen>
for the fun part
<SeanTAllen>
errr sorry that was a bad pun
<SeanTAllen>
method parameters:
<SeanTAllen>
fun my_method(x: MyClass)
<SeanTAllen>
so what is the reference capability of "MyClass"?
<SeanTAllen>
that depends on the default we discussed earlier
<SeanTAllen>
if its
<SeanTAllen>
class val MyClass
<SeanTAllen>
then its a `val` otherwise its either `ref` or `iso`
<SeanTAllen>
the `ref` or `iso` is sadly a "feature" that at least sylvan and i want to get rid of
<SeanTAllen>
the default reference capability for a class that has a constructor like
<SeanTAllen>
new create() =>
<SeanTAllen>
is `ref`
<SeanTAllen>
but if your class has no constructor
<SeanTAllen>
then the default type is `iso`
<SeanTAllen>
there are historical reasons for this but the person who fought strongly for it is gone
<SeanTAllen>
and i know sylvan and i both think its very confusing and would like to have the default always be `ref`
<SeanTAllen>
so if you get confused by that last bit, don't worry, it still trips me up all the time
<SeanTAllen>
I hope that helps.
<SeanTAllen>
So, all of this isn't in the tutorial in one place because its really 2 or 3 different topics depending on how you look at it
k0nsl has quit [Quit: “If we don't believe in freedom of expression for people we despise, we don't believe in it at all — Noam Chomsky”]
<SeanTAllen>
Candle: that code won't work
k0nsl has joined #ponylang
k0nsl has joined #ponylang
k0nsl has quit [Changing host]
<emilbayes>
SeanTAllen: ah thanks heaps for clarifying
<SeanTAllen>
candle: i switched that up for you a little, you'd need to recreate the same pattern elsewhere...
<SeanTAllen>
getting a val reference to the JsonDoc
<SeanTAllen>
once I have a val reference to it then, its safe to get at the data as it won't be changed
<SeanTAllen>
so I can match on that as a JsonObject val
<SeanTAllen>
however, I need the else because it could be any other type of JsonType and that isn't handled
plietar has joined #ponylang
<emilbayes>
I'm calling a C function that returns int as a standard return code (0 good, -1 error). Would it be customary for the pony function to raise an error if the c function did return anything but 0?
<SeanTAllen>
i dont think there is a custom on that
<SeanTAllen>
so here's the way to approach "error" right now emilbays
<SeanTAllen>
how likely is the error to occur?
<SeanTAllen>
there is a high cost to `error`, lower than say exceptions in java but still high. if you expect the error to happen often and this code might be used in a "hot path", the you probably don't want to use error. if however, its fairly rare, then error is a good idea.
<SeanTAllen>
the other alternative is a sum type for "this was a good result, this was an error" and there's an overhead to the matching that you would need to do on that
<SeanTAllen>
but that overhead is lower than lots of `error` calls but higher than a "once in a while" error
<SeanTAllen>
that might not be the answer you are looking for emilbayes but its how i always go about approaching the problem
<emilbayes>
SeanTAllen: Thanks for the answer!
<emilbayes>
SeanTAllen: I'm not sure what is right here as the call that might error is very expensive (password hashing), but the rest of the library has cheaper operations (eg. verifying a MAC), but I'd like the API to be consistent
<SeanTAllen>
so here is an important question
<SeanTAllen>
would someone call this a lot?
<SeanTAllen>
if password hashing is expensive then worrying about the cost of `error` seems silly as it will be dominated by other code
<emilbayes>
SeanTAllen: I guess the answer is probably no. It's probably very expensive operations when taking other operations into account
<emilbayes>
Yeah
<SeanTAllen>
so then
<SeanTAllen>
here's the other issue
<emilbayes>
SeanTAllen: I think the added "security" here is worth the cost of error
<SeanTAllen>
for `error` there is no conveying "what went wrong"
<SeanTAllen>
if you need to convey the "type of error", you need a sum type
<emilbayes>
SeanTAllen: Yes ok that too
<SeanTAllen>
if simply "it went wrong" is ok and the "what went wrong" is obvious from the context, then, error is the way to go
<emilbayes>
SeanTAllen: So the C library in question will most likely error if it is unable to allocate enough memory
<emilbayes>
Yeah ok
<SeanTAllen>
i write a lot of high performance code these days so i tend to put performance concerns ahead of api concerns, not that i want bad api's, i just think about the performance implications up front
<emilbayes>
SeanTAllen: I think I'll start with error and change to a sum type later as I get better
<SeanTAllen>
makes sense
<emilbayes>
SeanTAllen: Yeah I understand
<SeanTAllen>
its a good place to start
<emilbayes>
SeanTAllen: Thanks for being so helpful :)
<SeanTAllen>
you're welcome.
<emilbayes>
Yesterday jemc proposed `A: Seq[U8] iso = String iso` as a "byte buffer" for some crypto I'm working on, but I can't seem to convert A to a cpointer so I can pass if off to my C function. Am I restricted to using String explicitly, or can I retain the more general generic of Seq[U8]?
<emilbayes>
So I'm not sure the default arguments of String work either
pduncan has joined #ponylang
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
pduncan has quit [Ping timeout: 258 seconds]
plietar has quit [Remote host closed the connection]
plietar has joined #ponylang
plietar has quit [Remote host closed the connection]
endformationage has joined #ponylang
plietar has joined #ponylang
nyarum has joined #ponylang
plietar has quit [Ping timeout: 240 seconds]
<emilbayes>
I can't quite figure out how to have an Array[U8] or String that has the ref capability, so they can be passed into a method, the method modify them, and then print them afterwards. Both Array and String default to val and that trips me up
Praetonus has joined #ponylang
plietar has joined #ponylang
<emilbayes>
Ah so I get it now, I cant lift the capability of a immutable reference to a mutable one. Also, only string is val by default
<Candle>
SeanTAllen: Mostly concerned with it being hard to comprehend; that was intended as a testcase for the end result. If it was all in one function then it'll be almost incomprehensible.
<Candle>
SeanTAllen: Thanks for the edits; lookthin through them now.
<Candle>
looking*
<Candle>
(I'm sure I tried something similar you the edits you made! Oh well...)
nyarum has quit [Remote host closed the connection]
nyarum has joined #ponylang
nyarum has quit [Remote host closed the connection]
nyarum has joined #ponylang
TheLemonMan has joined #ponylang
plietar has quit [Remote host closed the connection]
plietar has joined #ponylang
plietar has quit [Ping timeout: 260 seconds]
plietar has joined #ponylang
nyarum has quit [Remote host closed the connection]