4 ms·
> it seems to prefer blocks to lambdas What does this mean?
by kbp 8y ago
> it seems to prefer blocks to lambdas
What does this mean?
- christophilus 8y agoCrystal prefers these constructs [0] `foo.map {|x| x + 1}` where the stuff between the squiggles is called a "block". I come from Ruby, so maybe Crystal got this one right, but Ruby blocks, at least, are a more limited, less general-purpose approach to lambdas (by which I mean anonymous, first-class functions + closures) [1]. [0] https://crystal-lang.org/docs/syntax_and_semantics/blocks_and_procs.html https://crystal-lang.org/docs/syntax_and_semantics/blocks_an... [1] https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions https://docs.microsoft.com/en-us/dotnet/csharp/programming-g...
- mirekrusin 8y agoCrystal has lambdas w/closures (called Proc) with `->{ 1 }` syntax [0]. Because of ruby-like syntax where `foo` is a call if `foo` is a function you need to do `foo.call` on those lambdas explicitly - so you can distinguish between passing them around as values `foo` and calling them `foo.call` or `foo.call(arg1, arg2, ...)`. I've played with it a bit, haven't seen problems with compile times, they were actually pretty good. The nice thing about Crystal is that it is extremely easy to use, terse code, easy macros, fast executables, algebraic types, good packaging story - in general very good ergonomy. I hope it'll pick up one day. [0] https://crystal-lang.org/docs/syntax_and_semantics/literals/proc.html https://crystal-lang.org/docs/syntax_and_semantics/literals/...