This is called "ranking" and is very simple in APL: ⍋⍋'GNUAPL' 2 4 6 1 5 3
The permutations 4 1 6 2 5 3 (i.e. ⍋'GNUAPL') and 2 4 6 1 5 3 are inverses of each other, and ⍋ will invert a permutation. Jay. On 17 October 2016 at 15:41, Ala'a Mohammad <amal...@gmail.com> wrote: > Hi Juergen, > > Thanks for the fix. > > Apology if I could not explain what I'm trying to do. It is: given a > string, replace every char with its alphabetic index (starting from > 1). The following simpler solution achieves it. > > ⊢string ←'GNUAPL' > GNUAPL > ⊢string[⍋string] ← ⍳⍴string > 1 2 3 4 5 6 > string > 2 4 6 1 5 3 > > but now 'string' is overwritten. Then i tried to generalize it, thus > > {str⊣str[⍋str]←⍳⍴str←⍵} 'GNUAPL' > 2 4 6 1 5 3 > > but now I need '⊣', otherwise the returned result will be the ordered iota. > > I tried to understand why it returns 1 2 3 4 5 6 (without ⊣), but > failed! Any hints/references? > > Thanks again for the fix. > > Ala'a > > > On Mon, Oct 17, 2016 at 2:34 PM, Juergen Sauermann > <juergen.sauerm...@t-online.de> wrote: > > Hi Ala'a > > > > thanks, fixed in SVN 798.You will now get a DOMAIN ERROR instead of > > a failed assertion. > > > > The DOMAIN ERROR is being reported because you try to compare objects > that > > would be called left values in C/C++, so your code is also wrong. I would > > also > > be careful with using A⍳B if A or B becomes large. For regular structures > > like > > > > abc←'abcdefghijklmnopqrstuvwxyz' > > abc⍳XXX > > > > you might consider using something like > > > > 0 ⌈ 26 ⌊ ¯97 + ⎕UCS XXX > > > > which will decrease your execution time from O((⍴A)×(⍴B)) down to O(⍴B). > > > > /// Jürgen > > > > > > > > On 10/16/2016 04:51 PM, Ala'a Mohammad wrote: > > > > I was trying to assign order to a word letters for example 'zach' is > > 312, I got it finally, for example for 'maine' > > abc←'abcdefghijklmnopqrstuvwxyz' > > 1+(⌽⍳5)[(⍋abc⍳'maine')] > > 4 1 3 5 2 > > > > But I got the following failing assertion and wanted to check if > > something related to my code or the interpreter. > > I'm using > > GNU APL > > : apl -v > > BUILDTAG: > > --------- > > Project: GNU APL > > Version / SVN: 1.6 / 796 > > Build Date: 2016-09-26 18:43:22 UTC > > Build OS: Linux 3.13.0-37-generic x86_64 > > config.status: unknown configure options > > Archive SVN: 787 > > > > Operating system is Linuxmint 17.1 64bit (Linux rock 3.13.0-37-generic > > #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014 x86_64 x86_64 x86_64 > > GNU/Linux) > > > > Regards, > > > > Ala'a > > > > ------------------------------------------------------------ > --------------------------- > > > > abc←'abcdefghijklmnopqrstuvwxyz' > > abc⍳'maine' > > 12 0 8 13 4 > > ⍋abc⍳'maine' > > 1 4 2 0 3 > > (⍋abc⍳'maine')←⍳5 > > equal() called on object of classLvalCell > > > > ============================================================ > ================== > > Assertion failed: 0 > > in Function: equal > > in file: Cell.cc:117 > > > > Call stack: > > > > ---------------------------------------- > > -- Stack trace at Cell.cc:117 > > ---------------------------------------- > > 0x7fb94a6e9f45 __libc_start_main > > 0x446105 main > > 0x56b84d Workspace::immediate_execution(bool) > > 0x487e89 Command::process_line() > > 0x487f2d Command::do_APL_expression(UCS_string&) > > 0x4923c8 Executable::execute_body() const > > 0x5201b0 StateIndicator::run() > > 0x4c57e9 Prefix::reduce_statements() > > 0x4c4d59 Prefix::reduce_MISC_F_B_() > > 0x460d8f Bif_F12_SORT_ASC::eval_B(Value_P) > > 0x45fdaf Bif_F12_SORT::sort(Value_P, Sort_order) > > 0x47746a Cell::greater_vec(Cell const*, Cell const*, void > const*) > > 0x476b78 > > 0x4552df do_Assert(char const*, char const*, char const*, > int) > > ======================================== > > > > SI stack: > > > > Depth: 79 > > Exec: 0x1796ad0 > > Safe exec: 0 > > Pmode: ◊ (⍋abc⍳'maine')←⍳5 > > PC: 9 ENDL > > Stat: (⍋abc⍳'maine')←⍳5 > > err_code: 0x0 > > thrown: at StateIndicator.cc:39 > > e_msg_1: 'No Error' > > e_msg_2: '' > > e_msg_3: '' > > > > Depth: 78 > > Exec: 0x17b2af0 > > Safe exec: 0 > > Pmode: ◊ abc[s] > > PC: 4 ENDL > > Stat: abc[s] > > err_code: 0x50005 > > thrown: at Value.cc:1050 > > e_msg_1: 'INDEX ERROR+' > > e_msg_2: ' abc[s]' > > e_msg_3: ' ^ ^' > > > > Depth: 77 > > Exec: 0x17b2820 > > Safe exec: 0 > > Pmode: ◊ s⌷abc > > PC: 3 ENDL > > Stat: s⌷abc > > err_code: 0x50002 > > thrown: at PrimitiveFunction.cc:2308 > > e_msg_1: 'RANK ERROR' > > e_msg_2: ' s⌷abc' > > e_msg_3: ' ^ ^' > > > > Depth: 76 > > Exec: 0x17b2e30 > > Safe exec: 0 > > Pmode: ◊ abs⍳s > > PC: 2 'abs > > Stat: abs⍳s > > err_code: 0x30001 > > thrown: at Symbol.cc:662 > > e_msg_1: 'VALUE ERROR' > > e_msg_2: ' abs⍳s' > > e_msg_3: ' ^' > > > > Depth: 75 > > Exec: 0x17d0ae0 > > Safe exec: 0 > > Pmode: ◊ abs[s] > > PC: 3 'abs > > Stat: abs[s] > > err_code: 0x30001 > > thrown: at Symbol.cc:662 > > e_msg_1: 'VALUE ERROR' > > e_msg_2: ' abs[s]' > > e_msg_3: ' ^' > > > > Depth: 74 > > Exec: 0x17a1e40 > > Safe exec: 0 > > Pmode: ∇ λ1[1] > > PC: 13 ← > > > > ============================================================ > ================== > > Assertion failed: idx < items_valid > > in Function: operator[] > > in file: Simple_string.hh:140 > > > > Call stack: > > *** do_Assert() called recursively *** > > ============================================================ > ================== > > > > > > > >