<jhass>
asterite: mmh is github just confused or did you click release and then put it back to a draft?
A124 has quit [Quit: '']
A124 has joined #crystal-lang
FromGitter has joined #crystal-lang
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
Oliphaunte has joined #crystal-lang
Oliphaunte has quit [Ping timeout: 258 seconds]
sandelius has joined #crystal-lang
<sandelius>
hey all
<sandelius>
I'm trying out crystal and are wondering how one would specify a class constant as a hash value? "an't use Class in unions yet, use a more specific type"
<jhass>
You have to use the specific metaclass of a base class
<jhass>
got some example of what you're trying to do?
<sandelius>
jhass some thing like @attributes = Hash(Symbol, Hash(Symbol, Array(Hash(Symbol, Class)))).new
<sandelius>
it's a nested hash
<jhass>
not "some like" please :/
<jhass>
what's the specific values you want to store and why
<jhass>
so do you have a common module or base class in all the valid rule_class'es?
<sandelius>
jhass no that's the problem :)
<jhass>
then you can't do it currently
<sandelius>
well I will if I must
<sandelius>
jhass, then I'll use an interface class for the rules
<sandelius>
jhass thx
<jhass>
and then your restriction is just Rule.class
<sandelius>
wow crystal has overloading :D
<sandelius>
I'm trying my best to NOT get over-excited about all this :)
bjz has joined #crystal-lang
<sandelius>
is there a way to let a method argument to be optional but accept different types if it's used? def method(type = nil) but accept symbol or string
cloud-oak has quit [Remote host closed the connection]
<RX14>
well
<RX14>
regarding that
<RX14>
i feel that the self there is ambiguous
<RX14>
and should not be allowed
<jhass>
well my Ruby roots say that class Foo < Bar is syntax sugar for Foo = Class.new(Bar)
<jhass>
:P
<RX14>
i never knew that
<RX14>
i came from java/C# then to ruby them crystal
<jhass>
(not in Crystal but in Ruby it pretty much is)
<RX14>
and a whole load sof other langauges inbetween
|2321 has joined #crystal-lang
<Yxhuvud>
one thing to remeber is that in ruby, the thing that is inherited from is an expression. you can totally write class Foo < [A, B].sample; end
<Yxhuvud>
and I'm not arguing for that to be legal :)
kfpratt has joined #crystal-lang
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
<miketheman>
hello!
<RX14>
jhass, how does the require "c/whatever" work in the stdlib? where's the lib defs?
<miketheman>
I tried to build crystal today from source (i.e. from scratch) - it appears that the process now requires an existing bootstrap version of crystal?
<jhass>
RX14: lib_c/arch and then we do some magic to add the right arch to the load path
<RX14>
ahh
<miketheman>
and I'm trying to figure out how to do it from scratch - i.e. as if crystal was never there
<jhass>
miketheman: well about two years now?
<miketheman>
jhass: sure, but there's no "start over, it'll take 4 hours, but it'll work" ?
<BlaXpirit>
miketheman, crystal is written in crystal, no other way
<jhass>
there's a ruby tag or so
<jhass>
but there's a couple of commits that need partial application iirc
<RX14>
which is disgusting
<jhass>
that is Ary did some stuff locally and uploaded a new binary that works :P
<BlaXpirit>
oh boy
<miketheman>
hahhaa. ok, that's fair.
<RX14>
should be a 2 part thing really somehow
<RX14>
jhass, i presume a write bounded IO would just discard anything written past the size...
<jhass>
mmmh
<jhass>
not sure
<jhass>
I think I'd prefer raising
<RX14>
there's nothing else really to do
<jhass>
just ignore the error if you want to
<RX14>
well
<RX14>
that seems to break the basic contract of an IO to me
<RX14>
i dunno
<jhass>
does it?
<RX14>
maybe we should just make it readonly
<jhass>
if you write and your disk gets full you get some Errno
<RX14>
i guess
<jhass>
already said I've no problem to start out with a readonly version ;)
<RX14>
yeah
<RX14>
I could make it so you could configure whether it throws or not
<jhass>
meh, no, not too many options
<jhass>
IMO it's a bug
<jhass>
if you think otherwise ignore the error I give you
<RX14>
what's a bug?
<jhass>
if somebody gives more data to write than there's "space"
greengriminal has joined #crystal-lang
<jhass>
write as much data as there's "space", raise if any is left afterwards
<RX14>
well i doubt a write sized IO would be of much use so i'll leve it out
<jhass>
<3
tomchapin has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<asterite>
I was just needing a size-limited IO some minutes ago, I think something like that should be in the standard library. I wonder about the name, though...
<RX14>
asterite, do you want me to PR it in by itself sooner then if you need one?
<asterite>
no, there's no hurry :)
<Yxhuvud>
one variant of writing past the io size would be to wrap around.
<jhass>
asterite: well we're still open to name suggestions, I think so far out of IO::Sized, IO::LengthBounded, IO::SizeBounded, IO::Sized wins
<RX14>
thats interesting
<RX14>
all it needs is some docs
<jhass>
supporting .rewind would be good
<RX14>
and the name becomes obvious
<jhass>
I think wrapping around would be malicious API design
<RX14>
jhass, hrrm
<RX14>
jhass, not by defauult
<RX14>
my modes
<jhass>
KISS
<RX14>
add more
<jhass>
add features as you have real world usecases
<jhass>
not prematurely
<RX14>
yes
<RX14>
i agree
<RX14>
I made the api be read_xxx so it's possible to add write_xxx methods later
<jhass>
huh?
<RX14>
read_size instead of size,
<jhass>
you should only need to implement read(Slice) and write(Slice) (to raise for now) and include IO
<RX14>
and pass close
<RX14>
and sync close
<jhass>
oh you mean the arguments in the constructor
<RX14>
and getter for read-remaining
<Yxhuvud>
why read_size instead of read(size) ?
<asterite>
IO::Limited ?
<asterite>
In Go it's called LimitedReader :-P
<jhass>
asterite: we want to add one that's limited by size and one that's limited by a boundary byte sequence
<RX14>
asterite, we were going to add a size bounded and content bounded reader
<RX14>
IO::Sized and IO::BOunded
<jhass>
so limited seems a bit ambiguous
<asterite>
I think bounded seems ambiguous too
<jhass>
I thought we were going for IO::Delimited there?
<RX14>
oh
<RX14>
we were
<RX14>
i thought it sounded off
<asterite>
mmm... how would you implement the bounded reader?
<jhass>
you're just trapped in mime/multipart terminology atm :P
<asterite>
read byte per byte until that byte is found? multipart is the use case?
<RX14>
asterite, we discussed this
<RX14>
last night
<jhass>
asterite: byte by byte and relying on the underlying IO to be buffered so it's fast
<RX14>
asterite, and yes multipart is the usecase
<asterite>
multipart doesn't come with the size of each part?
<RX14>
nope
<jhass>
there's no real smart way around it, at least we found none
<RX14>
if we know the underlying IO is buffered we could probably hack it around a bit
<RX14>
but nah
<jhass>
^
<RX14>
reading byte by byte should be fine
<RX14>
plus thats internal
<RX14>
if someone wants to have a crack
<RX14>
they can optimise it
<jhass>
yes, but for now KISS again
<RX14>
exactly
<asterite>
ugh, just saw the rfc... what were they thinking? :-)
<jhass>
"nobody's going to still use this in the 90s, it's fine for now"
<RX14>
asterite, it's not TOO bad
<RX14>
easier than parsing IRC
<jhass>
:D
<jhass>
MODE, my nemesis
* RX14
cries inside
<RX14>
and I didn't even write interpretation code
<RX14>
i literally just write a parser
<RX14>
it gives you the very raw parsing
<maxpowa>
at least MODE has a standard syntax
<maxpowa>
that pretty much all IRCds follow
<RX14>
at least IRC has a RFC
<jhass>
if it only weren't two commands actually
<jhass>
RX14: that nobody really follows :P
<tilpner>
And then people introduced CTCP quoting...
<maxpowa>
oh god dont get me started on CTCP bullshit
<maxpowa>
on another network there's a guy who thinks that everything can be solved with CTCP
<maxpowa>
it makes me cry
<RX14>
don't remind me lol
<BlaXpirit>
lol I just regex the PRIVMSG and ignore the rest
<RX14>
thats disgusting
<BlaXpirit>
nah I lie, gotta also respect the PING
<RX14>
regex for parsing :/
<jhass>
ya not parsing HTML with regex, yo?
<RX14>
or IRC
<BlaXpirit>
happens sometimes
<RX14>
I dislike using regex for parsing at all because I percieve it to be slow
<BlaXpirit>
that's true, but for parsing each individual token regex is not bad otherwise
<RX14>
would be nice if crystal accepted "-" to be stdin
<jhass>
mmh, does eval take --release?
<jhass>
I think it should
<RX14>
but multiline
<jhass>
crystal eval <<EOF
<RX14>
can't remmember how to multiline args
<RX14>
wait
<RX14>
eval takes stdin?
<jhass>
crystal eval should read from stdin with no code arg, yeah
<RX14>
NICE
<schovi>
Hello. I am learning macros and play around with "run(file)". I am stuck for really long time on problem, how to pass macro argument value into "run" command. There is example https://gist.github.com/schovi/e38a02d91f83a84ba72f8a39f46e5c92 I hope it is self explained. Question: How to pass variable value into "run" command.
<RX14>
jhass, looks like it doesn't take args at all
<jhass>
:(
<BlaXpirit>
schovi, you cannot pass a runtime value into a compile-time construct
<BlaXpirit>
do you expect to go into the past and change the way the program was compiled because your variable changed?
<RX14>
schovi, you
<RX14>
're essentially passing the string "variable" to the run program
<RX14>
jhass, i still feel {}.min is weird
<jhass>
I said debatable
<jhass>
on the plus side Ruby 2.4 optimizes [].min
<RX14>
this isn't ruby though
<jhass>
yes but it's not just me liking the construct :P
<BlaXpirit>
RX14, I don't like Math.min - what's so mathy about it?
<BlaXpirit>
it's a collection of items and you take the smaller of them
<schovi>
@BlaXpirit @RX14: Aha. Is there any way how to this? In my realcase i want to pass some filepath to load content of that file and save it inside some variable.
<asterite>
Why {...}.min is weird?
<RX14>
not what i'm used to
<RX14>
is all
<RX14>
which is a horrible reason
<schovi>
That mean, path to that file is known and unchangable during compile time.
<asterite>
ah, yes, in ruby [a, b].min is used all the time and I wasn't used to it at first
<jhass>
asterite: shall we drop Math.min/max ? :P
<BlaXpirit>
yes pls
<schovi>
Maybe store that in constant?
<RX14>
schovi, if you pass a constant into a macro you can get the value
<RX14>
like
<jhass>
call .resolve on it
<RX14>
that works?
<jhass>
yup
<RX14>
how does it fail though?
<BlaXpirit>
what fails
<RX14>
resolve
<jhass>
no method kind of error if it isn't a constant
<RX14>
ok
<jhass>
or Path rather
<BlaXpirit>
>> macro test(a); p {{a.resolve}}; end; A=5; test(A)
<sandelius>
I have a couple of questions. 1: does it matter in what order I require files/classes? 2: Is there a way to spawn workers to utilize multiple cores when using the web server?
<asterite>
maybe use a language where gender doesn't appear in words
<BlaXpirit>
sandelius, recently it started to seem to me like the order does not matter, it all ends up as if it was one big source file. and order does not matter within a source file either
<asterite>
I don't know if such language exists, though...
<BlaXpirit>
sandelius, spawn workers -- spawning processes would currently be the best bet
<BlaXpirit>
threadpool coming soon
<schovi>
It is little bit tricky, but I am able to resolve "relative" path (for example: git repository with library. path to file is same relative to repo root, but different relative to system root on different machines). it can be solved with load("../assets/file.png", __DIR__) which is macro with run call and then resolve path from these two arguments
<BlaXpirit>
I don't comprehend
<jhass>
asterite: English provides great workarounds without sounding too awkward actually :)
<jhass>
like singular they
<jhass>
german is a lot harder there :/
<jhass>
I wonder whether Lojban has gender
<jhass>
I wouldn't expect it to
pawnbox has quit [Remote host closed the connection]