ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Crystal 0.23.1 | Fund Crystal's development: | GH: | Docs: | API: | Gitter:
hightower3 has quit [Ping timeout: 255 seconds]
<FromGitter> <elorest> <oprypin> How would I save the binary value for a char and add that to an io which I would convert back to a string at the end?
<FromGitter> <elorest> Currently it’s storing the binary values of the numbers it seems. It’s there some sort of way to store a single byte as a value?
<FromGitter> <elorest> In c++ and java I can cast and unsigned integer to a byte.
Guest24175 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <johnjansen> a char is 2 bytes
<FromGitter> <elorest> most chars are only one byte. in utf8 they can be up to 4 though.
<FromGitter> <elorest>
<FromGitter> <johnjansen> what was i thinking
<FromGitter> <johnjansen> @elorest what exactly are you trying to do
<FromGitter> <elorest> I’m trying to write base91.
<FromGitter> <elorest>
<FromGitter> <johnjansen> ohhhhh
<FromGitter> <johnjansen> might have known
<FromGitter> <elorest> It seems like mine should work but it’s wrong somehow.
greengriminal has quit [Quit: This computer has gone to sleep]
<FromGitter> <johnjansen> did you see this btw
fryguy9 has joined #crystal-lang
fryguy9 has quit [Client Quit]
<FromGitter> <elorest> Yeah. I’m not really sure why they treat the string differently though… it makes the ruby implementation look harder to read than the java one for some reason.
<FromGitter> <elorest> Not very dry.
<FromGitter> <elorest> I still spend about 30 minutes trying to get the ruby version to compile in crystal. Got some weird errors and eventually just decided look at the working java one and go from there.
<FromGitter> <elorest> The ruby one also calls a variable that is never defined.
<FromGitter> <johnjansen> typical ruby
<FromGitter> <elorest> Idk I’ve been writing ruby for 12 years and typically ruby shouldn’t follow this pattern.
<FromGitter> <elorest> Probably is I’ve worked with bytes in c and java 10+ years ago but never really in ruby… so now trying to do it in crystal is confusing because bytes are just uint8 instead of byte and I’m not quite sure how to differentiate them.
<FromGitter> <johnjansen> since ive been in the land of crystal ive discovered a plethora of code that returns multiple types, relies on the inherent stringiness in ruby and many other sins … im kind of disappointed
<FromGitter> <elorest> Sure in regard to bytes definitely… the way it pretty much does the same thing twice for 2 different data types seems weird. Even in ruby they should just take the string and split it up into bytes and encode it instead of looking for string or array or bytes.
<FromGitter> <elorest> The second part of their block doesn’t even work… But mine doesn’t work at all for now! :(
<FromGitter> <elorest> It does return a value. It’s just wrong.
<FromGitter> <elorest>
<FromGitter> <johnjansen> this looks like alot of fun to debug … but alas i decided to clean the garage, and now it looks like a bomb went off … so id better do that before i get in trouble
greengriminal has joined #crystal-lang
<FromGitter> <johnjansen> 2 things jump out at me … 1, it starts with the correct letter and 2, its 1 char short
<FromGitter> <johnjansen> long
<FromGitter> <johnjansen> doesnt it use pairs of chars?
<FromGitter> <johnjansen> if so why does your have an odd number
tzekid has quit [Quit: Leaving]
_whitelogger has joined #crystal-lang
balduin has quit [Ping timeout: 255 seconds]
hightower2 has quit [Ping timeout: 260 seconds]
hightower2 has joined #crystal-lang
<FromGitter> <codenoid> @sdogruyol blog written in crystal
balduin has joined #crystal-lang
<oprypin> elorest, at least the encode looks perfectly fine
<oprypin> line 35 may be problematic
<oprypin> 123u8 << 3
<oprypin> 123u8.to_i << 3
<oprypin> the code is clearly from Ruby originally, assuming unlimited integer size everywhere
<oprypin> decode should not do the silly conversion to a fake string that's for sure
<FromGitter> <codenoid> hi oprypin
<oprypin> hi
<FromGitter> <elorest> <oprypin> Yeah the string thing on decode is just for debugging. It will return an io or slice….
<FromGitter> <elorest> encode has issues though in that it returns the wrong values. I tried to base it off the java implimentation.
<oprypin> oh Java. well they probably have int32 everywhere then
<oprypin> and you have uint8 in that one spot i pointed out, do check it
<FromGitter> <elorest> Ok.
<FromGitter> <elorest> Thanks
<oprypin> call slice.to_s if you know it's utf-8. there are certainly valid use cases for encoding strings even though the implementation uses bytes
_whitelogger has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
<FromGitter> <johnjansen> @elorest did you figure it?
Hak8or has joined #crystal-lang
Hak8or has quit [Ping timeout: 260 seconds]
<FromGitter> <elorest> Not quite but I think I’m close. Thanks.
<FromGitter> <johnjansen> nice
<FromGitter> <codenoid> yasss, (Kemal) != (Jekyll)
<FromGitter> <elorest> @johnjansen <oprypin> I tried everything I could think of and it still encodes the wrong values. I’ve mostly reverted it back.
<FromGitter> <elorest> <oprypin> I’ve changed everything I can think of to UInt8 but it still gives me the same values.
<FromGitter> <distinct> I just discovered crystal :)
<FromGitter> <elorest> Welcome!
<FromGitter> <distinct> Its so cool!
<FromGitter> <codenoid> hi
<FromGitter> <elorest> It’s the best here.
<FromGitter> <distinct> Im coming from Python
<FromGitter> <elorest> Cool.
<FromGitter> <elorest> I’ve used python. Mostly ruby and java though.
<FromGitter> <distinct> is there a go-to library for command line arg parsing in crystal
<FromGitter> <elorest> There is a built in one but i’ve used `mosop/cli`with success.
<FromGitter> <elorest> looks pretty good too.
<FromGitter> <distinct> Lol that guy mosop made two seprate CLI libraries
<FromGitter> <distinct> Both look good
<FromGitter> <distinct> @elorest admiral does look good
<FromGitter> <distinct> @elorest you use Atom as editor?
<FromGitter> <elorest> vim.
<FromGitter> <distinct> Thats hardcore
<FromGitter> <elorest> it’s not really that hard,
<FromGitter> <distinct> Is it really better than using something like Atom though?
<FromGitter> <elorest> meh. I think so. I’ve used a lot of editor’s and IDE’s at the end of the day though whatever works is fine.
<FromGitter> <elorest> If you’re good at vim it’s a tiny bit faster but mostly it’s just more fun.
<FromGitter> <distinct> i see 😄
<FromGitter> <bararchy> @distinct I'm using sublime it has great support for crystal via the crystal plugin
<FromGitter> <bararchy> Auto-formating , etc..
<FromGitter> <bararchy> Also for Atom:
<FromGitter> <distinct> @bararchy ooh, installing :D
<FromGitter> <distinct> I used sublime for a long time..but Atom UI i prefer
<FromGitter> <bararchy> Sure :) each with he's own preferences right ? ;)
<FromGitter> <distinct> How long have you been developing with crystal?
<FromGitter> <bararchy> 2-2.5 years
<FromGitter> <distinct> I really hope it continues to grow
<FromGitter> <bararchy> Playing around with, not real prod dev , only latly have I been actually developing in Crystal for production use
<FromGitter> <bararchy> Where did you hear about Crystal ?
<FromGitter> <distinct> I found crystal on
<FromGitter> <elorest> 2 years playing with it about 6 months in production
<FromGitter> <distinct> Was looking for alternative languages, really tired of Python
<FromGitter> <distinct> Crystal is a beautiful mix of form and performance
<FromGitter> <bararchy> Good to hear you like it so far , what are you planing to write with it ?
<FromGitter> <distinct> a trading bot
<FromGitter> <distinct> needed better performance than python could offer
<FromGitter> <bararchy> Cool :)
<FromGitter> <distinct> yet..wanted to use a pretty language
<FromGitter> <distinct> which is hard to come by lol.
<FromGitter> <bararchy> If you need any help or guidance the community is one of the best I ever being part of , so feel free to ask anything
<FromGitter> <distinct> Alright, one thing im wondering is where do you guys go to find packages
<FromGitter> <distinct> Is there a shard list
<FromGitter> <distinct> google keeps thinking im trying to find information on actual crystals
<FromGitter> <elorest>
<FromGitter> <bararchy> ^ yeha , best place is the
<FromGitter> <distinct> love it
greengriminal has quit [Quit: This computer has gone to sleep]
<oprypin> elorest, sorry, you understood me as the opposite of what i meant. if i wasnt on mobile i would've just fixed it
<oprypin> on mobile... lives up to its name
<FromGitter> <elorest> <oprypin> I think I figured that out eventually. Still doesn’t work though. by default these crystal uses int32. I believe that should be more than enough space to fit everything.
<FromGitter> <elorest> there’s my latest version.
<oprypin> elorest, yep, everything is exactly as i predicted
<oprypin> line 35 is the sole cause
<oprypin> >> 123u8 << 3
<DeBot> oprypin: # => 216 -
<oprypin> 123u8.to_i << 3
<oprypin> >> 123u8.to_i << 3
<DeBot> oprypin: # => 984 -
<FromGitter> <elorest> <oprypin> I think I changed it to every other possible value. Thanks
<FromGitter> <elorest> thanks again. Now I can go to sleep.
<oprypin> elorest, here's my vision of it
<hightower4> Hey, here's a Crystal library for reading/writing files in the Maildir format:
<FromGitter> <elorest> Cool. How would you remove the Array(UInt8) and replace it with IO::Memory?
<FromGitter> <LuckyChicken91_twitter> how can I push my shard to my github repo?
<FromGitter> <elorest> Push it to github like any repo. As far as versioning and tagging this can help.
<oprypin> elorest, it's the same really but you'd have to replace << with .write_byte
<oprypin> which i didn't find worth it
<FromGitter> <elorest> Ok. I wasn’t sure if it would be more efficient or something to use IO instead of an array.
<oprypin> IO is more for manipulations similar to text, array doesnt have the features but we dont need them
<oprypin> performance is exactly the same
<FromGitter> <elorest> Cool. Thanks for your help.
<oprypin> both use a constant size memory region that is occasionally replaced with a bigger one
hightower2 has quit [Ping timeout: 248 seconds]
<FromGitter> <elorest> Good to know.
<FromGitter> <LuckyChicken91_twitter> i dont know how to push it. Is there a command for this? can I select my folder on github?
<oprypin> LuckyChicken91_twitter, if it's on github, that means you've already pushed it
<FromGitter> <LuckyChicken91_twitter> i just created a repo
<FromGitter> <LuckyChicken91_twitter> theres nothing in the repo
<oprypin> LuckyChicken91_twitter, were you using Git at all?
<FromGitter> <LuckyChicken91_twitter> im not often git..
<FromGitter> <elorest> run `git init` in your folder.
<oprypin> hold on hold on
<oprypin> easier for a beginner to run `git clone`
<FromGitter> <elorest> ok
<oprypin> then put your files in that folder
<oprypin> then add all of them and commit
<oprypin> and push
<FromGitter> <LuckyChicken91_twitter> oh the git command!
<oprypin> if those words don't mean much to you... well, probably gotta learn git
<FromGitter> <LuckyChicken91_twitter> this is what i searched for
<FromGitter> <LuckyChicken91_twitter> oprypin, how do you finded my "crplus" repo?
<FromGitter> <LuckyChicken91_twitter> im getting this warning Warning: You seem to have cloned an empty repository.
<FromGitter> <elorest> That’s fine. Now copy your code into that folder, add, commit and push it.
<FromGitter> <elorest> You can find all of that in the guide I linked you above.
<FromGitter> <LuckyChicken91_twitter> which code should i copy in what folder?
<FromGitter> <elorest> The code you’re trying to get up to github.
<FromGitter> <LuckyChicken91_twitter> hm holding the folder over the github repo isnt working
<FromGitter> <elorest> cp -rf yourproject/* youremptyrepo/
<FromGitter> <LuckyChicken91_twitter> he shows me that is not a folder
<FromGitter> <elorest> it’s a url.
<FromGitter> <elorest> copy it to the empty repo you’ve cloned.
<FromGitter> <LuckyChicken91_twitter> the .git folder?
<FromGitter> <elorest> no. the folder that contains the .git folder
<FromGitter> <LuckyChicken91_twitter> but then im just cloning the crplus folder into the crplus folder
<FromGitter> <elorest> You’ve already cloned the folder. Now copy your code into the folder and add, commit and push it up to github.
<FromGitter> <elorest> don’t clone it again
balduin has quit [Ping timeout: 268 seconds]
<FromGitter> <LuckyChicken91_twitter> wait wait wait.. im having the crplus folder. And now i should copy the code in the src folder again into the crplus folder?
Cyrus has quit [Quit: WeeChat 1.7.1]
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 268 seconds]
Raimondii is now known as Raimondi
<FromGitter> <codenoid> ```code paste, see link``` []
<FromGitter> <codenoid> 😆
<FromGitter> <codenoid> ```code paste, see link``` ⏎ ⏎ 😆 ✨ []
hightower3 has joined #crystal-lang
rohitpaulk has joined #crystal-lang
Nouv has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
Ven has joined #crystal-lang
Ven has quit [Client Quit]
<FromGitter> <LuckyChicken91_twitter> yeaah my shard is working now
<FromGitter> <LuckyChicken91_twitter> sorry for being a little bit annoying @elorest
<Groogy> Morning
rohitpaulk has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
<Groogy> Hmm can I somehow provide a type to a method that would tell it "I want you to build an object of this type"
<hightower3> Groogy, you can pass a type, and do later
<Groogy> thx
<FromGitter> <LuckyChicken91_twitter> can someone tell me how the crystal language was made? because 98.1% is already maked with crystal.. this makes somehow no sense
<Nouv> It's self hosted
<Nouv> Crystal is able to compile itself
<Nouv> It was initially written in Ruby
<FromGitter> <LuckyChicken91_twitter> in RUBY?
<FromGitter> <LuckyChicken91_twitter> wut
<Nouv> Yes.
<FromGitter> <LuckyChicken91_twitter> but how can it then be so fast?
<Groogy> a compiler is just a glorified text reader that turns text into machine code, you could probably make a compiler in Brainfuck if you really hate yourself enough
<FromGitter> <LuckyChicken91_twitter> i know
<Nouv> Lucky: Initially it wasn't
<Nouv> when the compiler was written in Ruby it was slow
<Nouv> But self hosting itself, Crystal was able to compile fast
<FromGitter> <LuckyChicken91_twitter> hm. Really strange. well the main thing is that it works.
<Groogy> Clang and GCC is written in C/C++ isn't it?
<FromGitter> <LuckyChicken91_twitter> im sure
<FromGitter> <LuckyChicken91_twitter> "chicken and egg problem" sounds interesting
sz0 has quit [Quit: Connection closed for inactivity]
<Groogy> "can't cast (Array(Serializer::Type) | Bool | Float64 | Hash(Serializer::Type, Serializer::Type) | Int32 | Serializer::Node | String | Nil) to Array(Int32)"
<Groogy> Do I have to do the cast in two steps for it to work? :/
<crystal-gh> [crystal] akzhan opened pull request #4712: Regexp - Unicode codepoints support (master...libpcre-ucp)
<FromGitter> <LuckyChicken91_twitter> how can I detect if up_arrow key was pressed?
<oprypin> Groogy, ye probably
<FromGitter> <LuckyChicken91_twitter> hes just returning '\e' so i cant check if it was \e[B or \e[A etc
<oprypin> who's returning that
<Groogy> oprypin yeah :( will make a wrapper around it so client code doesn't have to be bothered
<hightower3> Troubles at ;-)
<oprypin> what troubles
<Groogy> exception it looks like
<hightower3> It was malfunctioning just a couple seconds ago, throwing Kemal/JSON error
<FromGitter> <LuckyChicken91_twitter> this guy is returning that --> STDIN.raw &.read_char
<hightower3> or something like that
<oprypin> LuckyChicken91_twitter, please see
<oprypin> or ditch the console and go for the nicer variant :D
<FromGitter> <LuckyChicken91_twitter> the people are saying theres no gui framework yet. But theres one. crsfml
<Groogy> CrSFML doesn't do what's normally termed GUI
<oprypin> LuckyChicken91_twitter, it does not allow you to put any native OS controls, even a simple button takes some effort. it's just graphics display and event handling
<Groogy> SFML is a multimedia library/framework
<FromGitter> <LuckyChicken91_twitter> hm
<FromGitter> <LuckyChicken91_twitter> but its a beginning
Ven has joined #crystal-lang
Ven is now known as Guest52311
<hightower3> Lol I just got error "named tuple too big"
kubaxvx__ has quit [Read error: Connection reset by peer]
<oprypin> D: i'm actually really curious what you were doing
<hightower3> oprypin, attempted to convert tables in to Crystal
<oprypin> hightower3, it it's compiletime, it should just be a collection of constants, if it's used by string at runtime, it should be a hash
kubaxvx__ has joined #crystal-lang
Nouv has quit [Quit: Nouv]
<FromGitter> <LuckyChicken91_twitter> is the website made with kemal?
<FromGitter> <codenoid> made with kemal
<FromGitter> <sdogruyol> @LuckyChicken91_twitter kemal website is built-with Jekyll to easily use Github Pages
<FromGitter> <sdogruyol> meanwhile is built with Kemal
<FromGitter> <LuckyChicken91_twitter> wut? i was sure its made with kemal because it would fit so well
<FromGitter> <LuckyChicken91_twitter> can someone answer this question:
<Groogy> hmmm vscode being super annoying
<Groogy> not letting me set he working directory correctly :/
<FromGitter> <LuckyChicken91_twitter> vscode does not seem to like directorys
rohitpaulk has quit [Ping timeout: 240 seconds]
<Groogy> exit
Groogy has quit [Quit: WeeChat 1.9]
<FromGitter> <LuckyChicken91_twitter> exit?
<FromGitter> <drosehn> `@method`-variables are variables that exist in instances of a class, which means they have to be defined inside a `class Blah` ... `end` section. And those variables are in an *instance* of a class, which means the program would need to do a `save_inst =` to create an instance of that class.
<FromGitter> <LuckyChicken91_twitter> i know
<FromGitter> <LuckyChicken91_twitter> but i would find it better if you can define @method_variables too in top level like in ruby
<FromGitter> <drosehn> You could avoid that by using `@@class` variables, and then wrapping all your methods inside of a `module`. This is kind of an odd reason to use a module, but it can be used to have the effect that I think you want.
<FromGitter> <drosehn> example:
<FromGitter> <drosehn> It was an explicit decision in the design of crystal that it would not support `@instance` variables at the top level like ruby does. And a similar decision was that crystal would not support `$global` variables in the way that ruby does.
<FromGitter> <drosehn> Well, it has some compiler-defined `$global`-variables, but does not allow users to create their own new `$variables`. Earlier versions of crystal *did* support user-defined `$global` variables, but it was decided that the crystal language would be better if it did not allow that.
rohitpaulk has joined #crystal-lang
<oprypin> $ does not stand for global
<oprypin> and yeah masking globals as variables of meaningless classes is so much better /s
Guest52311 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Ven has joined #crystal-lang
Ven has quit [Client Quit]
<oprypin> it's actually a difficult to find any information on what $ means
<oprypin> so i guess $~, $1, $2, $... are variables that can leak to the caller's scope
<FromGitter> <drosehn> I just used the `$global` and `$variables` because `$` is the prefix-character used to denote them in a few languages, including ruby.
<FromGitter> <drosehn> Well, the remaining `$-variables` in crystal are globally-defined "special variables" that the compiler controls.
<FromGitter> <drosehn> or maybe "provides and controls".
<oprypin> ah no, only $~ is a variable that can leak to the outer scope
<oprypin> $1 is an alias to $~[1].not_nil!
<FromGitter> <drosehn> Hmm. I'm not completely sure that `$~` will always leak to an outer scope, although I tend to program as if it did. so if it does, then I wouldn't notice it...
<oprypin> drosehn, an example if you are interested
<oprypin> now $0 is a whole different beast, i dont understand why it's a thing
<oprypin> >> $0
<DeBot> oprypin: # => "/home/crystal/.cache/crystal/crystal-run-eval.tmp" -
<FromGitter> <drosehn> Yeah, that's the kind of example I was wondering about. I knew `$~` leaked to outer scopes in some situations, but I wasn't sure it would leak to all outer scopes.
<oprypin> just one level
<FromGitter> <drosehn> Well, `$0` exists in many languages (including shells), and I expect it doesn't hurt anything to keep it in crystal. ("keep" in the sense that crystal used to have all the same `$global`-variable support that ruby has, but then removed almost all of that, except for the few things it "kept").
<oprypin> that's not a valid justification
<FromGitter> <drosehn> If `$0` was removed, then crystal would just have to add some other way to get the same value. It seems to me that wouldn't be much of a win.
<FromGitter> <LuckyChicken91_twitter> how can I rescue "undefined method" errors?
<oprypin> $0 is unconditionally rewritten to PROGRAM_NAME
<FromGitter> <drosehn> Well, I'm not a designer of the language. I just dabble with it when I have the time. But I'm happy that they kept `$0`.
<oprypin> LuckyChicken91_twitter, these errors happen at compilation, the program never runs
<oprypin> LuckyChicken91_twitter, try running `crystal build` and you'll see the error - these errors you can't catch, you need to fix your program
<FromGitter> <drosehn> ... and since the program never runs, it is impossible for the program to trap them.
<FromGitter> <LuckyChicken91_twitter> this error is wanted!
<FromGitter> <LuckyChicken91_twitter> i want to rescue it with begin,rescue,end
<FromGitter> <drosehn> It isn't wanted by crystal ! 😄
<FromGitter> <LuckyChicken91_twitter> ugh
<oprypin> sigh
<oprypin> >> "a" =~ /a/; p $0
<DeBot> oprypin: "/home/crystal/.cache/crystal/crystal-run-eval.tmp" - more at
<oprypin> >> "a" =~ /a/; p $00
<DeBot> oprypin: "a" - more at
<FromGitter> <LuckyChicken91_twitter> but wait.. theres ```$0``` ?! then crystal lied to me! crystal said "$global_variables are not supported, use @@class_variables instead"
<oprypin> it's not a global variable
<oprypin> just a silly special construct that starts with '$' and is unconditionally rewritten to PROGRAM_NAME
<FromGitter> <LuckyChicken91_twitter> its a special super indefinable variable?
<FromGitter> <LuckyChicken91_twitter> oh ok
<oprypin> proof
<oprypin> >> $0 = 5
<DeBot> oprypin: -
<FromGitter> <LuckyChicken91_twitter> > $0
<FromGitter> <drosehn> Well, for one thing, it's a global CONSTANT. The program cannot change the value. (although it looks like crystal does not complain about `$0 = "some string"`, but executing that does not change the value of `$0`).
<oprypin> sorry, that action is not accessible from gitter
<oprypin> drosehn, when you write $0 = blah, it's rewritten to PROGRAM_NAME = blah causing the error indirectly
<oprypin> anyway, the main point is $0 does makes sense in shells, but the shells also have $1, $2, $@ to get access to all arguments
<FromGitter> <drosehn> Well, I happened to pick an interesting test for this. I added the lines to the test-module program I had, and in that it does not error at all.
<oprypin> $0 is just the first argument passed to the program, a logical continuation of $1, $2 and all
<oprypin> and it went sh -> perl -> ruby -> crystal and ended up making absolutely no sense
<oprypin> because all other of these constructs have been replaced with something that makes sense
<oprypin> and also shells use $1 at every level, for function arguments if it's inside a function
<FromGitter> <drosehn> ```code paste, see link``` []
<oprypin> drosehn, yeah what do you know, writing PROGRAM_NAME = blah inside a module is totally legit
<FromGitter> <drosehn> Well, if it's a vote, I'm happy to vote to keep `$0`. If it's an argument you want, I'm out of here.
<FromGitter> <LuckyChicken91_twitter> no define_method in crystal?
<oprypin> LuckyChicken91_twitter, no define_method in crystal.
<FromGitter> <LuckyChicken91_twitter> whyy
<oprypin> because it's a compiled language
<oprypin> if you want ruby, you use ruby
<FromGitter> <LuckyChicken91_twitter> because i want to define a method which name "~"
<FromGitter> <LuckyChicken91_twitter> with*
<oprypin> >> class A; def ~; end; end
<DeBot> oprypin: #=> nil -
<oprypin> go ahead and do that then!
<FromGitter> <LuckyChicken91_twitter> but i cant execute the method "~" then
<FromGitter> <LuckyChicken91_twitter> its not a valid method name i think :/
<oprypin> >> class A; def ~; end; end;;
<DeBot> oprypin: Syntax error in eval:17: expecting any of these tokens: IDENT, +, -, *, /, %, |, &, ^, **, <<, <, <=, ==, !=, =~, !~, >>, >, >=, <=>, ===, [], []=, []?, [ (not '~') -
<oprypin> >> class A; def ~; end; end;
<DeBot> oprypin: # => nil -
<FromGitter> <LuckyChicken91_twitter> but i want to do ~ not
<oprypin> that's not a valid operator name. don't do that.
<FromGitter> <LuckyChicken91_twitter> a pity
<oprypin> i mean it is a valid operator name, just that it's a prefix operator
<FromGitter> <LuckyChicken91_twitter> oh i can use my defined methods in my file before they are defined?
<FromGitter> <LuckyChicken91_twitter> i think because its a compiler
rohitpaulk has quit [Ping timeout: 240 seconds]
greengriminal has joined #crystal-lang
Ven has joined #crystal-lang
Ven is now known as Guest99595
greengriminal has quit [Quit: This computer has gone to sleep]
pwned has joined #crystal-lang
<FromGitter> <LuckyChicken91_twitter> what is better: "perform" or "execute" ?
<oprypin> I think it's ridiculous to ask which of a pair of words is better.
<Papierkorb> These two words are not synonymous, and thus one is better/more appropriate/the only possible one per context
<FromGitter> <LuckyChicken91_twitter> i think i will name it "run"
<FromGitter> <LuckyChicken91_twitter> is someone here having method-ideas to make crystal a better place?
Guest99595 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Ven has joined #crystal-lang
Ven is now known as Guest27471
Guest27471 has quit [Client Quit]
<FromGitter> <LuckyChicken91_twitter> no? really?
<oprypin> nobody has any idea what you're saying, as usual
<FromGitter> <LuckyChicken91_twitter> uh
rohitpaulk has joined #crystal-lang
<FromGitter> <LuckyChicken91_twitter> i mean: is someone here having ideas for good methods?
<FromGitter> <LuckyChicken91_twitter> no?
<FromGitter> <LuckyChicken91_twitter> 😟
<FromGitter> <LuckyChicken91_twitter> is nobody understanding me
<FromGitter> <johnjansen> sorry @LuckyChicken91_twitter unfortunately not
<hightower3> Is there anything better for writing a non trivial console app than (the ncursesw and crt lib wrapper)?
<oprypin> hightower3, do you want an actual UI or just command line interface
<hightower3> ncurses-like interface, with windows etc.
<FromGitter> <LuckyChicken91_twitter> is there a way to get the the operating system name with crystal
<oprypin> LuckyChicken91_twitter, for what purpose?
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <LuckyChicken91_twitter> for knowing which operating system im using
<oprypin> LuckyChicken91_twitter, `{% if flag?(:linux) %} puts "I'm using linux" {% end %}`
greengriminal has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <LuckyChicken91_twitter> im using windows
<FromGitter> <LuckyChicken91_twitter> but he shows me linux
<FromGitter> <LuckyChicken91_twitter> but its just the linux subsystem
<FromGitter> <straight-shoota> So it's technically linux (inside windows)
<FromGitter> <straight-shoota> there is no direct way for crystal (or any application for that matter) to know this
<FromGitter> <straight-shoota> The os flags are known at compile time. If you want more details about the operating system like which linux distribution, you need to specifically ask the operating system
<FromGitter> <straight-shoota> For linux, this information would be provided for example by `lsb_release`
Elenian has joined #crystal-lang
<oprypin> not on ancient still supported redhats though xD
<FromGitter> <straight-shoota> *most linux :D
<FromGitter> <LuckyChicken91_twitter> but if crystal is official out for windows then it will show windows right?
Elenian has quit [Client Quit]
<oprypin> LuckyChicken91_twitter, when Crystal runs on Windows, flag?(:windows) will be present
<FromGitter> <straight-shoota> yes, you should already be able to use this code `{% if flag?(:windows) %} puts "I'm using windows" {% end %}`
<oprypin> currently you are running it under a reimplementation of a linux kernel
<FromGitter> <LuckyChicken91_twitter> ik
<FromGitter> <LuckyChicken91_twitter> can i btw directly put the flag out without testing which it is?
<oprypin> no
<FromGitter> <LuckyChicken91_twitter> oh ok
<FromGitter> <LuckyChicken91_twitter> uh can i then see which the flag can be?
<FromGitter> <LuckyChicken91_twitter> all possbilities
<oprypin> in the future there may be ways to get the system name as a string, but currently that's all we have
<FromGitter> <LuckyChicken91_twitter> thank you
<FromGitter> <straight-shoota> those flags however do not relate directly to operating systems. `:unix` for example entails quite a few different OSes
<FromGitter> <straight-shoota> arm* and *68* are obviously hardware architectures
<hightower3> Are is_a? and === identical in performance?
<oprypin> hightower3, no, and not even in functionality
<oprypin> is_a? is a syntax feature, === is a wrapper for it that does not carry over the type hints for the compiler
Ven_ has joined #crystal-lang
<FromGitter> <straight-shoota> @LuckyChicken91_twitter the link I gave you only details the "meta" flags, there might also be others not included in any of these groupings
<FromGitter> <LuckyChicken91_twitter> oh
<FromGitter> <LuckyChicken91_twitter> ah no matter i will use these temporarily
<oprypin> straight-shoota, yeah it's directly from llvm target triple, but then try to find the actual possible values for it
<oprypin> something's here but it's 5 items not 3
<oprypin> "triple"
<hightower3> Thanks. For spec tests, what's the way to initialize some @instance_var before tests are ran? If I define some before_each block and try to set it there, it tells me I can't use instance vars at top level
<oprypin> hightower3, can't really do that. specs are obviously not classes nor modules so yeah instance vars don't work there
<oprypin> if you can define a global (maybe even variable would work) outside of `describe` that could work
<hightower3> oh sure, will try that then, thanks
<oprypin> then there's actually providing such a feature but it's not without problems
Ven_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <LuckyChicken91_twitter> uh can someone pls explain me macros? for me they are just the dark deep of crystal
<FromGitter> <straight-shoota> do you know a templating engine like Jinja, Liquid, Twig, ...?
<FromGitter> <LuckyChicken91_twitter> no
<FromGitter> <straight-shoota> No templating at all or just not the mentioned engines?
<FromGitter> <straight-shoota> Basically, macros generate code from a template. This generated code is inserted at the place where the macro is called.
<FromGitter> <LuckyChicken91_twitter> ah ok
<hightower3> Hm, looks like Tuple can't be indexed using -1
<oprypin> :)
<FromGitter> <LuckyChicken91_twitter> what are the differences between tuple and array?
<hightower3> tuple is created on the stack, it is known at compile time, and you can't modify it after creation
<oprypin> the important part is that each item has its own type known at compile time
<FromGitter> <LuckyChicken91_twitter> i will still use arrays
<oprypin> lol
<FromGitter> <LuckyChicken91_twitter> i like arrays
<oprypin> of course you will because you just want ruby and not learn
<FromGitter> <LuckyChicken91_twitter> no nonono
<oprypin> oh yes
<FromGitter> <LuckyChicken91_twitter> idontwantruby
<oprypin> >> t = {"a", 5}; t[0].chars
<DeBot> oprypin: # => ['a'] -
<oprypin> >> t = ["a", 5]; t[0].chars
<DeBot> oprypin: -
<oprypin> - undefined method 'chars' for Int32
<oprypin> this bot could be so much better, sigh
<FromGitter> <LuckyChicken91_twitter> who programed this bot
<oprypin> @jhass
<FromGitter> <LuckyChicken91_twitter> @jhass your bot is not good enough
<oprypin> ...
<FromGitter> <bararchy> And if we are talking about @jhass , dude when you get sometime , can you please push a version in the crystal-git aur package ? Thankssss :):):)
<oprypin> bararchy, there is no need to update crystal-git unless the build breaks. it's always latest.
<oprypin> just rebuild/reinstall
<FromGitter> <distinct> Whats the best way to callback a method?
<oprypin> that's not a verb or anything that makes sense
<crystal-gh> [crystal] oprypin opened pull request #4716: Remove '$0' special syntax (
<hightower3> What's the most direct replacement for for?
<FromGitter> <johnjansen> use case @hightower3 :-)
<FromGitter> <johnjansen> not `case` but a usecase
<hightower3> standard for (i=0;i<10;i+=1) ...
<FromGitter> <johnjansen> 1) times do |i|
<FromGitter> <straight-shoota> or `0.upto(10) do |i|`
<FromGitter> <johnjansen> or (0..10).each do |i|
<hightower3> hm, hm... yeah, probably acceptable
<oprypin> and dont forget `Number#step(*, to = nil, by = 1)`
<FromGitter> <johnjansen> probably?
<FromGitter> <johnjansen> what are we missing @hightower3
<FromGitter> <straight-shoota> I think step makes only sense when you want different step then 1
<oprypin> well sure, but the question was a replacement for `for`
<FromGitter> <johnjansen> agreed, but from the “probably acceptable” comment, he must need something else
<oprypin> `i = 0; while i < 10; i += 1; end`
<FromGitter> <johnjansen> yeah, step seems to be the only thing missing unless its the condition component
<FromGitter> <straight-shoota> I assumed "standard" refers to a loop incrementing by one
<FromGitter> <johnjansen> haha @oprypin is there already
<hightower3> oprypin, yes, I was using that approach so far :)
<hightower3> but I didn't like that the increment had to be at the bottom
<hightower3> Shouldn't Array#clear be called #clear!
<oprypin> hightower3, mutating methods get a '!' only when a corresponding non-'!' method would also make sense
<oprypin> or in a simpler way, dont need '!' when it's obvious anyway
<FromGitter> <johnjansen> imo i have always thought that `!` should be consistently used as a mutating version indicator, it make it all very predictable
<hightower3> hm, interesting approach.. I mean, it may be known/guessable for some basic/built-in methods whether a non-! makes sense or not, but for general, other people's modules, a user can't be expected to know the inner workings/data structure and whether non-! exists/makes sense or not.
<hightower3> Exactly johnjansen
<Papierkorb> If it's hard to tell from the API, then the API is bad
<hightower3> Well, yeah, when you're looking at the API the doubt is already cleared up since you're already on the listing of available methods
<hightower3> But it prevents you from guessing/knowing in advance
<Papierkorb> No docs
<FromGitter> <johnjansen> and being able to guess is a major productivity boost
<Papierkorb> Also, having ! everywhere would be tedious and would make the bang lose its meaning real quick. `#insert!` and stuff?
<hightower3> Yeah, you're right on that
<hightower3> What's a straightforward way to trim (shorten) array to certain size?
<hightower3> (discarding all elements that fall out of the upper bound)
<Papierkorb> You want to remove the last n elements?
<hightower3> I want to keep the first 8 elements in the array, discarding everything else
<Papierkorb> See Array#pop
<Papierkorb> There's sadly no discarding delete in Array. Looks like missing functionality.
<Papierkorb> If you don't want to modify the original array, just go with `ary[0, 7]`
<Papierkorb> 0, 8*
<oprypin> Papierkorb, hightower3, in that kate `ary.first(8)`
<oprypin> dont know how "case" became "kate"
<hightower3> Right, I was hoping for some in-place modification
<oprypin> dont see any
<Papierkorb> johnjansen, though I really like C++/Qt's naming convention: Method names are verbs, or end in one. If the verb is in past tense, a copy is returned. If it's not in past tense, the original is modified. E.g.: `someList.sort();` vs `someList.sorted().somethingElse();`
<oprypin> hightower3, `ary[8..ary.size] = []` is an option then
<oprypin> but i think you're better off reassigning anyway
<hightower3> It seems that array.delete_at 8..-1 works
<oprypin> that is good
<FromGitter> <LuckyChicken91_twitter> if im installing my shard then there appears a long random text! not like in other shards the version: Updating ⏎ Using myshard (7q6ab932r250c075f16416ae512j0a61ae50dk1b)
<oprypin> i don't think the "random text" was copied unchanged :D
<oprypin> LuckyChicken91_twitter, other projects used a git feature called 'tags'
<oprypin> `git tag v1.0.0; git push --tags`
<oprypin> make sure this tag matches what you have in shard file, otherwise it's silly :p
<FromGitter> <LuckyChicken91_twitter> yes i changed the "random text" because i was not sure that i can get hacked if im publiciting the valid random text
<oprypin> meanwhile, if you write `git log` you'll see that random text as your latest commit id
<oprypin> no it's ok
<FromGitter> <LuckyChicken91_twitter> oh okay
pwned has quit [Ping timeout: 240 seconds]
<FromGitter> <LuckyChicken91_twitter> short question to linux: how can I just go one folder back?
<oprypin> cd .. ?
<oprypin> `cd ..`
<FromGitter> <LuckyChicken91_twitter> no! now im at the beginning of the system
<Papierkorb> LuckyChicken91_twitter, please read up on bash and git. It'll help you immensely in the long run.
<FromGitter> <LuckyChicken91_twitter> okay
sagax has joined #crystal-lang
<oprypin> LuckyChicken91_twitter, have you considered logging in to gitter with your github account instead
<oprypin> won't have that annoying _twitter thing
<FromGitter> <LuckyChicken91_twitter> yes
<FromGitter> <LuckyChicken91_twitter> i have
<FromGitter> <LuckyChicken91_twitter> but i have registered me with my twitter account in gitter
greengriminal has quit [Quit: Leaving]
<oprypin> ok so log out and log in with github?
<FromGitter> <LuckyChicken91_twitter> uh i think my gitter account and github account is not connected
<FromGitter> <LuckyChicken91_twitter> 2 different accounts
<FromGitter> <LuckyChicken91_twitter> i cant use the class which i defined in the shard
<oprypin> cool cool
<FromGitter> <LuckyChicken91_twitter> everything is working but not the class
<FromGitter> <LuckyChicken91_twitter> do you know why, oprypin?
Ven has joined #crystal-lang
Ven is now known as Guest59775
<oprypin> new thing
<FromGitter> <LuckyChicken91_twitter> nice
Guest59775 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <LuckyChicken91_twitter> wow! it can run soo many programming languages!
<hightower3> If I have def x(one, two, three) , and I call x() with a tuple of 3 elements, will it automatically expand into 3 args?
<oprypin> hightower3, certainly not. call `x(*tuple)`
<hightower3> Ah of course, thanks
<FromGitter> <LuckyChicken91_twitter> do i need to use modules instead of classes in my shard?
<oprypin> when will it end
<FromGitter> <LuckyChicken91_twitter> what?
thews has quit [Ping timeout: 245 seconds]
<FromGitter> <LuckyChicken91_twitter> what do you mean oprypin
<oprypin> LuckyChicken91_twitter, you should put more effort into your questions (and communication overall), make them more specific while still providing context. and maybe you don't even need to ask, just see what other people are doing, and read documentation first!
<oprypin> what i mean is that i'm really annoyed
<FromGitter> <LuckyChicken91_twitter> hm my goal was to annoy nobody here
<FromGitter> <LuckyChicken91_twitter> but i failed
<FromGitter> <LuckyChicken91_twitter> thats sad
<oprypin> hey, part of that is on me
<hightower3> I have a line: r1 += (r2 - r1) * alpha | 0; . And when I run it it tells me "undefined method '|' for Float64". What am I missing here?
<oprypin> one of these things is a Float64
<oprypin> what's the point of | 0 now?
<oprypin> have you been secretly doing javascript
<oprypin> can't easily recover from that
<hightower3> Hehe ;-)
<oprypin> hightower3, so i think that you meant to apply the horrible hack that javascript truncates numbers when you use | 0 but obviously here it's nonsense
<hightower3> Yeah, needed a to_i in any case, and to remove |0
<FromGitter> <fridgerator> are there any examples of testing what happens inside of a spawn block with spec? or is it possible?
<oprypin> fridgerator, make the block do side effects, or better push to a channel
<oprypin> not exactly sure about the use case
<FromGitter> <fridgerator> one sec, i'll link what i'm trying to test
<FromGitter> <fridgerator> I want to test the `beat` method, and the `check_alive!` method, but they run in a separate fiber
<oprypin> move spawn out of it
<FromGitter> <fridgerator> your
<oprypin> no edits!
<FromGitter> <fridgerator> I wondered how that translated to irc
<FromGitter> <fridgerator> you're saying dont use spawn?
<FromGitter> <fridgerator> i'm using spawn, becuase could be blocking ?!?
<oprypin> remove spawn inside beat. use spawn{beat} elsewhere
<FromGitter> <fridgerator> ah ok
<FromGitter> <fridgerator> i'm already doing that actually, so that spawn is probably unecessary
Ven has joined #crystal-lang
Ven is now known as Guest16543
rohitpaulk has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
<hightower3> case is not fall-through, right?
<oprypin> hightower3, is not
Liosha has joined #crystal-lang
<Liosha> Hi crystal community, I'm trying to do bindings of libpython3 but I'm getting segment faults, here is a minimal code :
<Liosha> I just was able to run Python.exit(0) successfully, but not other python functions here:
<oprypin> good, i'm on it
<oprypin> Liosha, is there any api reference
<oprypin> list of all funcitons
<Liosha> oprypin, I'm using Python source code
<oprypin> Liosha, i think you just didnt init
<Liosha> Can I generate Python binding automatically?
<oprypin> maybe
<oprypin> Liosha, you are using snprintf wrong.
<Liosha> oprypin, Do you mean init the Python VM?
<oprypin> ye
<oprypin> str is where it writes data. you provided a string which is in the data section, not writable
<Liosha> oprypin, Thanks you!, I know Python and I'm learning Crystal, so need to learn C too :-)
<oprypin> woops, unused variable
<Liosha> oprypin, Thanks you! \(ˆ˚ˆ)/ I'm will try to binding Python to Crystal now, maybe a **Pystal** shard :-)
<Liosha> I just read your repos and found this, just awesome <3 <3 <3
<oprypin> Liosha, no it's not mine, just an unchanged fork
<oprypin> this is mine though and it appears to work on this
Guest16543 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Liosha> osprypin, many thanks you, I will play with, great work :-)
<hightower3> Ah help me a little bit here please. I have a method like def test( arg : Hash of String => String | Bool | Int32). But when I call it, it tells me e.g.: nstance variable '@options' of Cls must be (Hash(String, Bool | Int32 | String) | Nil), not Hash(String, Bool | String)
<Liosha> hightower3, maybe you can do, Bool | Int32 | String) | Nil))
<oprypin> hightower3, that's... not valid syntax there
Liosha has left #crystal-lang [#crystal-lang]
<hightower3> I must be tired.. What is pestering me is that it's not allowing me to do something like: def tput(options : Hash(String|Int32|Bool) = {}). It complains that I must specify {} as "{} of KeyType => KeyValue"
thews has joined #crystal-lang
<oprypin> hightower3, `def tput(options = Hash(String|Int32|Bool).new)`
<oprypin> though that's still not valid cuz 2 types
<oprypin> Liosha is gone..
<FromGitter> <codenoid> :O
jihantoro has joined #crystal-lang
jihantoro has quit [Client Quit]
<FromGitter> <elorest> Apparently this base91 implementation that I build yesterday with <oprypin>s help is 7 times slower than base64.
<oprypin> of course it is
<FromGitter> <elorest> Because of extra logic since 91 isn't a binary number?
<oprypin> base64 is 4 bytes to get 3 bytes, and this is god knows what kind of abomination
<FromGitter> <elorest> kilo
<oprypin> hm the implementation of base64 in standard library is still really annoying
<oprypin> probably because it's crazy optimized
<FromGitter> <elorest> Adobe uses base85 for everything and it seems like it would match weird to bytes too.
<oprypin> because one could write a base64 implementation in like 5 lines
<FromGitter> <elorest> yeah that's what I thought.
rohitpaulk has quit [Ping timeout: 260 seconds]
sz0 has joined #crystal-lang
Ven has joined #crystal-lang
Ven is now known as Guest72659
<FromGitter> <distinct> Day 2 using crystal
<FromGitter> <distinct> Still love it :D
<FromGitter> <fridgerator> 👍
<FromGitter> <elorest> 👍
hightower3 has quit [Ping timeout: 240 seconds]
snsei has joined #crystal-lang
Guest72659 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]