The Crystal programming language | http://crystal-lang.org | Fund Crystal's development: http://is.gd/X7PRtI | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/
?.
instead of .try &
)
if foo = some_nilable
would be foo = some_nilable; if foo
(or maybe a dedicated assignment operator as @asterite mentioned)
if foo = anything
is not allowed at all. i imagine they may have had a similar discussion in their past)
if foo = nilable
instead of foo.try {}
list-style-type: lower-alpha
in CSS)
i += 1
by i = i.succ
makes it even more generically useful
brew install crystal
and with --build-from-source
T
is restricted to be of type Vec
, which is used for both arguments and the return type. How can I do similar with Crystal, without a type alias or relying on the inferred call site types?proc abs[T: Vec](o: var T, v: T): var T = ...
where
or even overloading forall
signature
where it belongs
def
instead of mine just generating the body, and I decided on mine, for a couple reasons. 1) The readability as mentioned. 2) I would like to selectively choose which ones to annotate as always inlined, 3) I would like to add additional logic to some methods.
I'm trying to write a class method that initializes an Indexable type with random floats.
def self.rand(min = 0.0, max = 1.0)
res = new
res.each_index { |i| res[i] = Random.rand min..max }
res
end
This works, but I am wondering if this can be done more concisely/in one line instead of 3. Don't really want to macro around this if the language has something I could use that I don't know about.