On Sat, May 7, 2011 at 3:12 AM, Zhe Hu <iammegat...@gmail.com> wrote:
> what's the difference between:
> V{ } clone 3 suffix!
> V{ } 3 suffix!
> I guess my question is why do we need "clone", since it takes one object,
> but puts back just one object.

V{ } creates a literal vector and pushes it on the stack. When typing
at the listener this doesn't make much difference from using 'clone'
with it. But when used in a function it makes a big difference. Try
this:

: my-vec ( -- v ) V{ } ;
: my-vec2 ( -- v ) V{ } clone ;

my-vec 3 suffix! drop my-vec .
my-vec2 3 suffix! drop my-vec2 .

The V{ } creates a new vector and embeds that actual vector instance
in the function body. So the '3 suffix!' on my-vec actually modifies
the vector in the function body. Calling my-vec again shows the
modified vector.

Chris.
-- 
http://www.bluishcoder.co.nz

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to