RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.24.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
hightower4 has quit [Ping timeout: 260 seconds]
<FromGitter> <marksiemers> Can you specify a commit hash? `966449d36c6390c48ae3dd4c5160138ad9734f89`
<FromGitter> <marksiemers> That would be the latest for baked_file_system
<FromGitter> <marksiemers> Or ask @straight-shoota for a new release
hightower4 has joined #crystal-lang
<FromGitter> <marksiemers> Try specifying the commit hash
<FromGitter> <bew> hightower4 does it do that with a new project or n existing project?
<FromGitter> <bew> Maybe you have a shards.lock file
OceannBoy has joined #crystal-lang
<hightower4> bew I thought about it, I deleted the entry from shard.lock and also deleted the whole directory in lib/ and .shards/
<hightower4> Didn't help
<hightower4> I'll try with commit hash as last resort
<hightower4> The message is the same ("(0.9.5 at master)") but it did take the commit I specified
<hightower4> So yeah, that'll do for now, thanks for the discussion
<FromGitter> <marksiemers> Just one more thought based on the shards.lock, after switching to master, do a `shards update`
<FromGitter> <marksiemers> there may be a system-wide cache of that shard or something
<hightower4> I did that, let me try again with everything cleaned first
<hightower4> marksiemers: that worked, thanks!
qard has quit [Quit: qard]
<crystal-gh> [crystal] ysbaddaden pushed 1 new commit to master: https://git.io/vNxKI
<crystal-gh> crystal/master 47b45da Julien Portalier: Fix: uninitialized sa_mask value in sigfault ext
OceannBoy has quit [Ping timeout: 264 seconds]
OceannBoy has joined #crystal-lang
<travis-ci> crystal-lang/crystal#47b45da (master - Fix: uninitialized sa_mask value in sigfault ext): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/337081819
Yxhuvud has quit [Remote host closed the connection]
<hightower4> If I want to do e.g. macro mymacro(decl) and call it as mymacro name : Type, how do I access "name" and "Type" within the macro?
<hightower4> decl.var and decl.type it seems
relyks has quit [Quit: relyks]
<FromGitter> <bew> Yes, this is documented here: https://crystal-lang.org/api/0.24.1/Crystal/Macros/TypeDeclaration.html
<FromGitter> <Svenskunganka> Hey fellas, I have a question about Macros. How do I embed the contents of a block as a method body? For learning purposes I am building a filetype library that matches using magic numbers (https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files). I want to define a macro that allows people to add new matchers. Here's an example: ⏎ ⏎ *filetype.cr* ⏎ ⏎ ```code paste, see
asterite has quit [Ping timeout: 265 seconds]
jhass has quit [Ping timeout: 276 seconds]
DeBot has joined #crystal-lang
asterite has joined #crystal-lang
jhass has joined #crystal-lang
<FromGitter> <Svenskunganka> For example, doing this: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a7669bd4a6b0dd32b86e08a]
<FromGitter> <marksiemers> I think you want to capture the block in the `def is_ ...`
<FromGitter> <marksiemers> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a766ab098927d5745749e49]
<FromGitter> <marksiemers> Actually, if you use yield, you may not need the `&block` at all.
<FromGitter> <Svenskunganka> Wouldn't the API be like this then: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Which seems odd [https://gitter.im/crystal-lang/crystal?at=5a766b39ac509d207db616fc]
<FromGitter> <Svenskunganka> In the previous error that I got, I want to embed line 3 of the error, but not line 2 & 1 (`do |slice|` and `end`)
<FromGitter> <Svenskunganka> Oh I can use `block.body` in the macro
<FromGitter> <Svenskunganka> This works: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a766c4c98927d574574a4c6]
<FromGitter> <Svenskunganka> Now for making sure the macro defines the method inside the `Filetype` module and not in the scope it was called from...
<FromGitter> <marksiemers> If you run into issues, you could try an approach similar to this: https://github.com/amberframework/amber/blob/master/src/amber/dsl/server.cr#L2
<FromGitter> <marksiemers> But your's looks good, assuming no scoping issues like you mentioned
<FromGitter> <Svenskunganka> That's a handy reference, thank you!
OceannBoy has quit [Remote host closed the connection]
faustinoaq has joined #crystal-lang
faustinoaq has quit [Client Quit]
faustinoaq has joined #crystal-lang
jnyw has quit [Ping timeout: 248 seconds]
faustinoaq has quit [Ping timeout: 256 seconds]
qard has joined #crystal-lang
kkkkkk has joined #crystal-lang
kkkkkk has quit [Client Quit]
<FromGitter> <bew> @Svenskunganka for the coping issue you can do https://carc.in/#/r/3igc
<FromGitter> <bew> it feels weird that the second test work though
<FromGitter> <bew> Got my answer: https://carc.in/#/r/3igg it won't work if the new scope has a `FileType` module too
<FromGitter> <Svenskunganka> Hmm that will be a problem
<FromGitter> <Svenskunganka> Is there a way to get a reference to the `module` a macro is defined in?
<FromGitter> <bew> Huh no don't think so
cremes has quit [Quit: cremes]
faustinoaq has joined #crystal-lang
qard has quit [Quit: qard]
jnyw has joined #crystal-lang
brycek_ has joined #crystal-lang
rohitpaulk has joined #crystal-lang
foxbot has joined #crystal-lang
brycek has quit [*.net *.split]
foxbot_ has quit [*.net *.split]
crse[m] has quit [*.net *.split]
juni0r has quit [*.net *.split]
brycek_ is now known as brycek
willamin has quit [Ping timeout: 240 seconds]
swav has quit [Ping timeout: 240 seconds]
willamin has joined #crystal-lang
swav has joined #crystal-lang
crse[m] has joined #crystal-lang
juni0r has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
sz0 has joined #crystal-lang
hightower3 has joined #crystal-lang
hightower3 has quit [Ping timeout: 248 seconds]
hightower4 has quit [Ping timeout: 256 seconds]
DTZUZO has quit [Ping timeout: 268 seconds]
hightower4 has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
DTZUZO has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
Yxhuvud has joined #crystal-lang
jnyw has quit [Quit: WeeChat 2.0.1]
sz0 has quit [Quit: Connection closed for inactivity]
desdeux[m] has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
hightower3 has joined #crystal-lang
hightower2 has quit [Ping timeout: 240 seconds]
rohitpaulk has quit [Ping timeout: 256 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
cremes has joined #crystal-lang
coderobe has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
<FromGitter> <aisrael> Is there a way for a method (or overloaded methods) to behave differently whether the given block expects a parameter or not? That is, to do different things depending on block arity?
<RX14> @aisrael no
<RX14> you can omit block arguments to methods, so it doesn't really make sense to have that behaviour
<RX14> i'd personally be open to changing it
p0p0pr37 has quit [Remote host closed the connection]
<FromGitter> <aisrael> Yeah I realize in my calling method I can just `yield x` (or `.call(x)`) and have the block ignore the yielded value. Am just thinking e.g. if I wanted the behavior of `Spec.run_before_each_hooks` to pass in something if the receiving block expects something, then I can’t just override/overload it in my code. I’d have to submit a PR.
<RX14> well you can always monkey patch
<RX14> but yes a PR is preferred if it's possible
<FromGitter> <aisrael> That’s the thing—I can’t monkey patch without having to rewrite `Spec.run_before_each_hooks` entirely (sure, it’s just one line but…). Submitting a PR, well, uhm, frankly am not confident about doing that yet—what if no one else thinks what I’m trying to do is useful?
<RX14> just call previous_def?
<RX14> previous_def { yield "foo" } ?
<RX14> plus, what exactly are you trying to do?
<FromGitter> <aisrael> (I’l try that, but from my experiments with blocks with 0 or 1 arity I can’t get it to work side by side with the original method). I guess the real question is: is there a way for a spec’s before/after block to know the context (`NestedContext`) of the corresponding spec?
<FromGitter> <aisrael> (Am trying to automate generating Hi8 cassette names from the `describe` and `it should` descriptions, just like `vcr`)
<RX14> why do you need to know that?
<RX14> ah ok thats an extremely valid usecase
<RX14> yeah make an issue or PR for that
<RX14> i'm sure everyone will agree your usecase is valid
<FromGitter> <aisrael> I actually have something that can do that now overriding `Spec::RootContext.describe`. But I figured a `before` (or rather an `around` block, if we had it) would be cleaner.
<RX14> yeah
coderobe has joined #crystal-lang
<FromGitter> <aisrael> Thanks! First, I’ll see about writing an `around` hook. PR that. Next, I’ll see about passing in the `NestedContext` in a second PR? Just to keep the PRs “clean"
<RX14> im not sure around can work
<RX14> hmm
<FromGitter> <aisrael> oh… yeah I haven’t really given that much thought, just assumed since `before`/`after` are there that no one’s just gotten around to an `around`
<RX14> yeah before/after are easy
<RX14> you just call a block before and a block after
<RX14> with around you have to pass the whole spec into the block
<RX14> and the block can do stuff like not call the spec at all
<RX14> it's a lot more side effects and a lot more decision
<RX14> and a lot more power
<FromGitter> <aisrael> I understand. That’s exactly how RSpec `around` hooks behave, too, right? OTOH RSpec `around` passes in an `example`, and the block is expected to call `example.run`. So, it’s really exposing a lot of the innards.
<FromGitter> <aisrael> Anyway—it’s getting late (here) and really, a lot of this is still beyond my "5+ years experience with Crystal+Amber” so I’ll sleep on it and maybe the community will have better ideas :)
<vegai> hmm, the crystal rpm package doesn't seem to be ok
<vegai> doesn't install anything in path
<vegai> then again, crystal & shards are in /usr/lib/crystal/bin/
<RX14> are you sure vegai?
<RX14> where is this rpm from?
<vegai> well this is odd
<vegai> rpm -ql crystal does show /usr/bin/crystal but I don't have that
<RX14> lol
<RX14> reinstall packge I guess
<vegai> reinstalling
<vegai> yes
<vegai> warning: file /usr/bin/shards: remove failed: No such file or directory
<vegai> warning: file /usr/bin/crystal: remove failed: No such file or directory
<vegai> guess I've done something stupid again
<RX14> probably
<RX14> happens to me all the timwe
<vegai> running history doesn't at least show me doing rm against them
<vegai> perhaps the stupid thing I've done is using Linux :P
<RX14> yeah
<RX14> should have used plan 9
<RX14> i should port crystal to plan 9
<RX14> would be fun
<vegai> more fun that porting to Windows, I'm sure
<vegai> well ok, I'm not so sure about that
<RX14> definitely more fun than porting to windows
<RX14> which i've given up on until people stop bikeshedding about File::Info
<RX14> of course Go works on plan9
<RX14> being written by rob pike and all
<vegai> I saw a python port at some point also
<vegai> that was probably a bit more difficult to pull off
rohitpaulk has quit [Ping timeout: 256 seconds]
<FromGitter> <asterite> before/after/around don't make sense for the current spec because one usually use them to setup instance vars so they are shared between tests... but spec doesn't use classes, so there's no way to access data created in a before block
<FromGitter> <asterite> As I said it many times now, the current `spec` is probably a mistake, something like TestUnit with classes and inheritance would have better better and more flexible
<FromGitter> <sdogruyol> @asterite aside from what you mentioned I like spec actually
instancer67 has joined #crystal-lang
<RX14> @asterite I disagree
<RX14> @asterite, @aisrael just provided a perfectly sane usecase for `before`/`after` which is resetting VCR state
<RX14> around I don't think we should have
<RX14> but I really really enjoy the current spec suite
<RX14> I really do
pta2002 has left #crystal-lang ["WeeChat 1.9.1"]
cremes has quit [Quit: cremes]
<instancer67> is there a way to get the input from "gets" before the enter key has been pressed?
<instancer67> or do I have to check for every key myself to do this?
<oprypin> instancer67, there's no way
<RX14> you'll find there's 2 things going on here instancer67
<RX14> first, gets always waits for a neline
<RX14> you'll probably want STDIN.read_char or similar
<instancer67> hm ok so I need to do myself ok
<RX14> second, terminals do line buffering so you won't get that inout anyway
<RX14> so you need to use STDIN.raw
<RX14> which disables the line buffering on terminals
<RX14> instancer67, https://crystal-lang.org/api/0.24.1/IO/FileDescriptor.html#raw%28%26block%29-instance-method
<RX14> and look at those examples too
<instancer67> ah ok thanks
<RX14> hope that helps
faustinoaq has quit [Ping timeout: 256 seconds]
<instancer67> in the example, it creates a new string from the buffer. But I can also just do "buffer[0].chr" whats better?
<RX14> uhh
<oprypin> well if you dont want to get garbage in, then probably new string from buffer
<RX14> ignore that bit of the example instancer67
<RX14> just use read_char
<RX14> it's 200% safer
<instancer67> so you mean io.read_char(buffer) instead of io.read(buffer) right?
<RX14> no
<RX14> read the docs
<instancer67> wow! "STDIN.raw do |io| ; key = io.read_char ; end" works good. Why are they not just using this in the example? weird
<RX14> because the example sucks
<instancer67> aah.. i will do a pull request to change it
coderobe has left #crystal-lang [#crystal-lang]
alex`` has quit [Quit: WeeChat 2.0.1]
<instancer67> RX14: this is weird. when I run the 2048.cr example and replace these 4 lines with "input = io.read_char.to_s" in read_keypress then when I press the arrow keys, it acts like i pressed CTRL+C
<RX14> Yes
<RX14> You're reading a single char
<RX14> Look at the length of some of the strings
<instancer67> aah...
<RX14> They're 3 chars long
<RX14> Sigh
<RX14> Arrow keys being multiple chars breaks everything
<RX14> Someone should just make a shard that handles this
<RX14> The thing is you need to read from one to 3 chars
<RX14> But no more and no less
<RX14> And that code snippet is the only way to achieve that
<RX14> Even that snippet makes the assumption that the read call will return one key press only
<RX14> Even that snippet makes the assumption that the read call will return one key press only
faustinoaq has joined #crystal-lang
alex`` has joined #crystal-lang
Groogy has quit [Quit: WeeChat 2.0.1]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
<instancer67> damn this key input is laggy
<RX14> instancer67, code?
<RX14> it's probably because of the way you implemented it :(
sz0 has joined #crystal-lang
<instancer67> oh its probably because i used system("clear")
faustinoaq has quit [Ping timeout: 248 seconds]
<FromGitter> <bew> Why did you used that?
rohitpaulk has joined #crystal-lang
cremes has joined #crystal-lang
faustinoaq has joined #crystal-lang
<FromGitter> <bew> What after you trying to do actually?
<FromGitter> <codenoid> night
<instancer67> i just used this for now because i wanted to test it. Im using an ascii escape sequence thingy now to clear screen
hightower2 has joined #crystal-lang
hightower4 has quit [Ping timeout: 260 seconds]
moei has joined #crystal-lang
instancer67 has quit [Ping timeout: 260 seconds]
<FromGitter> <sdogruyol> so we removed `JSON::Type`?
<oprypin> y tho
<FromGitter> <sdogruyol> ugh, this broke kemal :P
<RX14> oprypin, there's plenty discussion in the PR
<RX14> the reason why is because it makes JSON::Any recusrsive properly
<RX14> you will get an Array(JSON::Any) and a Hash(String, JSON::Any) from JSON::Any
<RX14> and there's nopr ecursive aliases
<oprypin> that's what it is, not why
<RX14> why? because thats what people expect
<RX14> read the PR
<RX14> it's going to be far more informative then me trying to recall everything off the top of my head
<oprypin> yep
cremes has quit [Quit: cremes]
cremes has joined #crystal-lang
cremes has quit [Client Quit]
rohitpaulk has quit [Remote host closed the connection]
hightower2 has quit [Ping timeout: 276 seconds]
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
Ven`` has joined #crystal-lang
danielpclark has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
cremes has joined #crystal-lang
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
return0__ has joined #crystal-lang
return0e has quit [Ping timeout: 264 seconds]
return0__ has quit [Ping timeout: 240 seconds]
return0e has joined #crystal-lang
cremes has quit [Quit: cremes]
A124 has quit [Quit: '']
A124 has joined #crystal-lang
<hightower3> Hey folks, are there any problems with adding JSON::Any to the list of TYPES in crystal-db/src/db.cr ? I did that and it allowed me to read and write JSON to postgres database directly (field type jsonb).
<hightower3> Jsonb appears to automatically be converted to JSON::Any in Crystal and without the above, the error shows up that JSON::Any is not in the list of TYPES so one can't read out the values from the db
alex`` has quit [Quit: WeeChat 2.0.1]
jokke has joined #crystal-lang
f1refly has joined #crystal-lang
<FromGitter> <internethostage> Good day guys! ⏎ Newbie question alert ⏎ ⏎ My current goal is to open a jpg file, change random bytes inside, and write a new file. ⏎ To do that, my first attempt has been to try read each line of the file, and then write the output (without changes yet), however this isn't working, I suppose from changing the files content to String... ... [https://git
<FromGitter> ... ter.im/crystal-lang/crystal?at=5a7773f57dcd63481f192035]
<FromGitter> <internethostage> any suggestions on how to approach this? :)
<RX14> you can't store binary data in strings in crystal
<RX14> there's multiple ways to correctly copy a binary file
<RX14> for simply copying a file i'd use IO.copy
<FromGitter> <internethostage> I was thinking IO.each_byte
<RX14> since you eventually want to modify it that depends if you want to parse it or not
<RX14> IO#each_byte would work
<RX14> then IO#write_byte into the new file
<FromGitter> <internethostage> i see
<FromGitter> <internethostage> so I open the file, say ⏎ `file = File.read("myfile")` ⏎ then I go through the output with `file.each_byte ` ?
<RX14> no
<RX14> File.read gets you a string
<FromGitter> <internethostage> right
<RX14> you want File.open
<FromGitter> <internethostage> got it, thanks!
<RX14> File.open("input.png") do |file|
cremes has joined #crystal-lang
imdumb has joined #crystal-lang
<imdumb> how do I remove the last character of a string? i feel really dumb
<RX14> or
<RX14> str[0..-2]
<RX14> or
<RX14> str[0, str.size - 2]
<imdumb> o boi.. what is going on with my brain.. i dont understand
pta2002 has joined #crystal-lang
imdumb has quit [Quit: Page closed]
hightower2 has joined #crystal-lang
pta2002 has left #crystal-lang ["WeeChat 1.9.1"]
hightower2 has quit [Ping timeout: 256 seconds]
<FromGitter> <asterite> RX14 for resetting VCR state we have the global Spec.before_each. Webmock uses it to reset webmocks. That's why I think that use case fits more a "global" before hook rather than ran in a particular set of specs.
<FromGitter> <asterite> So before hooks are not really needed for this use case...
<RX14> isn't that what was being talked about?
<FromGitter> <asterite> Ah, sorry, I didn't read the whole conversation 😊
<RX14> I was certain we were talking about the global Spec.before_each
<RX14> we don't *have* anything else
<RX14> oh
<RX14> yes
<RX14> we were talking about monkey-patching Spec.run_before_each_hooks to pass the Context to the Spec.before_each hook
<RX14> I think
<RX14> or just the spec name
<RX14> the spec suite is weird
<RX14> like
<RX14> in implementation
<RX14> externally I really like it
<RX14> Spec's impl I think suffers from being "too OO"
<RX14> it's so simple there should just be a single spec runner object which maintains a stack of records
<RX14> instead of having this Context object with parents
<RX14> but then they're also in a stack too
<RX14> so you have to maintain each Context's parent relationship and the stack?
<RX14> well whatever, it works
<FromGitter> <ezrast> Is there a way to call `#class` with an implicit receiver? `self.class` fails if used in the constructor before `self` exists.
<RX14> hmm
<RX14> looks like you're out of luck
<RX14> I think `self` usage should be allowed in the ctor if it's only used to call class methods
<RX14> wait no
<RX14> nope
<RX14> there's no way @ezrast
<RX14> that kinda sucks
<FromGitter> <ezrast> I can cheese it with ⏎ ⏎ ```@[Primitive(:class)] ⏎ def __class ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5a7783867dcd63481f196a92]
<FromGitter> <ezrast> but I suspect that's not behavior I should be relying on
<RX14> well
<RX14> how about
<RX14> `def _class; self.class; end`
<RX14> then just call that
<FromGitter> <ezrast> won't that have the same problem?
<RX14> won't what you wrote have the same problem?
<RX14> primitive or not it's still a method
<RX14> and can't be called before all ivars are initialized
<FromGitter> <ezrast> there's nothing wrong with the method, I just can't call it directly because `class` is a reserved word
<RX14> you can't call methods on the class from the ctor before all ivars are set
<Papierkorb> Have you tried `{{ @type }}` ?
<RX14> so how can you call __class?
<RX14> @ezrast works for me: https://carc.in/#/r/3ik7
<RX14> but then do does this...: https://carc.in/#/r/3ik9
<RX14> hmm
<FromGitter> <ezrast> huh, maybe I'm not understanding the error I'm getting
<FromGitter> <ezrast> let me try to reduce
<RX14> just send the error
<RX14> yeah but there should be a way to call class without macros Papierkorb
<FromGitter> <ezrast> I'm getting `Error: 'self' was used before initializing instance variable '@name', rendering it nilable`
<Papierkorb> "Should be" maybe, but that's a non-hacky solution that works right now
<RX14> yeah
<RX14> why can I never get that error to appear
<Papierkorb> And can be improved by .class later on
<RX14> @ezrast this should error, you agree: https://carc.in/#/r/3iki
<RX14> @ezrast and this does not error: https://carc.in/#/r/3ikj
<RX14> what's te problem?
<FromGitter> <ezrast> Now I'm not sure since I don't know why your second example does not error
<RX14> nor do I
<RX14> actually
<RX14> the compiler keeps track of which local methods touch instance variables
Ven`` has joined #crystal-lang
<FromGitter> <ezrast> Gah, it was a typo in my code. I was calling a different method than `class` in one spot. Sorry sorry.
<RX14> lol
Ven`` has quit [Ping timeout: 256 seconds]
alex`` has joined #crystal-lang
thews has quit [Read error: Connection reset by peer]
thews has joined #crystal-lang
thews has joined #crystal-lang
thews has quit [Changing host]
alex`` has quit [Quit: WeeChat 2.0.1]