Paste: hashtable + tuple question

Author: tylerg
Mode: factor
Date: Wed, 18 Feb 2009 01:23:54
Plain Text |
! sorry if this is not the best place to post this sort of question but here goes ( if there is a better place let me know )

! I'm trying to make a tuple with a hashtable for the initial value of one of the slots.  However, the initial keyword wants a literal value, so neither of these work

: TUPLE foo1 { table assoc :initial H{ } clone } ; 

: TUPLE foo2 { table assoc :initial 3 <hashtable> } ;

! And if I do this, every time I create all the foo3 objects that are created end up sharing the same hashtable

TUPLE: foo3 { table assoc :intial H{ } } ; 

! Is there a way to do this using the initial: keyword? 

Annotation: solution

Author: slava
Mode: factor
Date: Wed, 18 Feb 2009 03:14:58
Plain Text |
Right now the only solution is to define a constructor word,

TUPLE: foo4 table ;

: <foo4> ( -- foo4 ) foo4 new H{ } clone >>table ;

New Annotation

Summary:
Author:
Mode:
Body: