On Mon, Nov 2, 2015 at 3:17 PM, Cedric St-Jean <[email protected]> wrote:
> immutable Bird
>    height::Float32
> end
>
> immutable Cage
>    bird::Bird
> end
>
> function catch(some_bird::Bird, some_animal)
>     new_bird = Bird(10.2)
>     c = Cage(b)
>     ...
>     new_bird
> end
>
> catch(b,b)
>

Assuming by boxed you mean gc allocation (which is the only time it is
stored as a tagged value in memory).

> 1. When are immutable values boxed? Is new_bird a boxed value? What about
> `some_bird` and `some_animal`?

They are boxed when it is necessary. For pretty much all the three
variables you have above, there isn't enough info to tell whether they
will be boxed.
With the current typeinf/codegen, they will be boxed if the variable
is not type stable.

> 2. I assume that Cage.bird is stored as an immediate value (no pointer).
> Isn't there a risk with large composite types that this is memory and CPU
> inefficient, having to copy it everywhere? Is that a consideration in

No, codegen will figure out the best way to pass them around.

> choosing immutable vs. type?

No.

In general, boxing is not what you need to think specifically about.
(You'll probably want to worry about type stability.)

>
> Cédric

Reply via email to