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

Implement Operator, String Repeat CPPOPS_CPPTYPES #95

Closed
wbraswell opened this issue Apr 9, 2019 · 21 comments
Closed

Implement Operator, String Repeat CPPOPS_CPPTYPES #95

wbraswell opened this issue Apr 9, 2019 · 21 comments

Comments

@wbraswell
Copy link
Owner

Implement the ast_to_cpp__generate__CPPOPS_CPPTYPES() C++ code generation subroutine for the string repeat operator:

https://github.com/wbraswell/rperl/blob/master/lib/RPerl/Operation/Expression/Operator/String/Repeat.pm

Ensure all tests continue to pass in both the existing PERLOPS_PERLTYPES mode as well as the new CPPOPS_CPPTYPES mode:

https://github.com/wbraswell/rperl/tree/master/lib/RPerl/Test/Operator07StringRepeat

Use the string concatenation operator as reference:

https://github.com/wbraswell/rperl/blob/master/lib/RPerl/Operation/Expression/Operator/String/Concatenate.pm

Use the "getting started" documentation for step-by-step instructions:

https://github.com/wbraswell/rperl/blob/master/docs/devs_getting_started.txt

@wbraswell
Copy link
Owner Author

@jsxs0
Hello Mr. Sandral,

This is your issue for GSoC Pull Request Challenge, Round 1! :-)

Please use this comment thread for all discussions related to this Pull Request Challenge.

@jsxs0
Copy link

jsxs0 commented Apr 10, 2019

I've installed the necessary software(s) required on my machine, but I'm still not able to open it/ execute it.
PS. I'm using MS Windows 10

@JJ
Copy link

JJ commented Apr 10, 2019 via email

@wbraswell
Copy link
Owner Author

@jsxs0
Regarding operating system requirements for this project, you will need Linux of some kind, and I strongly suggest Xubuntu.
You can use a virtual machine if you are unable to install Xubuntu directly onto your hardware, although I will be unable to provide support for anything other than Xubuntu itself.

@jsxs0
Copy link

jsxs0 commented Apr 13, 2019

Hi mentors, I'm working over it. Do not mark me inactive. Cause of my exams, I've been highly preoccupied but I'm still figuring out a way through it.
Hope you understand.
Thanks & Regards.

@jsxs0
Copy link

jsxs0 commented Apr 13, 2019

Alright, so I've got started with RPerl, and the issue of course. So, our main intention here is to implement an operator, for the purpose of string repeat with the help of CPPOPS_CPPTYPES.
Starting off, with the C++ code generation, we know that to implement it with the same, it'd be:
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
string repeat(string s, int n)
{
string s1=s;
for(int i=1;i<n;++i)
s+=s1;
return s;
}
int main()
{
string s="rperl";
int n=4;
cout<<repeat(s,n)<<endl;
return 0;
}
Which when implemented, would give us an output like:
'rperlrperlrperlrperl'.
Now, keeping this in mind, when we move onto Perl.
For returning a new string which is made by concatenating a given string n number of times, I can either use a dot operator (.) or the lower-case X- x (repetition).
Using them here, we get:
use strict;
use warnings;
use 5.010;

 my $x = 'RPerl';
 my $y = 'Operators';

 my $z = $x . ' ' . $y;
 say $z;

Yielding us: RPerl Operators.
Here, I did not use the . concatenation, but if I'd have used that too, the same result'd have been yielded.
Next off, x the repetition operator
This will work by specifying a string operator on the left side, and a number on the right.
Documents/string_rep.pl
use strict;
use warnings;
use 5.010;

my $y = 'RPerl ';
 
my $z = $y x 2;
say $z;
 
say $y x 2 . 'Operators';

gives us:
Rperl Rperl
Rperl Rperl Operators
++ on a string
Making special use of the ++ operator on strings
use strict;
use warnings;
use 5.010;

my $x = "ay";
say $x;
$x++;
say $x;
 
 
$x++;
say $x;
 
$x++;
say $x;
Thus, we get:
ay
az
ba
bb

These were all my approaches to the given assignment, now talking of this with respect to the the string repeat operator, rperl/Repeat.pm:
With the standard packages, and headers being used, OO INHERITANCE, CRITICS, OO PROPERTIES, and standard SUBROUTINES & OO METHODS will be used.
Now, in the string reparation generation, in Operator::String::Repeat->ast_to_rperl__generate():
We've an operator referring to a sub class, which is basically checking it's existence, and if it is so, it'd allow it for the operation.
A subgroup would be created, and the child of it will generate the repetition.
Obviously, since it's stored in an array, it'd allocate those blocks, with the strings to be repeated, and later at the end, append them, and later output them.
But, in case the Sub expression condition doesn't pass, it'd go to the die case, and an error message will be displayed.
The usual routines follow.
I'd be evaluating the above mentioned snippets in the code (master file), and test cases will be checked for.
I've used the string concatenation operator as a reference along with the Learning RPerl book, and got to the best of knowledge, all of these.
If the approach I'm following is correct, it wouldn't take long for me to implement them, and complete this operator implementation.
If I'm going wrong anywhere in my approach, do guide me.
Thanks & Regards.

