snsei has quit [Remote host closed the connection]
duane has quit [Ping timeout: 248 seconds]
duane has joined #crystal-lang
<FromGitter>
<CreationFox> Hi, I'm new to crystal. I keep seeing these things where they have a variable name in || symbols, for example, `|x|`. I can't find the documentation reference as to what this does, could someone point out what it is and what it does for me?
<FromGitter>
<AZanellato> That is passing that variable to a block
<FromGitter>
<AZanellato> if you have an array of numbers, for example, numbers = [1, 2, 3, 4, 5]
<FromGitter>
<AZanellato> you can do numbers.each { |n| puts n}
<FromGitter>
<CreationFox> Ok, so, if I'm understanding correctly, it's like in C++ when you load arguments into a function?
<FromGitter>
<CreationFox> Let me be more specific.
<FromGitter>
<AZanellato> Kindof, yeah.
duane has quit [Ping timeout: 248 seconds]
<FromGitter>
<AZanellato> it is similar to the calling of a function in C++, except here the function before the block determines which arguments it will supply to it
<FromGitter>
<AZanellato> it isn't you giving |x| to each
<FromGitter>
<AZanellato> but `each` giving you a variable, that you name it `x `
<FromGitter>
<AZanellato> does that make sense?
duane has joined #crystal-lang
<FromGitter>
<CreationFox> Alright, I think I'll try it out to make sure I can understand.
pabs has quit [Ping timeout: 240 seconds]
pabs has joined #crystal-lang
duane has quit [Ping timeout: 264 seconds]
pabs has quit [Ping timeout: 240 seconds]
pabs has joined #crystal-lang
pabs has quit [Ping timeout: 260 seconds]
pabs has joined #crystal-lang
_whitelogger has joined #crystal-lang
akaiiro has quit [Remote host closed the connection]
sz0 has joined #crystal-lang
<FromGitter>
<S-YOU> Figured that h2o to run without libuv, and it is even faster (upto 150k/s on my machine, with libuv was 120k/s)
baweaver is now known as baweaver_away
<FromGitter>
<codenoid> hi
<FromGitter>
<codenoid> how to generate random word
<FromGitter>
<fgimian> this simply creates an instance variable for each, does some validation and sets the appropriate default value or nil if there isn't one
<FromGitter>
<fgimian> what I'm attempting to do next (hence my question above), is generate a method which does something like this β β ``` def arguments β {name: @name, state: @state, options: @options} β end``` [https://gitter.im/crystal-lang/crystal?at=5b1ba4630b75bc7d5af6a171]
<FromGitter>
<fgimian> which I will use when printing out to the user what they've passed in
<FromGitter>
<fgimian> I realised that instance_vars is a bad idea, because I could potentially define my own additional instance_vars for internal processing
<FromGitter>
<fgimian> so I just need to think of a nice way that I can use macros to build an array of argument names, and then return them using their `@bla` instance variable in a named tuple as shown above
* FromGitter
* fgimian hopes that makes some sense ... :)
<FromGitter>
<fgimian> was just re-reading the docs on macros to understand what they can do and how one could approach this problem with them
<FromGitter>
<S-YOU> agree that instance_vars may be not for all use cases. β I am not sure, I understand what is result you are trying to achieve.
<FromGitter>
<S-YOU> it is something equivalent from python or ruby?
<FromGitter>
<fgimian> nah not quite, I'm just trying to design a DSL so that authors can write "actions" without having to do much work
<FromGitter>
<fgimian> I just want them to be able to define their arguments, and then a run method that does tho work
<FromGitter>
<fgimian> I'll try this a bit longer and I'll push up some code to GitHub soon, perhaps I'll share it here if I'm still stuck to get a second opinion
<FromGitter>
<fgimian> I could potentially do it like that actually, I was trying to make it one call per arg, similar to admiral.cr
<FromGitter>
<fgimian> I'm using its code as a reference for some ideas π
<FromGitter>
<fgimian> I'll get there, i'm really close
<FromGitter>
<S-YOU> Interesting idea
<FromGitter>
<fgimian> yeah, I'll share when I'm done for sure
<FromGitter>
<fgimian> so I got it going, I had to store the names in a class constant and then, the trick was to use the `{% begin %}` block to build a valid named tuple
<FromGitter>
<S-YOU> I see. I don't know why it requires begin end though.
<FromGitter>
<fgimian> me either but that seems to do the trick π
faustinoaq has joined #crystal-lang
<faustinoaq>
Crystal is awesome! (testing IRC bridge, ignore me :-P)
<FromGitter>
<fgimian> Crystal is awesome indeed π
<faustinoaq>
Interesting, JVM and .NET Frameworks on TFB use an entire test only for plaintext and another just for json, like `aspnet-core-plaintext` and `aspnet-core-json`, `<@jvm-framework-here>-plaitext`, etc
<faustinoaq>
Crystal on TFB is using just one app to accomplish all tests, maybe we can create `crystal-plaintext`, `crystal-json`, etc WDYT?
<faustinoaq>
This can ensure the compiler is optimizing the app to be fast in just one test at time :)
<FromGitter>
<mvlootman> @faustinoaq You use both Crystal (personal projects) and .Net/C# (work), right? What do you think are advantages of using Crystal over .Net? Is it just a language preference?
<faustinoaq>
Yep, I use .NET at work and at uni, C# and VB (even F#) are very nice, they have a great toolbox, high demanded, cross-platform and fast, very fast :), although...
<faustinoaq>
The .NET environment is a bit tricky in some ways (same as JVM)
<FromGitter>
<j8r> @fgimian You need `{% begin %} and {% end %}` because inside `{ {% for ... end%} }` isn't valid Crystal code, but a macro that generate one.
<faustinoaq>
Crystal feels more friendly and robust, so is easier to code my ideas with a bit of safety :)
<FromGitter>
<mvlootman> I like the syntax of Crystal and start to dislike C# more with the addition of more and more features.
<FromGitter>
<mvlootman> I hope Crystal gets mature enough v1.0 so it can handle compilation of big projects without memory/compilation time issues
<faustinoaq>
Yeah, Writing an algorithm in Crystal is way easier (like Python, Ruby) than Java or C#/VB. Crystal has a dynamic feel with types and fast execution :)
<faustinoaq>
@mvlootman I think we can achieve that by cleaning up the language and removing a lot of things that are making crystal slow at compile time.
<FromGitter>
<mvlootman> Currently working with Go, but that is mainly because of Crystal not reaching 1.0. Also golang has a bigger reach, for instance support on AWS serverless. I think Crystal could be a good fit there too.
<faustinoaq>
"...Remove inessential or redundant language features.."
<FromGitter>
<mvlootman> yes I read that. But also read some Gitter messages from Ary, that worried me a little, like full type inference was perhaps a hinderance (compile time/memory)
<faustinoaq>
Yeah, crystal is very young, we still need to enhance/fix/implement a lot of things to be stable enough ;-)
<FromGitter>
<mvlootman> But I keep coming back to look at how Crystal is doing, because it still appeals to me very much. π
faustinoaq has quit [Ping timeout: 264 seconds]
faustinoaq has joined #crystal-lang
<faustinoaq>
@mvlootman I also was worried about that. Don't pay attention to Ary :-P, He had some ups and downs with crystal ;-)
<FromGitter>
<S-YOU> I am curious of LOC of each sources on TFB, crystal might be be one of the cleanest implementation out there.
<FromGitter>
<mvlootman> benchmark results should also show memory / cpu usage to do a fair comparison
Groogy has joined #crystal-lang
<FromGitter>
<fgimian> Just another question from me, suppose we have a union type of `Array(String) | Nil` and I'm certain that the data in there is an `Array(String)`; how do I force it to be turned into that type so that all related methods work?
<FromGitter>
<fgimian> actually never mind, I found my problem
<FromGitter>
<fgimian> my value was actually nil, which was causing my problem
<FromGitter>
<j8r> I'm near to an initial release, it will be close to nano/micro at first. I'm still to figure out how Termbox works under the ground, there are lines that disapear and redraw incorectly
<FromGitter>
<fgimian> perhaps I've tried to abstract too much away with macros or DSLs
<FromGitter>
<fgimian> I should say in advance, *please forgive me* if I've done some terrible things ... I'm still trying to get to grips with Crystal and expect that I would have done some things badly which I'll laugh about in a few months π
<FromGitter>
<fgimian> which of course makes sense
<FromGitter>
<fgimian> but I'm trying to write a DSL similar to Ruby-land
<FromGitter>
<j8r> can you `@options : Array(String) = Array(String).new`?
<FromGitter>
<fgimian> let me try
That_Guy_Anon has quit [Ping timeout: 265 seconds]
<FromGitter>
<fgimian> hmm that does actually work
<FromGitter>
<fgimian> not a bad idea really
<FromGitter>
<j8r> To explain, you have to specify a default value
<FromGitter>
<j8r> Because it may not be initialized, like the error told, therefore rendering it nil
<FromGitter>
<fgimian> yeah
<FromGitter>
<fgimian> I like your idea because it makes it easy to incorporate into my macro
<FromGitter>
<fgimian> of course, the only tricky thing will be stuff like an Int which will default to 0 I assume
<FromGitter>
<j8r> you can also do this inside a `def initialize(@options = Array(String).new); end`
<FromGitter>
<fgimian> yeah, sadly that's a lot harder to generate with the macro
<FromGitter>
<fgimian> because I run the macro for each "argument"
* FromGitter
* fgimian hopes that makes sense
<FromGitter>
<fgimian> let me try your approach though, perhaps it'll get me through
<FromGitter>
<fgimian> it may not work for certain types it seems, like Ints .etc, I'll need to deal with those differently
<FromGitter>
<j8r> You need Ints?
<FromGitter>
<fgimian> well, ultimately each action can do anything, e.g. installing a Homebrew package, creating a file, updating a plist file .etc .etc, so in theory, yeah, the parameters can be of any type
<FromGitter>
<fgimian> depending on the action
<FromGitter>
<fgimian> maybe I need to go back to the drawing board on this π
<FromGitter>
<fgimian> I have done it successfully with Python, but of course, that doesn't care about types much π
<FromGitter>
<fgimian> in Python I simply set all unset values to `None` (same as `nil`) and then check if the argument had any data with a conditional
<FromGitter>
<fgimian> ultimately I would face a similar challenge in any typed language, so just need to maybe rethink my approach
<FromGitter>
<j8r> `crystal tool format` may fix this... I guess
<FromGitter>
<fgimian> haha yep, that's a direct port of my original code
<FromGitter>
<fgimian> will do that now, sorry, I'm still getting to grips with it
<FromGitter>
<j8r> no worry, that's fine :-)
<FromGitter>
<fgimian> π
<FromGitter>
<fgimian> oh haha, the format tool didn't change anything
<FromGitter>
<fgimian> except aligning one comment
<FromGitter>
<j8r> If you do system things, when you will need Ints? All is string?
<FromGitter>
<fgimian> but I'll switch to a case statement for sure
<FromGitter>
<fgimian> I'll need to double check my original implemented actions to see if I used ints to be honest
<FromGitter>
<fgimian> I definitely use booleans, strings and arrays of strings
<FromGitter>
<j8r> you can also use Strings everywhere and cast when needed
<FromGitter>
<fgimian> My original implementation has 29 actions for many things, npm, pip, brew, brew cask, brew tap, files, archives .etc .etc
<FromGitter>
<fgimian> true
<FromGitter>
<fgimian> I'm essentially developing something like Chef ... but specifically for configuring Macs
<FromGitter>
<fgimian> hehehe
Raimondii has joined #crystal-lang
<FromGitter>
<fgimian> most params are strings, that's true though
<FromGitter>
<fgimian> just checking my original code now
<FromGitter>
<fgimian> yeah, looks like only 1 - 2 parameters were ever ints, the main one was I have an action for manipulating JSON files and I pass the indent level in as a int
<FromGitter>
<j8r> That's interesting π How is the configuration?
<FromGitter>
<fgimian> well, in my original implementation, the config was mostly YAML
<FromGitter>
<fgimian> however, my idea in Crystal is to do it ... IN Crystal
DSNTravellerbot[ has quit [Ping timeout: 256 seconds]
kp666[m] has quit [Ping timeout: 256 seconds]
kixune[m] has quit [Ping timeout: 256 seconds]
cptaffe has quit [Ping timeout: 276 seconds]
jokke2 has quit [Ping timeout: 240 seconds]
jokke2 has joined #crystal-lang
That_Guy_Anon has joined #crystal-lang
pabs has quit [Ping timeout: 265 seconds]
pabs has joined #crystal-lang
pabs has quit [Ping timeout: 255 seconds]
pabs has joined #crystal-lang
GoldenBear has quit [Ping timeout: 245 seconds]
olbat[m] has joined #crystal-lang
<crystal-gh>
[crystal] RX14 closed pull request #6160: Allow redefining None to 0 for @[Flags] enum (master...allow-redefine-None-to-0-in-enum-flags) https://git.io/vhly9
akaiiro has joined #crystal-lang
pabs has quit [Ping timeout: 240 seconds]
mech422 has joined #crystal-lang
<mech422>
Hi All - stupid question, but I can't find it in the 'syntax and semantics' doc - what do '|' symbols do? as in: thrice do |i|...
<mech422>
seems to be some sort of variable declaration ? (you can refer to it in the do block..) or is it just the receiver for the yield statement ?
pabs has joined #crystal-lang
<FromGitter>
<paulcsmith> Is there a built-in way to detect what OS Crystal is being run on? I'm trying to load a binary depending on whether the user is on Linux or Mac and hoping something is built-in but I don't see anything in the docs
<RX14>
well, people are free to do whatever they want but snaps are terrible
snsei has joined #crystal-lang
<akaiiro>
faustinoaq snaps and flatpacks are awful. appimages seem nice
<RX14>
they're all bad tbh
<RX14>
just make distro packages
<RX14>
its not that hard
pabs has quit [Ping timeout: 240 seconds]
pabs has joined #crystal-lang
<faustinoaq>
RX14 Oh ok :)
<FromGitter>
<j8r> Hum ok @RX14 you have to use fpm or package it to deb, rpm, apk, and pkgbuild - and deal with the dependency hell. If you have lots of dependencies, good luck π
<RX14>
nope
<RX14>
you make your software packageable
<RX14>
and wait for the distro maintainers to do the work
<RX14>
I wish :)
<FromGitter>
<j8r> If you have e.g. Centos 6 and wants new libs?
<RX14>
but really fpm isn't so hard to use
<RX14>
and if you make one self-contained tarball it's super easy to unpack it into /usr
<RX14>
and make sure you comply with FHS
<RX14>
then a few tweaks to man and licence files per distro, maybe docs and you're all set
<FromGitter>
<j8r> That's a bit like an appimage a self-contained tar.gz. Please do not untar it to /usr, you may mess up your system OMG β
<FromGitter>
<j8r> `/usr/local` at least
<FromGitter>
<j8r> but anyway, appimages have their uses for desktop apps. But on the server side, this is another story
<RX14>
no
<RX14>
you untar to /usr in the package build directory
<RX14>
then the package contains the tar contents at /usr
<RX14>
and thats fine
<RX14>
thats exactly how I built the new crystal packages:
<RX14>
i built a tar.gz with a statically-linked compiler that conformed to the FHS, then untarred the tar.gz into /usr, fiddled around with the files a bit to conform to the letter of the per-distro packaging guidelines
<RX14>
and then packed it up
<RX14>
untarring into /usr is only bad if it's actually /usr not $PKGROOT/usr :)
<FromGitter>
<j8r> But the `/usr` may be modified by system packages. And you tar.gz isn't a dist package, you can have problems
<FromGitter>
<j8r> nothing tells the system you have actually untarred :-/
<FromGitter>
<j8r> haa ok `$PKGROOT/usr :`
<FromGitter>
<j8r> got itΓΉ
<FromGitter>
<j8r> Too bad we aren't on BSD
<FromGitter>
<j8r> You can install packages as user - and eventually do messy things without impacting the OS. Why the hell we need to be root on linux :3