Skip to content

Commit

Permalink
Print nested sublist extractions correctly
Browse files Browse the repository at this point in the history
* PrintElmsListLevel preserves the old behaviour of PrintElmsList for
  EXPR_ELMS_LIST_LEV.
* PrintElmsList applies to EXPR_ELMS_LIST and now checks if its first
  argument is of type EXPR_ELMS_LIST or EXPR_ELMS_LIST_LEV. If yes, the
  list is put in brackets.
  • Loading branch information
zickgraf committed Oct 14, 2022
1 parent cb453fd commit 690a68b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,32 @@ static void PrintIsbList(Expr expr)
** Linebreaks are preferred after the '{'.
*/
static void PrintElmsList(Expr expr)
{
Expr list = READ_EXPR(expr, 0);
Pr("%2>", 0, 0);
if (TNUM_EXPR(list) == EXPR_ELMS_LIST || TNUM_EXPR(list) == EXPR_ELMS_LIST_LEV) {
Pr("(", 0, 0);
PrintExpr(list);
Pr(")", 0, 0);
} else {
PrintExpr(list);
}
Pr("%<{", 0, 0);
PrintExpr(READ_EXPR(expr, 1));
Pr("%<}", 0, 0);
}


/****************************************************************************
**
*F PrintElmsListLevel(<expr>) . . print a selection of several elements of a list
**
** 'PrintElmsListLevel' prints the list elements expression <expr> of the form
** '<list>{<positions>}'.
**
** Linebreaks are preferred after the '{'.
*/
static void PrintElmsListLevel(Expr expr)
{
Pr("%2>", 0, 0);
PrintExpr(READ_EXPR(expr, 0));
Expand Down Expand Up @@ -2242,7 +2268,7 @@ static Int InitKernel (
InstallPrintExprFunc( EXPR_ELM_LIST , PrintElmList);
InstallPrintExprFunc( EXPR_ELMS_LIST , PrintElmsList);
InstallPrintExprFunc( EXPR_ELM_LIST_LEV , PrintElmListLevel);
InstallPrintExprFunc( EXPR_ELMS_LIST_LEV , PrintElmsList);
InstallPrintExprFunc( EXPR_ELMS_LIST_LEV , PrintElmsListLevel);
InstallPrintExprFunc( EXPR_ISB_LIST , PrintIsbList);

// install executors, evaluators, and printers for matrix elements
Expand Down
4 changes: 4 additions & 0 deletions tst/testinstall/function.tst
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,8 @@ gap> funcloop(x -> (x in x) and x);
function ( x ) return x in x and x; end
gap> funcloop(x -> x in (x and x));
function ( x ) return x in (x and x); end
gap> funcloop(x -> ([ x ]{[ 1 ]}){[ 1 ]});
gap> funcloop(x -> (([ x ]{[ 1 ]}){[ 1 ]}){[ 1 ]});
gap> funcloop(x -> [ [ x ] ]{[ 1 ]}{[ 1 ]});
gap> funcloop(x -> ([ [ x ] ]{[ 1 ]}{[ 1 ]}){[ 1 ]});
gap> STOP_TEST("function.tst", 1);

0 comments on commit 690a68b

Please sign in to comment.