2

I'm facing the following error:

&*chdir('/home/account')   

Failed to change the working directory to '/home/account': Default constructor for 'IO::Path' only takes named arguments

What do I need to change to overcome this error?

(I am using perl6 version 2013.12 Ubuntu 14.04)

raiph
  • 26,254
  • 3
  • 45
  • 89
branco
  • 107
  • 8
  • Please show the code that produced the code and add some details. And read [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – wayneOS Apr 23 '18 at 21:11
  • 1
    `&*chdir('/home/account')` works for me if I create the dir first; or displays `Failed to change the working directory to '/home/account': chdir failed: no such file or directory` if I don't. The "Default constructor" message is an entirely different thing and seems to be just tacked on the end of the error message which is odd. Are you forgetting to show some other code you've written? Even then, it just looks odd. You may be using an old Perl 6 version. What does say $*PERL.compiler.version display? – raiph Apr 24 '18 at 04:41
  • 2
    The way the "Default constructor" message is just tacked on the end is odd. But it gets odder. In Perl 6 the "default constructor" is [`Mu`'s `.new`](https://docs.perl6.org/routine/new#class_Mu) which provides a default implementation of `.new`. But "Classes may provide their own new method to override this default." -- and `IO::Path` **does** provide [its own `.new`](https://docs.perl6.org/routine/new#%28IO::Path%29_method_new). My guess is your P6 is very old or you've got some code you're not showing that's odd or your system is odd. Can you provide details about your code, OS version etc.? – raiph Apr 24 '18 at 05:06
  • perl6 version 2013.12 Ubuntu 14.04 – branco Apr 24 '18 at 13:16
  • Your compiler is over 4 years old and is essentially a preview release of that compiler and the Perl 6 language. The first and only official version so far of the Perl 6 language, called `6.c` aka `6.Christmas`, was [announced on Christmas Day 2015](https://perl6advent.wordpress.com/2015/12/). The **Rakudo** compiler implements this `6.c` language. Rakudo **Star** is the compiler plus nice extras. I strongly recommend you download and install a recent **Rakudo Star**. If that won't work, then at least a recent Rakudo. My next message will provide guidance on that. – raiph Apr 25 '18 at 16:29
  • If you are familiar with the basics of compiling source code (using `make`, `gcc`, etc.), go to [the Rakudo Star **source** download page](https://rakudo.org/files/star/source) and follow the instructions. Otherwise, if you have a **64 bit** system, download the "Ubuntu 14.04 amd64*: deb" that's linked from [Pre-compiled OS packages for Rakudo](https://github.com/nxadm/rakudo-pkg#rakudo-pkg) and run `sudo dpkg -i *.deb`. Because this latter isn't the **Star** bundle, you'll need to also follow the instructions regarding `zef` and use it to install whatever packages/modules you want. Hth. – raiph Apr 25 '18 at 16:39

1 Answers1

8

2013.12 is 4.5 years old. I would not recommend learning Perl 6 with that version. Please try to get a more recent version: the documentation for it will be more up to date, and it will be one, if not 2 orders of magnitude faster.

Also, why not use chdir instead of &*chdir? The latter being something that is relic from ancient times, afaik. If you just chdir, you get:

$ perl6 -e 'chdir("/home/account")'
Failed to change the working directory to '/home/account': does not exist

Which is definitely already much more understandable.

Secondly, if a chdir fails, it returns a Failure. When a Failure is sunk (aka being called in "void" context in Perl 5 terms), it will throw the Exception it contains. Which is what you just saw.

chdir returns an IO::Path object if successful, which is True in a Boolean context such as an if or a ternary:

$ perl6 -e 'say chdir("/home/account") ?? "Yeah!" !! "Alas"'
Alas

But in most cases where you want to do something inside a directory, you will want to use indir( $path, { code to execute } ). That will ensure that no code will be executed in that directory except for the code given as the second parameter.

Elizabeth Mattijsen
  • 19,100
  • 3
  • 57
  • 83
  • I'm beginning to use perl6 as my shell on Ubuntu but I know dash and coreutils well so I want to use the 'shell' command a lot. When I tried to use indir in my perl6 version 2013.12 I get 'Undeclared routine: indir. I thought 'indir($*CWD,{shell 'pwd'})' would work but it doesn't. – branco Apr 24 '18 at 13:16
  • 2
    @branco: 2013.12 is 4.5 years old. I would *not* recommend learning Perl 6 with that version. Please try to get a more recent version: the documentation for it will be more up to date, and it will be one, if not 2 orders of magnitude faster. – Elizabeth Mattijsen Apr 24 '18 at 14:09
  • 1
    @ElizabethMattijsen I hope it's okay I lifted your comments into your answer (if not, feel free to revert my edit). I was about to post my own answer saying that branco really just needed to install a new version, but you'd already said it. – Christopher Bottoms Apr 25 '18 at 12:56