Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 19:53
    straight-shoota synchronize #11207
  • 17:04
    straight-shoota synchronize #11139
  • 17:04
    straight-shoota synchronize #11207
  • 17:02
    straight-shoota synchronize #11297
  • 17:02
    straight-shoota synchronize #11207
  • 12:49
    straight-shoota closed #10889
  • 12:49
    straight-shoota closed #6498
  • 12:44
    straight-shoota closed #10377
  • 12:43
    straight-shoota closed #11265
  • 12:43
    straight-shoota closed #4704
  • 12:43
    straight-shoota closed #11262
  • 12:43
    straight-shoota closed #11253
  • 08:06
    straight-shoota synchronize #11343
  • 07:58
    straight-shoota closed #11344
  • 07:58
    straight-shoota closed #9519
  • 07:57
    straight-shoota synchronize #11289
  • 07:57
    straight-shoota synchronize #11325
  • 07:56
    straight-shoota synchronize #11321
  • 07:55
    straight-shoota synchronize #11288
  • 07:55
    straight-shoota synchronize #10889
George Dietrich
@Blacksmoke16
really could have each << on its own line as well
:shrug:
mfiano
@mjfiano:matrix.org
[m]
ah makes sense. Thanks a lot, night!
mfiano
@mjfiano:matrix.org
[m]
Going to have to figure out how to get the name of an ivar tomorrow...
George Dietrich
@Blacksmoke16
if you're iterating over @type.instnace_vars its just .name
mfiano
@mjfiano:matrix.org
[m]
in a {% for ivar in @type.instance_vars %} ... {% end %} I tried something like io << {{ivar.name}} << " " << {{ivar}} and got the value duplicated instead of the name, which makes me believe its a quoting issue, but I'm afk so I'll try any suggestions tomorrow.
George Dietrich
@Blacksmoke16
might need ivar.name.stringify
otherwise it'll prob invoke the getter instead of the name
mfiano
@mjfiano:matrix.org
[m]

I woke up today with a couple questions:

1) Why isn't #[]= included in indexable? Do I always have to implement this if it is always the same (apart from assigning) as #unsafe_fetch?

2) If I have a struct with an array as its only ivar, is there a more convenient way to make the struct Indexable besides defining #unsafe_fetch that just forwards to the array's version? I'm not really familiar with delegates but thinking they are the key here.

mfiano
@mjfiano:matrix.org
[m]
I see how delegate is used now, and it is the answer to #2. New question: Is there a technical reason why the #[]= methods with Range parameters from Array are not included for StaticArray (or a Slice of one)? I'm sad I can't assign into subranges of a homogeneous array.
oprypin
@oprypin:matrix.org
[m]
mfiano: indexable is about ability to read by index. ability to write by index wasn't seen as common enough and big enough to implement a generic module for
mfiano
@mjfiano:matrix.org
[m]
Fair enough. Any reasoning for only being able to write a single index with StaticArray?
oprypin
@oprypin:matrix.org
[m]
mfiano: ability to assign to a range is very powerful and includes resizing of the array.
staticarray can't be resized so there would be too many cases where the only way out would be too raise a runtime exception in the general case
mfiano
@mjfiano:matrix.org
[m]
That is true. If it's doing bounds checking already though, it can be implemented for SA to not dynamic grow the heap memory (since it's not heap memory)
It is looking like my types are going to be structs wrapping a regular dynamic Array then
I might pay for allocation/fragmentation with lots of objects, so not sure yet though
Emilia
@rymiel:rymiel.space
[m]
Regarding the discussion in crystal#10976 is the cause behind the invalid memory access of some actions unknown? Do these segmentation faults happen in practice or is the CI just overwhelmed? Sad to see everything with a red cross :(
FlowerBrackets - code here
@BracketsFlower_twitter
Hey you can refer this resource on System arraycopy() method in java - https://www.flowerbrackets.com/system-arraycopy-method-java/
mfiano
@mjfiano:matrix.org
[m]
Where is the macro control flow and other keywords listed in the docs, such as {% for ... %}
mfiano
@mjfiano:matrix.org
[m]
Hmm I suppose there is no repeat loop
George Dietrich
@Blacksmoke16
hm?
mfiano
@mjfiano:matrix.org
[m]
Trying to generate a call to initialize value, value, value where the number of "value"s is the length of the splatted macro argument
Hmm, I guess I could do this, but it seems macro writing in Crystal is a lot of DRY violations, unless I'm not experienced.
  private macro make_accessors(*names)
    {% for name, i in names %}
      def {{name}}
        @data[{{i}}]
      end
      def {{name}}=(value : Float64)
        @data[{{i}}] = value
      end
    {% end %}
  end

  private macro make_constructors(*names)
    def initialize({% for name in names %} {{name}} : Float64, {% end %})
      {% for name, i in names %}
        @data[{{i}}] = {{name}}
      {% end %}
    end
    def initialize(value : Float64 = 0.0)
      initialize({% for name in names %} value, {% end %})
    end
  end

  make_accessors x, y, z
  make_constructors x, y, z
mfiano
@mjfiano:matrix.org
[m]
Just seems odd that I have to bind a variable to iterate N times, and I can't even use an underscore
(line 19 above)
mfiano
@mjfiano:matrix.org
[m]
My first library is finished, code-wise, and I'm pretty happy with it. I still have to do docs and specs which will take a long time given the number of defs, but yay
George Dietrich
@Blacksmoke16
nice one!
mfiano
@mjfiano:matrix.org
[m]
I saved a considerable amount of complexity and duplicated code by wrapping a staticarray and forwarding missing, instead of all the nonsense i had to do before
i think srasu suggested that, or whoever it was, thanks
oh i guess it's suskeyhose over on gitter
Is there a recommended style guide apart from the rather short one on the web site? I was looking to see what magic number this language recommends for max columns :)
George Dietrich
@Blacksmoke16
i dont think there is one
i usually just make it so i dont have to scroll :p
mfiano
@mjfiano:matrix.org
[m]
Well, I hope the macro writing DSL grammar is on the list of things to improve. This is definitely not as powerful as Lisp.
George Dietrich
@Blacksmoke16
only related things that i know of are like crystal-lang/crystal#8835 and crystal-lang/crystal#9802
From IRC (bridge bot)
@FromIRC
<riza> @mjfiano - what are you looking for that you aren't finding?
mfiano
@mjfiano:matrix.org
[m]
I mentioned one thing just below the code snippet above
methods in macro land is the issue discussing most of my concerns though
George Dietrich
@Blacksmoke16
yea it uses a subset of the stdlib methods
From IRC (bridge bot)
@FromIRC
<riza> ah yeah, for sure.
George Dietrich
@Blacksmoke16
fwiw i think you can improve this a bit
From IRC (bridge bot)
@FromIRC
<riza> the inability to repeatedly inject a macro has suffered me many times
mfiano
@mjfiano:matrix.org
[m]
I get that nothing can possibly be as powerful as Lisp, without actually being Lisp, because once you add homoiconicity to a language that enables powerful macros taking advantage of the full language instead of a DSL, you can practically call it a Lisp
But a little more will go a long way
However, despite being a huge Lisp fan, I stay away from macros unless I have to, unlike a lot of people that grow old trying to bend the language to do cool new things. However, when I actually do need to write a macro for some syntactic abstraction or boilerplate reduction, I need access to the language at compile time, not some tiny subset of it.
George Dietrich
@Blacksmoke16
fwiw you could do like {% for i in 0..4 %}
mfiano
@mjfiano:matrix.org
[m]
I am by no means trying to bash Crystal though. Its balance of simplicity and power is what drove me to try it, and I am very pleased with that. Lisp is pretty much 1000% power.
Yes, the "loop n times" instead of "loop over some collection/range" can be simulated like that, though I would have liked to use _ in place of i to convey meaning to the reader.