Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix printing of GAP functions containing sublist extractions #5116

Merged
merged 1 commit into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 23 additions & 0 deletions tst/testinstall/function.tst
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,27 @@ 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

# nested sublist extractions
# a single extraction
gap> funcloop(x -> [ x ]{[ 1 ]});
function ( x ) return [ x ]{[ 1 ]}; end

# two extractions
gap> funcloop(x -> ([ x ]{[ 1 ]}){[ 1 ]});
zickgraf marked this conversation as resolved.
Show resolved Hide resolved
function ( x ) return ([ x ]{[ 1 ]}){[ 1 ]}; end
gap> funcloop(x -> [ [ x ] ]{[ 1 ]}{[ 1 ]});
function ( x ) return [ [ x ] ]{[ 1 ]}{[ 1 ]}; end

# three extractions
gap> funcloop(x -> (([ x ]{[ 1 ]}){[ 1 ]}){[ 1 ]});
function ( x ) return (([ x ]{[ 1 ]}){[ 1 ]}){[ 1 ]}; end
gap> funcloop(x -> ([ [ x ] ]{[ 1 ]}{[ 1 ]}){[ 1 ]});
function ( x ) return ([ [ x ] ]{[ 1 ]}{[ 1 ]}){[ 1 ]}; end
gap> funcloop(x -> ([ [ x ] ]{[ 1 ]}){[ 1 ]}{[ 1 ]});
function ( x ) return ([ [ x ] ]{[ 1 ]}){[ 1 ]}{[ 1 ]}; end

# four extractions
gap> funcloop(x -> ([ [ x ] ]{[ 1 ]}{[ 1 ]}){[ 1 ]}{[ 1 ]});
function ( x ) return ([ [ x ] ]{[ 1 ]}{[ 1 ]}){[ 1 ]}{[ 1 ]}; end
gap> STOP_TEST("function.tst", 1);