Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 04 22:42
    straight-shoota closed #12800
  • Dec 04 22:41
    straight-shoota edited #12800
  • Dec 04 22:41
    straight-shoota closed #12770
  • Dec 04 22:41
    straight-shoota closed #12773
  • Dec 04 20:38
    straight-shoota closed #12819
  • Dec 04 17:58
    HertzDevil synchronize #12784
  • Dec 04 15:51
    Blacksmoke16 review_requested #10648
  • Dec 04 15:50
    Blacksmoke16 synchronize #10648
  • Dec 04 15:48
    Blacksmoke16 synchronize #10648
  • Dec 04 15:00
    Blacksmoke16 closed #12820
  • Dec 04 11:38
    straight-shoota closed #12807
  • Dec 04 11:38
    straight-shoota closed #12808
  • Dec 04 11:38
    straight-shoota closed #12816
  • Dec 04 00:00
    douglascamata closed #12820
  • Dec 03 23:10
    Blacksmoke16 closed #12821
  • Dec 03 23:10
    Blacksmoke16 labeled #12821
  • Dec 03 23:09
    Blacksmoke16 labeled #12821
  • Dec 03 22:13
    hutou labeled #12821
  • Dec 03 22:13
    hutou opened #12821
  • Dec 03 22:01
    douglascamata edited #12820
George Dietrich
@Blacksmoke16
Probably would need to add some of that in like in the SO post
To see what the actual issue is
Paulo Coghi
@paulocoghi

Hello everyone!

Do you know how to inform that a functions parameter type is of a specific NamedTuple format? Or it isn't necessary?

For example:
def update(data : NamedTuple( id: Int32, json : String ) )
end
George Dietrich
@Blacksmoke16
does that not work?
Paulo Coghi
@paulocoghi
No
George Dietrich
@Blacksmoke16
whats the error?
Paulo Coghi
@paulocoghi
syntax error in 'STDIN:62:44': expected ')' or named argument, not json
George Dietrich
@Blacksmoke16
and how are you calling the method
ah nvm i see the issue
Paulo Coghi
@paulocoghi
Hmmm, maybe this is the reason. The function signature was different and I was updating it. The calling line wasn't updated
George Dietrich
@Blacksmoke16
it should be json: String not json : String
Paulo Coghi
@paulocoghi
Ah, ok!
Thanks a lot!
George Dietrich
@Blacksmoke16
tho i will say named tuples arent really meant to be used to model data as something you pass around
Paulo Coghi
@paulocoghi

ah nvm i see the issue

Exactly. This was the issue

Thanks a lot again!
George Dietrich
@Blacksmoke16
consider using a struct like record Data, id : Int32, json : String then update(data : Data) or something like that
Paulo Coghi
@paulocoghi
Interesting! I will do that :)
From IRC (bridge bot)
@FromIRC
<renich> Hey Blacksmoke16, found where to submit errata for the book: https://www.packtpub.com/support/errata
George Dietrich
@Blacksmoke16
:thumbsup: thanks
Renich
@Renich:matrix.org
[m]
You're welcome.
hellstabber
@_xmpp_hellstabber=40404.city:matrix.org
[m]
Hi
Is there a book you can recommend to learn crystal?
2 replies
Quinton Miller
@HertzDevil
Using compiled compiler at .\.build\crystal.exe
icr:1:0> 1
=> Invalid memory access (C0000005) at address 0x20
[0x7ff658127842] GC_realloc +82 in C:\Users\Quinton\crystal-win\.build\crystal.exe
[0x7ff6552f65e9] realloc at C:\Users\Quinton\crystal-win\src\gc\boehm.cr:139
[0x7ff655211a78] __crystal_realloc64 at C:\Users\Quinton\crystal-win\src\gc.cr:46
[0x7ff656121ae3] interpret at C:\Users\Quinton\crystal-win\src\compiler\crystal\interpreter\interpreter.cr:322
[0x7ff6560d7518] interpret at C:\Users\Quinton\crystal-win\src\compiler\crystal\interpreter\interpreter.cr:227
[0x7ff65641175b] to_s at C:\Users\Quinton\crystal-win\src\compiler\crystal\interpreter\interpreter.cr:153
[0x7ff655403b75] << at C:\Users\Quinton\crystal-win\src\io.cr:174
[0x7ff655403b1f] puts at C:\Users\Quinton\crystal-win\src\io.cr:231
[0x7ff655247601] puts at C:\Users\Quinton\crystal-win\src\kernel.cr:386
[0x7ff6565ece76] run at C:\Users\Quinton\crystal-win\src\compiler\crystal\interpreter\repl.cr:87
[0x7ff65657833a] repl at C:\Users\Quinton\crystal-win\src\compiler\crystal\command\repl.cr:10
[0x7ff656573199] run at C:\Users\Quinton\crystal-win\src\compiler\crystal\command.cr:100
[0x7ff656572b6d] run at C:\Users\Quinton\crystal-win\src\compiler\crystal\command.cr:51
[0x7ff656572adc] run at C:\Users\Quinton\crystal-win\src\compiler\crystal\command.cr:50
[0x7ff655211945] __crystal_main at C:\Users\Quinton\crystal-win\src\compiler\crystal.cr:11
[0x7ff65547d8d3] main_user_code at C:\Users\Quinton\crystal-win\src\crystal\main.cr:115
[0x7ff65547d7ea] main at C:\Users\Quinton\crystal-win\src\crystal\main.cr:101
[0x7ff655227559] main at C:\Users\Quinton\crystal-win\src\crystal\main.cr:127
[0x7ff655227673] wmain at C:\Users\Quinton\crystal-win\src\crystal\system\win32\wmain.cr:35
[0x7ff65819ed74] __scrt_common_main_seh at d:\a01\_work\43\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
[0x7ffcc2807034] BaseThreadInitThunk +20 in C:\WINDOWS\System32\KERNEL32.DLL
[0x7ffcc36a2651] RtlUserThreadStart +33 in C:\WINDOWS\SYSTEM32\ntdll.dll
1 reply
almost there...
Jordan Ellis Coppard
@tsujp

