You can use "firstn" to get an arbitrary number of elements from a sequence
onto the stack, but I think that is often a sign of "bad" code.


http://docs.factorcode.org/content/word-firstn,sequences.generalizations.html

Also, your hashtable>cd word seems like it could be more clear if it were
something like:

    : hashtable>cd ( assoc -- cd )
        { [ "title" of ] [  "artist" of ] [ "rating" of ] [ "ripped" of ] }
<cd> ;

Regarding "auto-serialization" of objects into json, you can do something
like this, defining a tuple class "foo", then making one, converting it to
json and then converting the json string back into a hashtable and
constructing a foo object from slot values in the hashtable:

    TUPLE: foo a b c ;
    C: <foo> foo
    1 2 3 <foo> >json json> foo from-slots

Best,
John.



On Wed, Jul 10, 2013 at 11:45 PM, Loryn Jenkins <lor...@gmail.com> wrote:

> Hi
>
> I've pasted a snippet of code that serialises an object (a vector
> containing a tuple) to JSON format, then loads it back into memory.
>
> http://paste.factorcode.org/paste?id=3028
>
> When loading JSON representation into memory instantiates a hashtable,
> which I then convert into a tuple using the word hashtable>cd
>
> My questions:
>
> 1. I'm using first4 to retrieve the members of the tuple from the JSON
> representation, placing them on the stack, so they can form an input to
> boa. How would I retrieve an *arbitrary* number of slots onto the stack?
> (i.e. For objects have e.g. 10, 15 or 50... slots.)
>
> 2. What I'm doing seems pretty kack-handed. What generic understanding of
> reflection and/or core words have I not yet discovered, which would
> contribute to implementing a more generic function?
>
> 3. Is there a Factor library providing a more direct serialisation format
> than JSON?
>
>
> Loryn Jenkins
>
>
> ------------------------------------------------------------------------------
> See everything from the browser to the database with AppDynamics
> Get end-to-end visibility with application monitoring from AppDynamics
> Isolate bottlenecks and diagnose root cause in seconds.
> Start your free trial of AppDynamics Pro today!
> http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to