p.s. for the tacit stack issue, you did not include your definition of
comp2, but if it's from aoc day 13, a plausible issue is that comp2
would be returning _1 or 1 instead of 0 or 1 (which is what that
quicksort implementation expects).

That said, when debugging stack errors on recursive functions, it can
be handy to use $:&([echo) so that you can see where the spam where
the recursion goes wrong.

-- 
Raul

On Tue, Dec 13, 2022 at 1:43 PM Jaume <greenni...@gmail.com> wrote:
>
> Hello all
>
> Still here and I've done all the days in J except for day 7, But that's not
> why I'm here.
>
> So now I've done the first part, and I have a function that is too long to
> copy that does comparisons in an iterative way (I had some stack problems).
> Now I'm wanting to sort the elements using this function, but I don't know
> how.
>
> All the sorting is done using the standard comparison, all the grading is
> numerical, the quicksort implementation in
> https://www.jsoftware.com/help/dictionary/cif.htm (and in
> https://code.jsoftware.com/wiki/Essays/Quicksort) is giving me an error
> even when trying with numbers.
>
> sel=: 1 : 'x # ['
>
> quicksort=: 3 : 0
>
> if. 1 >: #y do. y
>
> else.
>
> (quicksort y <sel e),(y =sel e),quicksort y >sel e=.y{~?#y
>
> end.
>
> )
>
> quicksort 15 2 9 10 4 0 13 13 18 7
>
> |noun result was required: quicksort
>
> | x#[
>
> |[-0]
>
>
> And the tacit version, which I hope I modified correctly, it's also giving
> me a stack error.
>
> less=:{{x comp2 y}}
>
> great=:{{y comp2 x}}
>
> quicksort=: (($:@(less#[) , (=#[) , $:@(great#[)) ({~ ?@#)) ^: (1<#)
>
> quicksort pp
>
> |stack error: comp2
>
> | y comp2 x
>
>
> Any idea how can I sort the elements or correct the errors I have?
>
> Thanks
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to