I can't seem to get this string builder to work?

String.build do |io|
  Dir.current.rpartition('/').each do |x|
    io << x
  end

  puts io
end

Running it prints

#<String::Builder:0x100693f60>

Isn't it supposed to print the contents of the string? In this case I expect it to print /Users/tsujp/crystal_prompt

Jordan Ellis Coppard
@tsujp
Ohhhhhhhhhhhhhhh it needs to go outside the block derp and I need to set the return of the evaluation of that block also, so
foo = String.build do |io|
  Dir.current.rpartition('/').each do |x|
    io << x
  end
end

puts foo
Ali Naqvi
@naqvis
how to call overridden parent class method from different method?
class Foo
  def test
    "Foo test"
  end
end

class Bar < Foo
  def test
    "Bar test"
  end

  def bar
    # call parent.test
  end
end

pp Bar.new.call # => Should print "Foo Test"
Ali Naqvi
@naqvis

typo in above code

pp Bar.new.call => pp Bar.new.bar

Ali Naqvi
@naqvis
Thanks @Blacksmoke16
From IRC (bridge bot)
@FromIRC
<riza> is there a way to print what the compiler things is the list of types for a variable?
<riza> i feel like there is but i cant find the reference
Ali Naqvi
@naqvis
typeof ?
From IRC (bridge bot)
@FromIRC
<riza> yes that did it thank you @naqvis
<riza> searching the docs for type is useless
Ali Naqvi
@naqvis
:thumbsup:
stellarpower
@stellarpower
For the parent implementation, presumably you can't do
Bar.new.as(Foo).test
Syntax-wise, I'd also prefer Bar.new. Foo::test as opposed to lots of super or something, if that's parseable.
From IRC (bridge bot)
@FromIRC
<hightower2> Doesn't the last suggestion give an error tho? Copied from forum post: https://play.crystal-lang.org/#/r/dc2t
<hightower2> Aha sorry, the comment was meant to mean that it is possible in Ruby.
From IRC (bridge bot)
@FromIRC
<SamantazFox> Hello!
<SamantazFox> Is there a way to tell/hint the GC that something can be collected?
From IRC (bridge bot)
@FromIRC
<riza> my memory is, no there isn't
From IRC (bridge bot)
@FromIRC
<SamantazFox> aww :⁠/
From IRC (bridge bot)
@FromIRC
<riza> I have doubts you could get this to do anything useful: https://github.com/crystal-lang/crystal/blob/1.3.2/src/gc/boehm.cr#L160
From IRC (bridge bot)
@FromIRC
<SamantazFox> riza: hmmm, it just calls the libGC implementation?
<SamantazFox> so all memory management is done outside of crystal, right?

Try the online docs this are greate and maybe you can try this book to get a introductory of the language 🙂

https://www.packtpub.com/product/crystal-programming/9781801818674

I have only read the online docs : https://crystal-lang.org/reference/1.4/getting_started/
but the book is on my bucket-list ;D