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

Unprintable object? #3482

Closed
laurentbartholdi opened this issue May 31, 2019 · 8 comments
Closed

Unprintable object? #3482

laurentbartholdi opened this issue May 31, 2019 · 8 comments
Labels
kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements

Comments

@laurentbartholdi
Copy link
Contributor

I would very much like GAP to have an unprintable object: an object that, when returned, does not display anything. (This exists, e.g., in julia as the object "nothing").

Reason: I have a function called "Draw", which typically opens a window and draws an object in the window. In that case, it should return nothing. However, depending on user preferences it could also return an ascii string with a crude drawing of the object, or a JupyterRenderable object.

Then, if Draw itself is called from another command (say Draw with other parameters), the caller doesn't know if it should forward a return value or not. This forces ugly code of the form

if in_jupyter_mode() then
    return Draw(arguments);
else
    Draw(arguments);
fi;

Having "Draw" always return a value (such as "true") would be an alternative, but would pollute the screen unnecessarily.

I hope I'm not doing anything wrong by putting this in the "issues"... it's not a bug, it's a feature request.

@stevelinton
Copy link
Contributor

So if I understand, you want an object x that such that ViewString(x) is the empty string. Should String(x) and DisplayString(x) also be empty, or does it make more sense for String(x) to print some GAP input that can create the object?

@wucas wucas added kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements kind: new feature and removed kind: new feature labels May 31, 2019
@laurentbartholdi
Copy link
Contributor Author

laurentbartholdi commented May 31, 2019 via email

@ChrisJefferson
Copy link
Contributor

While I'm not disagreeing with this, we did in the past think about adding something like Python's "Nothing", or various variants of it (such as allowing "return f(x);" where "f(x)" didn't return anything just continuing to not return anything. None of the possible designs ended up winning.

@ChrisJefferson
Copy link
Contributor

ChrisJefferson commented May 31, 2019

Here is the previous PR (and from here you can get to some related PRs, which tried out other ideas). EDIT: I meant to link to a or here, but @fingolfin linked to them below.

@fingolfin
Copy link
Member

I do disagree with this. We thought about this and discussed it at length before. It just doesn't fit in naturally, and opens up tons and tons of corner cases, which need to be dealt with, and quickly (otherwise, we'll do undesirable things in some of them, yet people start to depend on them).

I'd also argue that a GAP function which sometimes returns a value and sometimes doesn't is bad design (in fact, I'd argue the same for any language, not just GAP). If you really need to deal with such a thing, you can use CallFuncListWrap, but really, I'd rather suggest you avoid this.

Finally., why can't your function just return fail or 0 or whatever in the first case?

(Oh, and "issues" include bug reports, feature requests, and support requests equally, so this is the right place for "feature requests").

@laurentbartholdi
Copy link
Contributor Author

laurentbartholdi commented Jun 4, 2019 via email

@fingolfin
Copy link
Member

We discussed this on at least one GAP day, not necessarily written down. Some relevant PRs are #824, #829, #831

@fingolfin
Copy link
Member

Anyway, I stand by my earlier remark that I consider it bad design to have a function which sometimes returns a value and sometimes not; and I kinda wish I could go back in time and enforce this rule on a language level (alas, some legacy code "relies" on this).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements
Projects
None yet
Development

No branches or pull requests

5 participants