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
Praetonus has quit [Quit: Leaving]
amclain has quit [Quit: Leaving]
SimonJF has quit [Remote host closed the connection]
jemc has quit [Ping timeout: 240 seconds]
autodidaddict has joined #ponylang
<autodidaddict> if I have a string and I want to remove whitespace from it but then also parse it with + and - in it into an I8, what's the best way to go about this?
<autodidaddict> so I could have "+3" or "+ 1" or " -9"
<autodidaddict> Rust lets me do 'mystring.parse::<i8>.unwrap()' turbofish
<autodidaddict> and that parse actually handles the + and -
<autodidaddict> oops, left some parens off that Rust code
<autodidaddict> I was able to brute force it by replacing whitespace and + and - .. but it feels like there should be a cleaner way than that
jemc has joined #ponylang
jemc has quit [Client Quit]
autodidaddict has quit [Ping timeout: 260 seconds]
jemc has joined #ponylang
jemc has quit [Ping timeout: 255 seconds]
papey has joined #ponylang
vaninwagen has joined #ponylang
papey has quit [Quit: WeeChat 1.9]
papey_lap has joined #ponylang
papey_lap has quit [Client Quit]
papey_lap has joined #ponylang
vaninwagen has quit [Ping timeout: 276 seconds]
papey_lap has quit [Read error: Connection reset by peer]
papey_lap has joined #ponylang
Matthias247 has joined #ponylang
papey_lap has quit [Read error: Connection reset by peer]
papey_la1 has joined #ponylang
Candle has quit [Ping timeout: 255 seconds]
Candle has joined #ponylang
papey_la1 is now known as papey
papey has quit [Ping timeout: 268 seconds]
papey has joined #ponylang
_whitelogger has joined #ponylang
papey has quit [Ping timeout: 260 seconds]
papey has joined #ponylang
_andre has joined #ponylang
autodidaddict has joined #ponylang
deep-book-gk_ has joined #ponylang
deep-book-gk_ has left #ponylang [#ponylang]
jemc has joined #ponylang
papey_lap has joined #ponylang
papey has quit [Ping timeout: 258 seconds]
<shepheb> I will never get "there can be only one" out of my head every time I type iso.
<shepheb> (that's a feature, not a bug)
<autodidaddict> I firmly believe we should be able to use `highlander` as a refcap alias for iso
<shepheb> in related news, I'm glad the #write RFC is coming along. also seems odd that #read predates it by many months.
<shepheb> jemc: thanks for fixing that crash.
<jemc> shepheb: no problem - thanks for reporting
<shepheb> interesting quirk; maybe there's a way to do it I can't see.
<shepheb> I've got a field with type Foo iso | None
<shepheb> and I want to read a field off it in a box-receiver function.
<shepheb> originally I was doing try (foo as Foo iso).etc() else defaultValue end
<shepheb> but now that "violates capabilities" in a way that isn't clear to me.
<shepheb> so I swapped it for a match foo = None | None => defaultValue; | let f: Foo iso => f.etc(); foo = consume f; end
<shepheb> but that sets foo, so it can't be on a box receiver.
<shepheb> it's not a problem to change it to ref, but this seems like it should be avoidable somehow.
<jemc> the issue is that `box->iso` == `tag`
<jemc> you've got to use a ref-receiver function (`ref->iso` == `iso`)
<shepheb> struggling to wrap my head around that, but I suppose it makes sense.
<jemc> it's telling you that it "violates capabilities" because it sees `{your Foo tag reference} as Foo iso`, which is a match that would pass at runtime (the right type id), but would violate capabilities
<shepheb> and in fact, changing to a ref receiver makes the (foo as Foo iso)... version work.
<jemc> autodidaddict: honestly, I'm surprised to hear that rust parses "+ 1" as a valid I8
<autodidaddict> jemc: I was shocked too. I was pairing when I wrote that Rust code and both of us said out loud "that can't possibly work"
<autodidaddict> it parses " - 12 " too
<autodidaddict> huh. I'm running it in the playground and it doesn't parse.
<shepheb> had you already stripped whitespace?
<autodidaddict> I'm looking at the Rust code now and I can't figure out why it works ;)
endformationage has joined #ponylang
jemc has quit [Read error: Connection reset by peer]
endformationage has quit [Read error: Connection reset by peer]
endformationage has joined #ponylang
jemc has joined #ponylang
<autodidaddict> "I8 val is not a subtype of I32 val" shouldn't there be an implicit conversion to put an I8 in an I32 var?
Praetonus has joined #ponylang
<jemc> no, it's one of pony's design choices not to allow any implicit numeric conversions, with the opinion that they result in bugs
<jemc> however it's quite easy to explicitly convert - use `my_num.i32()`
<autodidaddict> Yeah I was just thinking that it's a slippery slope. If you allow one implicit (seemingly safe) conversion... where do you draw the line?
<jemc> yeah, I've grown to like the explicit conversion because it makes it very clear how much bitwidth you have at any given time
<autodidaddict> yep.. it's just a struggle for people who can switch between 3 languages in one day... It's very easy to forget what can and cannot happen implicitly
amclain has joined #ponylang
<autodidaddict> I typed "def" instead of "fun" and couldn't figure out for 20 minutes why my stuff wouldn't compile.
<jemc> heh
<jemc> you can remind yourself of that by just remembering that Pony is the most "fun" language to write in
<autodidaddict> Indeed
<autodidaddict> That'd make Go a "func-y" language ... And Rust .. hmm, can't make much out of "fn"
<jemc> most "def"
<autodidaddict> HAH
<autodidaddict> how does one gain access to the fold() method on a list? I've got an array of tuples and I want to fold ._2 as a sum.. but fold() isn't showing up as being on either my array or my iterator via array.values()
<autodidaddict> so, I have code that I want to look something like this:
<autodidaddict> let _sum: I64 .... _sum = _values.fold( { (sum:I64, x: EvaluatedTerm) => sum + x._2.i64() }, 0)
<autodidaddict> where values is Array[EvaluatedTerm] and EvaluatedTerm is my tuple, with _2 being an I32
<autodidaddict> brute force is I converted _sum to a var and am doing : _sum = _sum + element._2 in a loop
<autodidaddict> doing Iter[EvaluatedTerm](_values.values()).fold( ... ) seems to let me invoke fold, but then I get a 3-page spam of receiver type mismatch args ;)
<jemc> autodidaddict: `Array` actually doesn't have `fold` - `List` has it, but that's a distinct sequence type
<jemc> if you want to do `fold` operations on an `Array`, check out the `itertools` package
<autodidaddict> I found it... take a look at my msg from 12:25.
<autodidaddict> I can't quite figure out how to get Iter[T] to fold without generating 300 errors
<jemc> something like `Iter[EvaluatedTerm](_values.values()).fold[I64]({(sum:I64, x: EvaluatedTerm) => sum + x._2.i64() }, 0)` should theoretically do it
<jemc> unless you're hitting capability issues
<jemc> if you can paste your errors into a gist or pastebin I can take a closer look
<autodidaddict> that's the syntax I was using. Let me see what I can find
<jemc> ah, your lambda needs to show the `I64` as the return value :)
<jemc> so: `Iter[EvaluatedTerm](_values.values()).fold[I64]({(sum:I64, x: EvaluatedTerm): I64 => sum + x._2.i64() }, 0)`
<jemc> > method result None val is not a subtype of I64 val^
<jemc> that was the key piece of info for that error
<autodidaddict> weird. I put that in and now I've got errors in functions unrelated to this call... that didn't have errors before
<autodidaddict> ok, here's a strange one
<autodidaddict> doing `_sum = ....` results in all kinds of weird errors in nearby functions
<autodidaddict> if I replace it with let d:I64 = ... then it complains that I'm not trapping an error
<autodidaddict> so then I wrap it in a try/else/end ... and the parser thinks there's an unassigned constructor variable..even though I set it in the else clause
<autodidaddict> I've run into this a few times before.. there seems to be no way to convince the compiler I'm actually setting my field
<jemc> the define-field-inside-`try`-inside-constructor thing is a known limitation that we haven't fixed yet - the workaround is to perform te actual assignment outside the `try` block
<shepheb> _sum = try ... else ... end should work?
<jemc> yeah, that :)
<shepheb> I don't think the compiler groks it being set on both branches.
<jemc> it's a weird case because from the compiler's perspective, the `try` block could bail out to the `else` "at any time"
<autodidaddict> ok I'll try and rearrange
<jemc> I originally thought it would be a trivial fix, but introducing the fix caused other issues related to other "symbol status" changes
<jemc> so I haven't been able to get it working right just yet
<autodidaddict> I do that and it goes back to complaining about other adjacent functions that used to work
<autodidaddict> I don't understand why this would change a function from working to non-working.. the change seems orthogonal
<jemc> I don't know what you mean by "used to work", but the compiler has various "passes" that it goes through, and if it encounters errors in an early pass, you won't see the errors from the latest pass
<jemc> so that may explain what you're seeing
<autodidaddict> so, when I am using a var and summing in a loop, everything compiles.
<autodidaddict> when I sum with fold, a function called in a loop 2 lines up (that compiled in previous version) now reports receiver type mismatch problems
<autodidaddict> if I remove the _sum = ... line, the function it used to say had a receiver type problem now compiles
<jemc> if you gist/pastebin the errors, I can probably help
autodidaddict has quit [Quit: Page closed]
autodidaddict has joined #ponylang
<autodidaddict> remember I get none of these errors if my constructor doesn't have a "_sum = (fold)" line in it... and that line _doesnt_ call the function it's claiming has a problem
<jemc> ah, this is a case where the error message was improved in a PR that was merged yesterday: https://github.com/ponylang/ponyc/pull/2005
<jemc> your issue is that until you've defined all the fields in your constructor, the `this` reference is "incomplete" (some fields are undefined) - therefore it is treated as opaque (a `tag`)
<jemc> that's why you see an error about `Roll tag`
<jemc> with the error message improvement, you'd see the additional helpful message that "this might be possible if all fields were already defined"
<autodidaddict> so I can't invoke functions in my class to populate fields in my constructor because it doesn't know what "this" is?
<autodidaddict> seems like a bad catch 22 - I need to invoke functions on "this" in order to populate fields, but this is undefined because I haven't finished populating fields?
<jemc> you can only invoke `tag`-receiver functions
<jemc> so if your `_evaluate` function doesn't read or write any fields, you can make it `fun tag _evaluate`
<autodidaddict> it returns values
<autodidaddict> fun ref _evaluate(term: RollTerm box) : I32 => match term.value() | let t: Die box => _roll(t.mult().i32(), t.sides().i32()) | let t: I8 box => t.i32() else 0 end
<autodidaddict> it requires ref because the random number generator I'm using needs it
Candle has quit [Ping timeout: 246 seconds]
<jemc> if that's the only need for accessing fields, you could pass in the RNG as another argument to `_evaluate` (and to `_roll`) - that way both functions could be `fun tag` and not access any fields
<autodidaddict> the RNG doesn't access any fields
<jemc> otherwise, you could give `_sum` an initial value of `0` or something before entering the `_evaluate` method
<autodidaddict> yeah, that works..but that makes sum a var instead of a let
<autodidaddict> my code compiles like a charm with var
<jemc> autodidaddict: you said you needed `fun ref` so you could access your RNG, which I was assuming was a field
<jemc> that's what I meant by "access fields"
<autodidaddict> fun ref _i32_between(low: I32, high: I32): I32 => let r = (_rand.int((high.u64() + 1) - low.u64()) and 0x0000FFFF).i32() let value = r + low value
<autodidaddict> ^^ this function doesn't compile without ref
<autodidaddict> and it access no fields
<jemc> isn't `_rand` a field?
<autodidaddict> wait, damn, nevermind
<jemc> if you gist/pastebin your whole code I may be able to help with finding an idiomatic approach
<autodidaddict> apparently I iz too dumbz
<autodidaddict> so, I now have no field access in the subordinate functions
<autodidaddict> still same error
<autodidaddict> switch to var with an initial value, it works
<autodidaddict> I'm instantiating the code in that gist with "let roller = Roller("3d6+5",env.out) let result = roller.roll()"
<jemc> > still same error
<jemc> you need to mark those functions as being `fun tag` - they don't access any fields, and that's how you annotate that
<autodidaddict> the code in my gist works
<jemc> sure, with `var _sum`, which is also fine
<autodidaddict> I'm after cleanliness and idiomatic. I'll try and fun tag and see if I can get it working with let
<jemc> if you're passing in the `rand: Rand`, and not accessing any state in those subordinate functions, idiomatically it would make sense for those stateless functions to be on a primitive instead
<autodidaddict> yeah I can refactor after I get it working
<autodidaddict> that works
<autodidaddict> I think we definitely need to amp that fact in the docs.. the idea that your constructor can't call non-tag functions is pretty huge
<autodidaddict> at least, not until all fields are initialized
<jemc> yeah, it comes from the constraint that Pony won't allow you to ever pass around an object whose fields are uninitialized
<jemc> except as a tag, which is safe because that's an opaque reference
<autodidaddict> it makes total sense now
<autodidaddict> but I definitely wasn't thinking that way looking at all the failures I was getting
<autodidaddict> sweet, got it working now with a primitive
<autodidaddict> is there a good example of a public library I can look at as an example for layout/testing, etc?
<jemc> I like to think that my public libraries are good examples of code organization :)
<jemc> they have the distinction from the standard library of keeping the tests separate from the library code, which I prefer
<autodidaddict> :)
<autodidaddict> that's why I asked. I like separate test areas
<autodidaddict> what's the significance of the _lib.pony and the @ sign ?
<jemc> the `@` symbol, anywhere it appears, refers to FFI stuff (calling C functions from a shared library)
<autodidaddict> ah, ok
<autodidaddict> I've been skipping past the FFI stuff as I learn the core Pony syntax
<jemc> yeah
<jemc> so for general code organziation, these guidelines from the standard library are good (I helped write them): https://github.com/ponylang/ponyc/blob/master/STYLE_GUIDE.md#naming
<jemc> my main departure from those is having tests in a separate directory
samuell has joined #ponylang
<samuell> How do I loop over characters of a string?
<samuell> If I do "for c in line" ... and env.out.print(c) I get "cannot infer type of c"
<samuell> Ok ... for c in line.values() ... and env.out.print(c.string()) seems to cut it ...
<samuell> eh, not completely, but ...
<samuell> (.values() obviously just gets unsigned 8 bit integers, right ...)
<jemc> samuell: if you want to iterate over codepoints rather than bytes, use `line.runes()` instead of `line.values()`
<jemc> where `runes` iterates over 32-bit codepoints, instead of 8-bit bytes
<samuell> jemc, Thx, will try!
Candle has joined #ponylang
<autodidaddict> how does one print debug statements inside a test?
<autodidaddict> e.g. how do I get access to env.out
<jemc> autodidaddict: there's an aptly named `debug` package for this
<autodidaddict> is there something special I need to do in order to get that to show up during a test run?
<autodidaddict> got it. arg
Candle has quit [Ping timeout: 258 seconds]
Candle has joined #ponylang
<autodidaddict> after all this I get into testing and find that my match iterator has a bug
<autodidaddict> maybe I should just take up basket weaving
<autodidaddict> works fine for terms like "3d6+12" or "2d10+5" but anything longer than that, it's skipping terms
<jemc> note that both `has_next` and `next` will be called on each iteration
<jemc> sounds like you may be skipping ahead on both methods?
<autodidaddict> nope I only skip on next
<jemc> k
<autodidaddict> Let me get this in github and I'll send you a link. I feel like this is one of those things where I'm so worried about the syntax I'm missing a big facepalm moment
<jemc> autodidaddict: have you tried without the `+ 1` on the offset calculation in MatchIterator.next?
<autodidaddict> yes. it creates more matches than I expect
<autodidaddict> other variants have actually hung the entire program
<autodidaddict> let me add a failing test
<jemc> also, I'm not sure that you should be adding the `offset` to the `end_pos` - I was assuming the `end_pos` was the total offset in the original string
<jemc> though I haven't looked it up in the API
<autodidaddict> yeah, I tried it without and setting absolute positions... it hangs the test runner ;)
<autodidaddict> ok, added a failing test
<autodidaddict> I'm flailing on this one. Can't figure out why this thing is off
<jemc> your test passes for me if I do `_offset = m.end_pos() + 1`
<samuell> Now wondering how to convert a fraction of ints to a float ...
<samuell> var frac: F32 = someint / someint
<autodidaddict> jemc: omg. I tried so many variations with 300 debug statements... I can't believe that one slipped by
* samuell trying to read up in docs ...
<autodidaddict> if you need me I'll be sulking in the dunce corner
samuell has quit [Quit: Hejdå]
<jemc> samuell: so, for all binary operations on numeric types, the arguments and return value all have to be the same type
<jemc> with that in mind, you want `some_int.f32() / other_int.f32()`
samuell has joined #ponylang
<samuell> jemc, I c ... but get "right side must be a subtype of left side"
<samuell> ... or "Cannot look up member f32 on a literal"
papey_lap has quit [Quit: WeeChat 1.9]
<jemc> samuell: I thought you were working with named references, not literals
<jemc> for literals you can just do `let frac: F32 = 1 / 9` and the compiler will implicitly infer it as two `F32` literals
<samuell> Ah, yes, I was ... just realized the difference ...
<jemc> or if you want/need to be explicit, you can do `let frac: F32 = F32(1) / F32(9)`
<samuell> My own code is not gisteable just yet (parsing a file)
<samuell> Ah
<jemc> yeah, so an integer-looking numeric literal can be of any numeric type - it has to be inferred by context by the compiler
<jemc> the `F32(1)` syntax is actually `F32.create(1)`, where that constructor takes an `F32` argument, and the type is inferred by that
<jemc> for an existing named reference of a numeric type, the type is already definite, so you have to convert it to what you're working with, with `some_int.f32()`
<samuell> IC
<samuell> Ok, I got the some_val.f32() to work in the playground now ... so getting closer :)
<samuell> Ah, yes ... had some other typos that confused me first, works now. Many thanks!
_andre has quit [Quit: leaving]
autodidaddict has quit [Ping timeout: 260 seconds]
Matthias247 has quit [Read error: Connection reset by peer]
samuell has quit [Quit: Hejdå]
autodidaddict has joined #ponylang
endformationage has quit [Quit: WeeChat 1.7]