Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Do something about the undefine() function #5

Closed
lucasbuchala opened this issue Feb 23, 2018 · 3 comments
Closed

Do something about the undefine() function #5

lucasbuchala opened this issue Feb 23, 2018 · 3 comments

Comments

@lucasbuchala
Copy link

The undefine routine is defined in file src/core/operators.pm as:

multi sub undefine(Mu    \x) is raw { x = Nil   }
multi sub undefine(Array \x) is raw { x = Empty }
multi sub undefine(Hash  \x) is raw { x = Empty }

It seems to be reminiscent from Perl 5, where you can write like this:

undef $x;  # sets $x to undef
undef @a;  # clear array content
undef %h;  # clear hash content

But whereas in Perl 5 it makes sense, I fail to see the purpose of it in Perl 6. If the programmer wants to clear a container (or set it to its default value), they can just assign Nil or Empty themselves:

$x = Nil;
@a = Empty;
%h = Empty;

If it's for the convenience of having a function that does just this, then shouldn't it have a more appropriate name? "reset"? "clear"? "set-to-default"? "undefine" besides being a longer name than "undef", doesn't do what its name says, it doesn't undefine variables in the ".defined method" meaning:

my $x is default(42);
my @a;
my %h;

undefine $x;
undefine @a;
undefine %h;

say $x.defined;  #=> True
say @a.defined;  #=> True
say %h.defined;  #=> True

It feels strange in this situation:

> my $a is default(42); $a = 10; dd $a; undefine $a; dd $a
Int $a = 10
Int $a = 42

> my $a is default(42); $a = []; dd $a; undefine $a; dd $a
Array $a = $[]
Slip $a = Empty

So, is there any plans for what to do with the undefine function? Or this should stay as it is?

@zoffixznet
Copy link
Contributor

👍 on deprecating undefine into oblivion.

@jnthn
Copy link
Contributor

jnthn commented Feb 23, 2018

This feels like a straggler from the days of undef being a thing. I suspect it has minimal usage in the module ecosystem, but we should probably check.

I'm inclined towards deprecating this in 6.d; it's a sub, so it's easy to do that already by just sticking an implementation of it CORE.d.setting and marking it is DEPCREATED so we only warn when using the 6.d language version..

@AlexDaniel
Copy link
Member

+½ for deprecating.

FWIW:

<AlexDaniel> greppable6: undefine \W
<greppable6> AlexDaniel, 6 lines, 5 modules: https://gist.github.com/c4c56e292b3a6a0a0de89c6504efbefa

tisonkun added a commit to Raku/doc that referenced this issue Feb 24, 2018
zoffixznet added a commit to Raku/doc that referenced this issue Jun 6, 2018
It's scheduled for deprecation[^1] in 6.d, so it's best to limit its
general use in doc examples

[1] Raku/6.d-prep#5
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants