• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[Rebol School] REBOL School

Maxim
3-Jul-2012
[530]
so it would be:
sort/compare/skip/index series :sf 2 2
Sujoy
3-Jul-2012
[531]
testing it now...
Maxim
3-Jul-2012
[532x3]
doh... that's my old modified sort func...
compare is used for the index and the func... hum.
I think you get blocks of fields when you use /compare with /skip
Sujoy
3-Jul-2012
[535x6]
>> blk: [1 [2  3] 0 [4 8] 5 [4 3]]
>> sort/skip blk 1
== [0 [4 8] 1 [2 3] 5 [4 3]]
sorry - that should read 
>> sort/skip blk 2
ok - am failing with the test, probably because i specified the problem 
wrongly
h: #hash! [k-a object! [
    name: "wonderwoman"
    attribs: make hash! ["1993-1994" #object! [
            rebal-year: 1993
            m: 160.018245
        ] "1992-1993" #object! [
            rebal-year: 1992
            m: 104.293
        ] "1991-1992" #object! [
            rebal-year: 1991
            m: 26.628
        ]]
...and so on...
my keys - for both the main hash and the inner hash are strings
i need to sort the hash h by the m attribute of the attribs hash
any ideas? would the same :sf work?
Maxim
3-Jul-2012
[541x3]
ok, so to get complete records, you need the /all refinement...
>> sort/skip/compare/all [1 [2  "a"] 0 [4 "z"] 5 [4 "m"]] 2 func 
[a b][a/2/2 < b/2/2 ]
== [1 [2 "a"] 5 [4 "m"] 0 [4 "z"]]
a, m, z are sorted.
Sujoy
3-Jul-2012
[544]
yup - that works...
but would it work for the structure i posted?
Maxim
3-Jul-2012
[545]
yes, you just need to adapt the paths you lookup.  the sort func 
gets a pair of blocks which are the whole records, which is why I 
start with a /2 to get the second field, which is the block ... in 
your case, that would be the object
Sujoy
3-Jul-2012
[546x3]
ok - thanks maxim
trrying it now
any luck with the new release of mod-web-api?
...and the json data structure?
Maxim
3-Jul-2012
[549]
the mod has been so heavily modified, its almost a complete rewrite. 
 its also heavily embeded within our production environement (libs 
and stuff) so that making it a stand-alone mod again will take some 
time... some time which currently, I don't have.  though note that 
we didin't actually add json support but greatly increased the flexibility 
of the i/o format conversion.
Sujoy
3-Jul-2012
[550]
sounds great...since i'm a noob, not sure i can help, but will gladly 
pitch in
Maxim
3-Jul-2012
[551x2]
we neededed to support, xml rest, SOAP and direct get/post interface 
to the same functions, and that is now working via a configuration, 
which allows you to tweak how the url is read and switch interfaces 
on the fly.
I also added path support for the mod so that you can use the same 
domain for web and api services.
Sujoy
3-Jul-2012
[553x2]
wow - cool!
any chance i can get to play with the code?
Maxim
3-Jul-2012
[555]
like I said , right now I can't rip it out easily because a lot of 
the code is shared with the code it serves (which is not part of 
the open source package).   It wasn't built with the task of making 
it independent... but it can be done.  It just takes time, which 
I currently don't have.
Sujoy
3-Jul-2012
[556x3]
no worries - am happy to wait!
sorry maxim - not having any luck with the sort function

>> sf: func [a b][o: select a/attribs "1991-1992" m: select b/attribs 
"1991-1992" o/m > m/m ]
>> sort/skip/compare/all comps 2 :sf
** Script Error: Invalid path value: attribs
** Near: o: select a/attribs "1991-1992"
help?
Henrik
3-Jul-2012
[559]
One of your objects does not have the 'attribs word.
Sujoy
3-Jul-2012
[560]
this is the structure i'm using:
h: #hash! [k-a object! [
    name: "wonderwoman"
    attribs: make hash! ["1993-1994" #object! [
            rebal-year: 1993
            m: 160.018245
        ] "1992-1993" #object! [
            rebal-year: 1992
            m: 104.293
        ] "1991-1992" #object! [
            rebal-year: 1991
            m: 26.628
        ] ] k-b object! [
    name: "wonderwoman"
    attribs: make hash! ["1993-1994" #object! [
            rebal-year: 1993
            m: 160.018245
        ] "1992-1993" #object! [
            rebal-year: 1992
            m: 104.293
        ] "1991-1992" #object! [
            rebal-year: 1991
            m: 26.628
        ] ]
Henrik
3-Jul-2012
[561x2]
The first element in that has does not appear to be an object.
that has = that hash
Sujoy
3-Jul-2012
[563x2]
yes - its actually a string
shouldnt sort/skip/compare/all comps 2 :sf pick up the object?
Henrik
3-Jul-2012
[565x2]
I'm not sure if it's possible, but you may then need to use 4 parameters 
instead of 2 in the compare function. Then use the string/object 
pairs for comparison.
I'm not certain that SKIP can be used with COMPARE.
Sujoy
3-Jul-2012
[567]
ah - so i should do:

>> sf: func [a b c d] [ o: select b/attribs "1991-1992" m: select 
d/attribs "1991-1992" o/m > m/m]
??
Henrik
3-Jul-2012
[568]
Untested, but yes, that's what I meant. I really don't know if it 
works.
Sujoy
3-Jul-2012
[569x2]
i get:
>> sort/compare comps :sf
** Script Error: Invalid argument: ?function?
** Near: sort/compare comps :sf
>> sort/compare/all comps :sf
** Script Error: Invalid argument: ?function?
** Near: sort/compare comps :sf
Arnold
3-Jul-2012
[571]
Back to the drawing board Sujoy and displaying the elements you want 
to use in your function piece by piece and maybe dump-obj is of any 
use?
(Now you don't use a and c)
Sujoy
3-Jul-2012
[572]
the sort/compare works great if its an object...am stuck because 
its a hash
Henrik
3-Jul-2012
[573]
Testing your code. What is COMPS?
Sujoy
3-Jul-2012
[574]
sorry - comps should be h - the hash
Henrik
3-Jul-2012
[575]
ok, the sort function must only have 2 parameters.
Sujoy
3-Jul-2012
[576]
not quite understanding how to use sort with this structure...
Henrik
3-Jul-2012
[577]
The structure is a little strange. Are you trying to sort the outer 
hash or the inner hash?
Sujoy
3-Jul-2012
[578x2]
both actually - need the outer hash sorted based on a property of 
the object inside the inner hash
ideally, would like to keep the hash h intact for retrieval by the 
keys