jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
postmodern has joined #crystal-lang
HumanGeek has quit [Ping timeout: 246 seconds]
_whitelogger has joined #crystal-lang
deavmi has quit [Ping timeout: 265 seconds]
deavmi has joined #crystal-lang
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 272 seconds]
alexherbo2 has quit [Ping timeout: 246 seconds]
<FromGitter> <naqvis> > *<oprypin>* https://crystal-lang.org/api/master/Array.html#[]=(index:Int,count:Int,values:Array(T))-instance-method reeeeeally should accept Indexable :⁠( ⏎ ⏎ Provided you want this method to sequentially copy elements :P
_whitelogger has joined #crystal-lang
alexherbo2 has joined #crystal-lang
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
postmodern has quit [Quit: Leaving]
_whitelogger has joined #crystal-lang
alexherbo23 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 256 seconds]
alexherbo23 is now known as alexherbo2
<riffraff169> i have this: opcodes = {} of String => Array(Int32)
<riffraff169> but this error:
<riffraff169> 59 | opcodes[op1][modeval] = code.to_i
<riffraff169> ^
<riffraff169> Error: no overload matches 'Array(Int32)#[]=' with types Mode, Int32
<jhass> riffraff169: so modeval is not a string but presumably an enum called Mode
<riffraff169> yeah, there it is
<riffraff169> so modeval.to_i
<jhass> that would turn it into an Int32, not a String
<riffraff169> yeah, modeval should be an int
<riffraff169> the array is "brk" = [ 234,-1,-1,-1,-1 ]
<jhass> Oh, you're right, I got confused by the hash, sorry
<riffraff169> so the array is a bunch of ints, probably -1 (not within 0..255)....yeah
<riffraff169> ok, got past that with .to_i...missing hash key now....so, it wont automatically create the hash key....yeah, just like ruby, check if key exists, if not, create the entry, then add the data, otherwise modify the data
<riffraff169> gotcha
<jhass> yeah
<jhass> Hash(String, Array(Int32).new {|h, k| h[k] = [] of Int32 } works too, just like ruby
<riffraff169> ok, here is one of the alternates we were talking about yesterday: include? vs has_key? which is preferable? or does one not even exist?
<jhass> include? doesn't exist at all :P We got Enumerable#includes?, son on Hash you'd check for .includes?({key, value}) which is probably not what you want
<riffraff169> yeah, i just want to see if the key is present for now, if not, create it
<jhass> has_key? it is, or use the "auto creating" hash like I mentioned above
<riffraff169> hmm, i havent encountered that expression before, so im trying to understand it...where does h and k come from?
<FromGitter> <Blacksmoke16> `h` is a reference to the hash itself and `k` is the missing key
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Hash.html#new(initial_capacity=nil,&block:Hash(K,V),K-%3EV)-class-method
<riffraff169> ah i get it, thats an initializer block...
<riffraff169> well, you learn something new every day...never had to use that before now
<riffraff169> searching for stuff is hard on google because most of the results i get are for crystal reports, not what i want
<FromGitter> <Blacksmoke16> better off searching the api docs
<FromGitter> <Blacksmoke16> and or adding `-reports` to your google search
<riffraff169> yep
<FromGitter> <Blacksmoke16> but also make sure you have the most up to date docs when you find something on google
<FromGitter> <wyhaines> "crystal language" also works pretty well if you want Google to find the appropriate API doc section for you.
<riffraff169> thats what ive been adding too
<riffraff169> hmm, weird, im getting an out of bounds error:
<riffraff169> Unhandled exception: Index out of bounds (IndexError)
<riffraff169> opcodes[op1.downcase][0] = 0
<riffraff169> setting any index in the array gives me the error, i even change the init block to this:
<FromGitter> <Blacksmoke16> is the array empty?
<riffraff169> opcodes = Hash(String, Array(Int32)).new { |h, k| h[k] = Array(Int32).new(modemap.size) }
<riffraff169> it will be the first time, yes....
<FromGitter> <Blacksmoke16> then there isnt an index 0 to set )
<FromGitter> <Blacksmoke16> :)
<FromGitter> <Blacksmoke16> you prob want to use `<<`
<riffraff169> hmm, the index wont necessarily be at 0 though...i have to set arbitrary items within the 21 entry array
<riffraff169> so i think `<<` isnt appropriate
<riffraff169> because that will just add at the next index
<FromGitter> <Blacksmoke16> maybe try https://crystal-lang.org/api/master/Array.html#insert(index:Int,object:T)-instance-method
<riffraff169> really what i want is to create the whole array with default values at the beginning, and be able to set individual items at will
<riffraff169> so im not sure insert is correct either
<riffraff169> i thought thats what Array(Int32).new(21) would do, but ill have to look that up to be sure
<FromGitter> <Blacksmoke16> i think that just sets the initial size of the array to 21
<FromGitter> <Blacksmoke16> you prob want to do like `Array(Int32).new 21, 0`
<riffraff169> doing `Array(Int32).new(size,-1)` worked.....yep
<FromGitter> <Blacksmoke16> 👍
<riffraff169> thanks for the help...working with a kind of a combination of a dynamic and static language is kind of weird
<riffraff169> ha ha!...i got it....doing a little code generation, the output will be a .cr file that can be included...each code has a list of modes it is valid in, and invalid ones are -1
<riffraff169> now to output the data, pretty printed to the file...would like to convert numbers that arent -1 to hex, but not really necessary
<riffraff169> so im going to use a makefile for some prerequisites (like this opcode generator)...would it be better if the makefile did a shards build and run? or would plain crystal run be better? not sure on that part
<riffraff169> basically a dependency....if the pre-generated files have changed, then recreate the code files from the data before running the main build
lunarkitty has quit [Ping timeout: 244 seconds]
<FromGitter> <Blacksmoke16> is this project meant to be installed? or run on its own
<riffraff169> the main project will probably be installed, but the small program im writing right now as a prereq of the project will just be run in the source tree itself, if necessary
<FromGitter> <Blacksmoke16> because there is a `postinstall` step you can do it in
<riffraff169> upon distribution i will provide the generated file, kind of like difference between `make clean` and `make distclean`...
<riffraff169> well, this would be prebuild actually
<FromGitter> <Blacksmoke16> fair enough
<riffraff169> do people tend to use makefiles? or shards only? some programming languages (java i believe) have their own totally separate project build ecosystem
<FromGitter> <Blacksmoke16> makefiles are pretty common
<riffraff169> ok, thats fine, im pretty familiar with those
alexherbo2 has quit [Ping timeout: 256 seconds]
<riffraff169> printing out my final opcode list ``` outfile << " opcodes = {\n"
<riffraff169> str = opcodes.keys.sort.each.join(",\n") do |opcode|
<riffraff169> " \"" + opcode + "\" => [" + opcodes[opcode].join(", ") do |val|
<riffraff169> end + "]"
<riffraff169> val < 0 ? val : "0x" + val.to_s(16)
<riffraff169> end
<riffraff169> outfile << " }\n"
<riffraff169> ```
<riffraff169> i like being able to chain methods like that, and use blocks/lambdas....python doesnt let me do that
<FromGitter> <Blacksmoke16> i think the `.each` is redundant
<FromGitter> <Blacksmoke16> could do `.sort.join`
<riffraff169> yep, you are right, thanks
<riffraff169> so now i have it generating my file as a module that will be included in another class..fantastic
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
<FromGitter> <Blacksmoke16> 👍
alexherbo2 has joined #crystal-lang
<FromGitter> <Dan-Do> why does crystal http module encode the cookies?
<FromGitter> <Dan-Do> I got JSESSIONID=0000N-X1lNeO_hMzfqNsEZVkJpY:19ciqlrd2 from the server, but crystal encode it to JSESSIONID=0000N-X1lNeO_hMzfqNsEZVkJpY%3A19ciqlrd2 before sending
<FromGitter> <Dan-Do> It made me crazy 2 days debugging this
<FromGitter> <asterite> might be a bug: https://github.com/crystal-lang/crystal/issues/9306
<FromGitter> <Dan-Do> Yes, it is. Right now I have to do this ⏎ ⏎ client.before_request do |request| ⏎ request.headers["Cookie"]=URI.decode_www_form(request.headers["Cookie"]) ⏎ end [https://gitter.im/crystal-lang/crystal?at=5f5a54c789b38d09211c43ad]
<FromGitter> <Dan-Do> Can we have an option to tell client not encode, something like: ⏎ ⏎ ```client.encode_cookie = false``` ⏎ ⏎ Right now it's hidden, we have no idea about the encoding of cookie until looking at/debugging the source code. [https://gitter.im/crystal-lang/crystal?at=5f5a5622f51808513b34f5c0]
<FromGitter> <grkek> How does one define a heredoc?
<FromGitter> <grkek> How to make my own heredoc
<FromGitter> <grkek> My own heredoc identifier?
<FromGitter> <Blacksmoke16> just change it to whatever you want
<FromGitter> <Blacksmoke16> `<<-FOO`
<FromGitter> <grkek> Oh nice :)
<jhass> just make one up, the token is <<-
<FromGitter> <grkek> Can I do something like JSX in crystal?
<FromGitter> <Blacksmoke16> heredocs support interpolation if thats what you mean
<FromGitter> <grkek> No, what I mean is that
<FromGitter> <grkek> can I literally write
<FromGitter> <grkek> <Box></Box> as crystal syntax
<FromGitter> <grkek> return <Box/>;
<FromGitter> <grkek> the semicolon slipped sorry :p
<jhass> no
<FromGitter> <grkek> Why not?
<jhass> because nobody wrote a preprocessor and tooling around it that would allow it
<FromGitter> <grkek> Damn it
<FromGitter> <Dan-Do> I am interesting in web javascript front-end preprocessor too :)
<FromGitter> <grkek> It would be interesting if I wrote a preprocessor for it tbh
<FromGitter> <grkek> just imagine building guis
<FromGitter> <Dan-Do> We already had shards as: Jinja(Twig)/Crinja, Mustache/Crustache
<FromGitter> <grkek> Meh they don't look as comfy as jsx
<FromGitter> <Dan-Do> Hint for you, shard "crystal-nodejs". With that I render the front-end code on server side. So, one code for both front/back end
<FromGitter> <Dan-Do> lol
alexherbo26 has joined #crystal-lang
alexherbo2 has quit [Read error: Connection reset by peer]
alexherbo26 is now known as alexherbo2
alexherbo24 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 246 seconds]
alexherbo24 is now known as alexherbo2
alexherbo2 has quit [Ping timeout: 256 seconds]
alexherbo2 has joined #crystal-lang
lunarkitty has joined #crystal-lang
lunarkitty is now known as lunarkitty7
alexherbo2 has quit [Ping timeout: 260 seconds]
<raz> grkek: JSX is ultimately just syntactic sugar for a method call. can be done with a simple string preprocessor easily.
<raz> but copying ideas from javascript is usually a bad idea. because their ideas tend to be bad. all of them.
<raz> in fact, if you were to design a language with the only goal of making it the exact opposite of javascript in every way, it would probably become a pretty good language
sagax has quit [Remote host closed the connection]
sagax has joined #crystal-lang
sorcus has quit [Ping timeout: 240 seconds]
sorcus has joined #crystal-lang
sorcus has quit [Ping timeout: 244 seconds]
postmodern has joined #crystal-lang
sorcus has joined #crystal-lang
sorcus has quit [Ping timeout: 272 seconds]
sorcus has joined #crystal-lang
<FromGitter> <wyhaines> I haven't put too much thought into it, but I think that one could build a JSX-like templating library, using Crystal, without doing anything very esoteric.
<raz> well, to each their own. i hate such language mixes with passion. editors and linters struggle. humans struggle with the inevitable rabbit holes of nested complexity. etc.
duane has quit [Ping timeout: 265 seconds]
duane has joined #crystal-lang