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/
break
statement break from the first while
in its dynamic scope? Or are blocks handled specially by inlining to allow loop
to have a block with a break
statement?
I'm curious how loop
works then. In code like
loop do
break
end
wouldn't the break exit the yield block and then just continue the loop?
initialize
vs new
, despite reading the docs and fully understanding what is written.
initialize
with a block as opposed to new
void x_initialize(X *x) {
// set all the stuff in x, which was uninit memory
}
X *x_new() {
X *x = malloc(sizeof(X));
x_initialize(x);
return x;
}
def initialize(@x, @y); end
def self.new(value : T = 0.0)
new value, value
end
def initialize(@x, @y); end
def initialize(value = 0.0)
initialize(value, value)
end
initialize
from now on unless I need to change the allocation strategy.
new
method that prompted this question early today? def self.new(&)
res = new
res.each_index { |i| res[i] = yield i }
res
end
Indexable
I do this to allow passing a block
def self.rand(min : T = 0.0, max : T = 1.0)
new { Random.rand min..max }
end
def self.rand(min : self = ZERO, max : self = ONES)
new { |i| Random.rand min[i]..max[i] }
end
include
vs extend
?
Which makes me curious about this
def something
yield
end
def pass
something { yield }
puts "hey"
end
pass do
break
end
does it print "hey"?
next