トップ 差分 一覧 ソース 検索 ヘルプ PDF RSS ログイン

chabo-dsl memo

func1

f1(a,b) =b;
f2(b,d) =f1(b,d);
c=(0..10);
i=2;
join(",",f2(c,f1(c[i..6],c[0..i+1])));

0,1,2,3

{
   const   [
       [0] "\",\"",
       [1] "\",\""
   ],
   data    ";",
   func    {
       f1   {
           args   "(a,b)",
           body   "b"
       },
       f2   {
           args   "(b,d)",
           body   {
               data    "f1",
               left    undef,
               right   "(b,d)"
           }
       }
   },
   left    {
       data    ";",
       left    {
           data    ";",
           left    {
               data    ";",
               left    var{func}{f1},
               right   var{func}{f2}
           },
           right   {
               data    "=",
               left    "c",
               right   {
                   data    "..",
                   left    0,
                   right   10
               }
           }
       },
       right   {
           data    "=",
           left    "i",
           right   2
       }
   },
   LOG     undef,
   right   {
       data    "join",
       left    undef,
       right   "(__STR__|0|__,f2(c,f1(array(c,i..6),array(c,0..i+1))))"
   },
   text    "[[f1|(a,b)|=|b|;|f2|(b,d)|=|f1|(b,d)|;|c|=|(|0|..|10|)|;|i|=|2|;|join|(__STR__|0|__,f2(c,f1(array(c,i..6),array(c,0..i+1))))]][[__STR__|1|__]][[f2|(c,f1(array(c,i..6),array(c,0..i+1)))]][[c]][[f1|(array(c,i..6),array(c,0..i+1))]][[array|(c,i..6)]][[c]][[i|..|6]][[array|(c,0..i+1)]][[c]][[0|..|i|+|1]][[b]][[d]]",
   vars    {
       c   [
           [0]  0,
           [1]  1,
           [2]  2,
           [3]  3,
           [4]  4,
           [5]  5,
           [6]  6,
           [7]  7,
           [8]  8,
           [9]  9,
           [10] 10
       ],
       i   2
   }
}

mergeSort

merge(l1,l2,out) = (
(length(l1) == 0 || length(l2) == 0) ? (push(out,l1);push(out,l2);return(out);) : ;
       (l2[0] < l1[0]) ? push(out,shift(l2))
                       : push(out,shift(l1)) ;
continue();
);
mergeSort(list) = (
       (length(list) <= 1) ? return(list) 
                           : merge(mergeSort(list[0..int(length(list)/2)-1])
                                  ,mergeSort(list[int(length(list)/2) .. length(list)-1])
                                  ,[]
                             )
);
list2=map($_*2-1,0..25);
push(list2,map($_*2,0..25));	
join(",",mergeSort(list2))

-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50