@wbraswell
Copy link
Owner Author

@jsxs0

Mr. Sandral,
I am unable to understand your long explanation, for now please refrain from providing long plain-English explanations of your plans.

It seems that you might be on the right track, but it will be impossible to know until you begin actually writing & running code.

@jsxs0
Copy link

jsxs0 commented Apr 27, 2019

Working over it.

@jsxs0
Copy link

jsxs0 commented Apr 28, 2019

My basic logic of string repeat is correct. Whenever I'm trying to run it in normal Perl compiler with a simple logic, I'm getting the output, correctly, but whenever this RPerl module is being compiled, it shows this error (from quite a lot of time, now):

Can't locate RPerl.pm in @INC (you may need to install the RPerl module) (@INC contains: C:/Perl64/site/lib C:/Perl64/lib) at C:\Users\jnzca\Documents\sample.pl line 6.
BEGIN failed--compilation aborted at C:\Users\jnzca\Documents\sample.pl line 6.

I've installed the RPerl module, and it is in the PATH of the rest RPerl files. It does not even compile, you see.
Can somebody guide me over this?
TIA.

@jsxs0
Copy link

jsxs0 commented Apr 28, 2019

Different outputs:

  • The . concatenation
    image

  • x the repetition operator
    image

  • ++ on a string
    image
    The source code for these operations (outputs) is:

  • The . concatenation
    use strict;
    use warnings;
    use 5.010;

    my $x = 'RPerl';
    my $y = 'Operators';

    my $z = $x . ' ' . $y;
    my $q = $y . ' ' . $x;
    my $e = $x . ' ' . $x;
    say $z;
    say $q;
    say $e;

  • x the repetition operator
    use strict;
    use warnings;
    use 5.010;

my $y = 'RPerl ';

my $z = $y x 2;
say $z;

say $y x 2 . 'Operators';

@jsxs0
Copy link

jsxs0 commented Apr 28, 2019

And, for the ++ on a string:
use strict;
use warnings;
use 5.010;

my $x = "rperl";
say $x;
$x++;
say $x;

$x++;
say $x;

$x++;
say $x;

$x--;
say $x;

Just wanted to know, are these approaches correct, is this the correct way to get going with it?
TIA.

@wbraswell
Copy link
Owner Author

@jsxs0
Sorry I can not provide any assistance for Microsoft software.

RPerl is now available on Docker, I suggest you start there.
http://rperl.org/get_rperl.html

@jsxs0
Copy link

jsxs0 commented Apr 29, 2019

@jsxs0
Sorry I can not provide any assistance for Microsoft software.

RPerl is now available on Docker, I suggest you start there.
http://rperl.org/get_rperl.html

Alright, I'd be doing that.
Did you check out the code snippets I had attached? Is it what exactly we want?

@wbraswell
Copy link
Owner Author

Please read the documentation:

https://github.com/wbraswell/rperl/blob/master/docs/devs_getting_started.txt

@jsxs0
Copy link

jsxs0 commented May 2, 2019

I'm not able to use Docker for Windows. Depreciated versions are been installed is what it says after the installations, even though I'm installing the Docker from the official website.
I'd better try using RPerl on Windows, itself.
I'd get back to you, regarding the updates, ASAP!

@shpsi
Copy link
Contributor

shpsi commented May 2, 2019

Hey Jasveen if you want to setup or install rperl correctly, i can give you my install_notes which was written while installing rperl in my system.

@jsxs0
Copy link

jsxs0 commented May 2, 2019

Hey Jasveen if you want to setup or install rperl correctly, i can give you my install_notes which was written while installing rperl in my system.

Thanks, @shpsi! Sure, let us catch up over it, over the emails.

@wbraswell
Copy link
Owner Author

@jsxs0
I already told you "I can not provide any assistance for Microsoft software."

If you are unable to use Docker, then you can try creating a full virtual machine using VirtualBox or VMware, then install real Xubuntu 16.04 Linux inside the VM.

If you are unable to use native Linux or Docker or a virtual machine, then I can't help you.

@wbraswell
Copy link
Owner Author

The install notes from @shpsi are for Linux installed inside a virtual machine. You are much better off using Docker, which does it all for you. And also there are ongoing issues with many other people's software on CPAN at this time, which makes installation tricky or impossible.
So, again, use Docker.

@jsxs0
Copy link

jsxs0 commented May 4, 2019

#101 Implement Operator, String Repeat CPPOPS_CPPTYPES Jasveen PRC-1 #103

@wbraswell
Copy link
Owner Author

@jsxs0
Thank you for your entry to the Google Summer of Code.
Unfortunately, your attempts to install and upgrade RPerl were unsuccessful.
I wish you the best of luck in the future!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants