We should really work on getting a Pike entry here. It'll require quite a lot of work though.
Sounds like an interresting project.
/ Peter Lundqvist (disjunkt)
Previous text:
2003-01-02 18:40: Subject: PLEAC
We should really work on getting a Pike entry here. It'll require quite a lot of work though.
/ Martin Nilsson (bygger parser
Well, some thougt needs to be put into it. We don't want to write stuff in their format do we? I think that it would be better to use our own and convert to theirs.
/ Marcus Agehall (Trådlös)
Previous text:
2003-01-02 19:18: Subject: PLEAC
It might get done pretty fast using a wiki. :)
/ Johan Schön (Firefruit)
I can't see that the conversion would be any problem, unless we do a _really_ stupid storage implementation on our side.
Perhaps one should make a CVS repository for all demo/example code. We could put this, the shootout, 99-bottles, shortest-RSA-imlpementation etc in one place.
/ Martin Nilsson (bygger parser
Previous text:
2003-01-02 19:56: Subject: PLEAC
Well, some thougt needs to be put into it. We don't want to write stuff in their format do we? I think that it would be better to use our own and convert to theirs.
/ Marcus Agehall (Trådlös)
On Thu, Jan 02, 2003 at 08:20:03PM +0100, Martin Nilsson (bygger parser @ Pike (-) developers forum wrote:
Perhaps one should make a CVS repository for all demo/example code. We could put this, the shootout, 99-bottles, shortest-RSA-imlpementation etc in one place.
well, most important is a place where people can quickly drop stuff without to much fuss. if someone gets bored he/she should be able to just do an example and just dumpt it somewhere.
btw, i am working on the second box "Accessing Strings" this turns out to be fun :-)
On Thu, Jan 02, 2003 at 06:45:00PM +0100, Martin Nilsson (bygger parser @ Pike (-) developers forum wrote:
We should really work on getting a Pike entry here. It'll require quite a lot of work though. http://pleac.sourceforge.net/
indeed, would be interresting. though it would be wise to read the perl cookbook for this, to see what the examples are actually intended to do, and not just blindly translate the perl source to pike.
here is the first example though:
//----------------------------- int i; // declare a variable of type int i = 'a'; // the ascii value of "a" i = '\n'; // the ascii value of a "newline" //----------------------------- string str; // declare a variable of type string str = "\n"; // a "newline" character str = "Jon "Maddog" Orwant"; // literal double quotes //----------------------------- str = #"This is a multiline here document terminated by a double-quote like any other string"; //-----------------------------
greetings, martin.
On Thu, Jan 02, 2003 at 08:05:46PM +0100, Martin Baehr wrote:
here is the first example though:
second: not sure if pasting from hilfe is a good idea. probably not, because, then you can't cut the examples and paste them for your own use...
i was however quite excited to see a few examples that look a lot nicer and compact in pike compared to perl :-)
Accessing Substrings //------------------------------ string str, value; int offset, count; value = str[offset..offset+count]; value = str[offset..];
string newstring, newtail; str = str[..offset-1]+newstring+str[offset+count..]; str = str[..offset-1]+newtail;
//------------------------------ // get a 5-byte string, skip 3, then grab 2 8-byte strings, then the rest string leading, s1, s2, trailing; [leading, s1, s2, trailing] = array_sscanf(str, "%5s%*3s%8s%8s%s");
// split at five byte boundaries array fivers = array_sscanf(str, "%{%5s%}");
// chop string into individual characters array chars = str/"";
//------------------------------ // switching to hilfe: $ pike Pike v7.2 release 340 running Hilfe v2.0 (Incremental Pike Frontend)
str = "This is what you have";
Result: "This is what you have"
string first, start, rest, last, end, piece; int t = str[0];
Result: 84
first = str[0..0];
Result: "T"
start = str[5..5+1];
Result: "is"
rest = str[13..];
Result: "you have"
last = str[sizeof(str)-1..sizeof(str)-1];
Result: "e"
end = str[sizeof(str)-4..];
Result: "have"
piece = str[sizeof(str)-8..sizeof(str)-8+2];
Result: "you"
str = "This is what you have";
Result: "This is what you have"
str = replace(str, ([ " is ":" wasn't " ]) );
Result: "This wasn't what you have"
str = str[..sizeof(str)-13]+"ondrous";
Result: "This wasn't wondrous"
str = str[1..];
Result: "his wasn't wondrous"
str = str[..sizeof(str)-11];
Result: "his wasn'"
str = "This is what you have";
Result: "This is what you have"
str = replace(str[..4], ([ "is":"at" ]) )+str[5..];
Result: "That is what you have"
str = "make a hat";
Result: "make a hat"
[str[0], str[-1]] = ({ str[-1], str[0] }); str;
Result: "take a ham"
string a, b, c; a="To be or not to be";
Result: "To be or not to be"
b=a[6..11];
Result: "or not"
b=a[6..7]; c=a[3..4];
Result: "or" Result: "be"
write("%s\n%s\n", b, c);
or be Result: 6
//------------------------------------------------
string cut2fmt(int ... positions)
{ string template = ""; int lastpos = 1; foreach(positions, int place) { template += "A" + (place - lastpos) + " "; lastpos=place; } template += "A*"; return template; }
string fmt=cut2fmt(8, 14, 20, 26, 30);
Result: "A7 A6 A6 A6 A4 A*"
write(fmt+"\n");
A7 A6 A6 A6 A4 A* Result: 18
// split at five byte boundaries array fivers = array_sscanf(str, "%{%5s%}");
What about
array fivers = str/5;
then? Is that considered uggly?
/ Peter Lundqvist (disjunkt)
Previous text:
2003-01-02 21:23: Subject: Re: PLEAC
On Thu, Jan 02, 2003 at 08:05:46PM +0100, Martin Baehr wrote:
here is the first example though:
second: not sure if pasting from hilfe is a good idea. probably not, because, then you can't cut the examples and paste them for your own use...
i was however quite excited to see a few examples that look a lot nicer and compact in pike compared to perl :-)
Accessing Substrings //------------------------------ string str, value; int offset, count; value = str[offset..offset+count]; value = str[offset..];
string newstring, newtail; str = str[..offset-1]+newstring+str[offset+count..]; str = str[..offset-1]+newtail;
//------------------------------ // get a 5-byte string, skip 3, then grab 2 8-byte strings, then the rest string leading, s1, s2, trailing; [leading, s1, s2, trailing] = array_sscanf(str, "%5s%*3s%8s%8s%s");
// split at five byte boundaries array fivers = array_sscanf(str, "%{%5s%}");
// chop string into individual characters array chars = str/"";
//------------------------------ // switching to hilfe: $ pike Pike v7.2 release 340 running Hilfe v2.0 (Incremental Pike Frontend)
str = "This is what you have";
Result: "This is what you have"
string first, start, rest, last, end, piece; int t = str[0];
Result: 84
first = str[0..0];
Result: "T"
start = str[5..5+1];
Result: "is"
rest = str[13..];
Result: "you have"
last = str[sizeof(str)-1..sizeof(str)-1];
Result: "e"
end = str[sizeof(str)-4..];
Result: "have"
piece = str[sizeof(str)-8..sizeof(str)-8+2];
Result: "you"
str = "This is what you have";
Result: "This is what you have"
str = replace(str, ([ " is ":" wasn't " ]) );
Result: "This wasn't what you have"
str = str[..sizeof(str)-13]+"ondrous";
Result: "This wasn't wondrous"
str = str[1..];
Result: "his wasn't wondrous"
str = str[..sizeof(str)-11];
Result: "his wasn'"
str = "This is what you have";
Result: "This is what you have"
str = replace(str[..4], ([ "is":"at" ]) )+str[5..];
Result: "That is what you have"
str = "make a hat";
Result: "make a hat"
[str[0], str[-1]] = ({ str[-1], str[0] }); str;
Result: "take a ham"
string a, b, c; a="To be or not to be";
Result: "To be or not to be"
b=a[6..11];
Result: "or not"
b=a[6..7]; c=a[3..4];
Result: "or" Result: "be"
write("%s\n%s\n", b, c);
or be Result: 6
//------------------------------------------------
string cut2fmt(int ... positions)
{ string template = ""; int lastpos = 1; foreach(positions, int place) { template += "A" + (place - lastpos) + " "; lastpos=place; } template += "A*"; return template; }
string fmt=cut2fmt(8, 14, 20, 26, 30);
Result: "A7 A6 A6 A6 A4 A*"
write(fmt+"\n");
A7 A6 A6 A6 A4 A* Result: 18
/ Brevbäraren
On Thu, Jan 02, 2003 at 09:45:01PM +0100, Peter Lundqvist (disjunkt) @ Pike (-) developers forum wrote:
// split at five byte boundaries array fivers = array_sscanf(str, "%{%5s%}");
What about array fivers = str/5; then? Is that considered uggly?
no, it's considered something i forgot about ;-) that is definetly better, thanks.
greetings, martin.
I would use that, or str/5.0 depending on the application.
/ Martin Nilsson (bygger parser
Previous text:
2003-01-02 21:40: Subject: Re: PLEAC
// split at five byte boundaries array fivers = array_sscanf(str, "%{%5s%}");
What about
array fivers = str/5;
then? Is that considered uggly?
/ Peter Lundqvist (disjunkt)
<curios> I have no pike handy at the moment. What is the difference between using a float and an integer? </curios>
/ Peter Lundqvist (disjunkt)
Previous text:
2003-01-02 21:45: Subject: Re: PLEAC
I would use that, or str/5.0 depending on the application.
/ Martin Nilsson (bygger parser
On Thu, Jan 02, 2003 at 10:15:01PM +0100, Peter Lundqvist (disjunkt) @ Pike (-) developers forum wrote:
<curios> I have no pike handy at the moment. What is the difference between using a float and an integer? </curios>
string str="123451234512345123";
Result: "123451234512345123"
array fivers = str/5;
Result: ({ /* 3 elements */ "12345", "12345", "12345" })
array fivers = str/5.0;
Result: ({ /* 4 elements */ "12345", "12345", "12345", "123" })
str/5 would be integer division which discards the leftovers.
greetings, martin.
In the last episode (Jan 02), Martin Baehr said:
On Thu, Jan 02, 2003 at 10:15:01PM +0100, Peter Lundqvist (disjunkt) @ Pike (-) developers forum wrote:
<curios> I have no pike handy at the moment. What is the difference between using a float and an integer? </curios>
string str="123451234512345123";
Result: "123451234512345123"
array fivers = str/5.0;
Result: ({ /* 4 elements */ "12345", "12345", "12345", "123" })
What's even more fun is
str/4.5;
(1) Result: ({ /* 4 elements */ "12345", "1234", "51234", "5123" })
I don't know how useful that is, but it does exactly what I expect dividing by a non-int value would do.
Don't forget,
| > str/-5; | (1) Result: ({ /* 3 elements */ | "45123", | "45123", | "45123" | }) | > str/-5.0; | (2) Result: ({ /* 4 elements */ | "123", | "45123", | "45123", | "45123" | })
:)
/ Mirar
Previous text:
2003-01-02 22:27: Subject: Re: PLEAC
In the last episode (Jan 02), Martin Baehr said:
On Thu, Jan 02, 2003 at 10:15:01PM +0100, Peter Lundqvist (disjunkt) @ Pike (-) developers forum wrote:
<curios> I have no pike handy at the moment. What is the difference between using a float and an integer? </curios>
string str="123451234512345123";
Result: "123451234512345123"
array fivers = str/5.0;
Result: ({ /* 4 elements */ "12345", "12345", "12345", "123" })
What's even more fun is
str/4.5;
(1) Result: ({ /* 4 elements */ "12345", "1234", "51234", "5123" })
I don't know how useful that is, but it does exactly what I expect dividing by a non-int value would do.
-- Dan Nelson dnelson@allantgroup.com
/ Brevbäraren
On Fri, Jan 03, 2003 at 12:20:02AM +0100, Mirar @ Pike developers forum wrote:
Don't forget, | > str/-5; | "45123", | > str/-5.0; | "123", | "45123",
cool! :-)
lets get on with it: (gotta do something while i attempt to get the pike 7.4 debian packages to compile on woody)
Establishing a Default Value //----------------------------- // use b if b is true, else c a = b || c;
// set x to y unless x is already true if(!x) x=y;
// use b if b is defined, else c // an undefined variable would be a compile time error. a= b?b:c; foo = bar || "DEFAULT VALUE"; dir = argv[0] || "/tmp"; dir = arrayp(ARGV) ? ARGV[0] : "/tmp"; count[shell||"/bin/sh"]++;
user = getenv("USER") || getenv("LOGNAME") || getpwuid(getuid())[0] || "Unknown uid number "+getuid();
if(!starting_point) starting_point = "Greenwich";
if(!sizeof(a)) a=b; // copy only if empty a=(sizeof(b)?b:c); // assign b if nonempty, else c
greetings, martin.
On Fri, Jan 03, 2003 at 02:06:35AM +0100, Martin Baehr wrote:
lets get on with it: (gotta do something while i attempt to get the pike 7.4 debian packages to compile on woody)
ahh, all build dependancies donwported, now pikeitself actually builds!
more translations:
Exchanging Values Without Using Temporary Variables
[var1, var2] = ({ var2, var1 }); // gee, i love this example. // it didn't even occur to me before // :-) temp = a; a = b; b = temp;
a = "alpha"; b = "omega"; [a, b] = ({ b, a });
[alpha, beta, production] = "January March August"/" "; [alpha, beta, production] = ({ beta, production, alpha });
greetings, martin.
// use b if b is defined, else c // an undefined variable would be a compile time error. a= b?b:c;
This sounds like a poor translation from a foreign concept Pike lacks.
If you were thinking of the Pikeish concept of definedness, such as whether something you indexed out of a mapping actually existed there, you would write (with b = my_mapping[some_index]):
a = zero_type(b) ? c : b;
/ Johan Sundström (a hugging punishment!)
Previous text:
2003-01-03 02:09: Subject: Re: PLEAC
On Fri, Jan 03, 2003 at 12:20:02AM +0100, Mirar @ Pike developers forum wrote:
Don't forget, | > str/-5; | "45123", | > str/-5.0; | "123", | "45123",
cool! :-)
lets get on with it: (gotta do something while i attempt to get the pike 7.4 debian packages to compile on woody)
Establishing a Default Value //----------------------------- // use b if b is true, else c a = b || c;
// set x to y unless x is already true if(!x) x=y;
// use b if b is defined, else c // an undefined variable would be a compile time error. a= b?b:c; foo = bar || "DEFAULT VALUE"; dir = argv[0] || "/tmp"; dir = arrayp(ARGV) ? ARGV[0] : "/tmp"; count[shell||"/bin/sh"]++;
user = getenv("USER") || getenv("LOGNAME") || getpwuid(getuid())[0] || "Unknown uid number "+getuid();
if(!starting_point) starting_point = "Greenwich";
if(!sizeof(a)) a=b; // copy only if empty a=(sizeof(b)?b:c); // assign b if nonempty, else c
greetings, martin.
/ Brevbäraren
On Fri, Jan 03, 2003 at 02:20:00AM +0100, Johan Sundström (a hugging punishment!) @ Pike (-) developers forum wrote:
// an undefined variable would be a compile time error. a= b?b:c;
This sounds like a poor translation from a foreign concept Pike lacks.
yes, abvioulsy, i was totally unsure what to do with that.
a = zero_type(b) ? c : b;
is indeed a lot better, and introduces a new pike feature at the same time...
greetings, martin.
An even better example than the mapping example is a function with optional arguments, I just realized;
// return b if b is defined (was supplied by the caller), else c int foo(int c, int|void b) { return zero_type(b) ? c : b; }
Where does one find the assignment descriptions?
/ Johan Sundström (a hugging punishment!)
Previous text:
2003-01-03 02:18: Subject: Re: PLEAC
// use b if b is defined, else c // an undefined variable would be a compile time error. a= b?b:c;
This sounds like a poor translation from a foreign concept Pike lacks.
If you were thinking of the Pikeish concept of definedness, such as whether something you indexed out of a mapping actually existed there, you would write (with b = my_mapping[some_index]):
a = zero_type(b) ? c : b;
/ Johan Sundström (a hugging punishment!)
You are probably on the right track. The problem description isn't a description but a title and a some Perl code. The most useful thing to do is what you have done, to interpret it in a context that makes sense for the language and make a useful example of how to solve an actual problem.
/ Martin Nilsson (bygger parser
Previous text:
2003-01-03 02:22: Subject: Re: PLEAC
An even better example than the mapping example is a function with optional arguments, I just realized;
// return b if b is defined (was supplied by the caller), else c int foo(int c, int|void b) { return zero_type(b) ? c : b; }
Where does one find the assignment descriptions?
/ Johan Sundström (a hugging punishment!)
On Fri, Jan 03, 2003 at 02:30:01AM +0100, Martin Nilsson (bygger parser @ Pike (-) developers forum wrote:
You are probably on the right track. The problem description isn't a description but a title and a some Perl code. The most useful thing to do is what you have done, to interpret it in a context that makes sense for the language and make a useful example of how to solve an actual problem.
yup, very true, that i don't come up with these myself just shows my lack of experience, yet on with it:
Converting Between ASCII Characters and Values:
string char="foo"; int num = char[0]; // gets the ascii value from the first char (that's // what ord() in perl does) char = String.int2char(num);
char = sprintf("%c",num); // the same as String.int2char(num) :-) write("Number %d is character %c\n", num, num); Number 101 is character e
string str; array arr; arr = (array)str; str = (string)arr;
int ascii_value = 'e'; // now 101 string character = String.int2char(101); // now "e"
write("Number %d is character %c\n", 101, 101);
array ascii_character_numbers = (array)"sample"; write("%s\n", ascii_character_numbers*" ");
string word = (string)ascii_character_numbers; string word = (string)({ 115, 97, 109, 112, 108, 101 }); // same write(word+"\n"); sample
string hal ="HAL"; array ascii = (array)hal; for(int i=0; i<sizeof(ascii); i++) { ascii[i]++; }
string ibm = (string)ascii; write(ibm+"\n"); // prints "IBM"
pike7.4 debian woody build seems almost done... :-)
greetings, martin.
I suggest you test your code examples too;
array ascii_character_numbers = (array)"sample"; write("%s\n", ascii_character_numbers*" ");
this needs a cast to array(string) before it will work as intended. Casting the string to an array(int) explicitly might also help up understandability a bit.
/ Johan Sundström (a hugging punishment!)
Previous text:
2003-01-03 02:54: Subject: Re: PLEAC
On Fri, Jan 03, 2003 at 02:30:01AM +0100, Martin Nilsson (bygger parser @ Pike (-) developers forum wrote:
You are probably on the right track. The problem description isn't a description but a title and a some Perl code. The most useful thing to do is what you have done, to interpret it in a context that makes sense for the language and make a useful example of how to solve an actual problem.
yup, very true, that i don't come up with these myself just shows my lack of experience, yet on with it:
Converting Between ASCII Characters and Values:
string char="foo"; int num = char[0]; // gets the ascii value from the first char (that's // what ord() in perl does) char = String.int2char(num);
char = sprintf("%c",num); // the same as String.int2char(num) :-) write("Number %d is character %c\n", num, num); Number 101 is character e
string str; array arr; arr = (array)str; str = (string)arr;
int ascii_value = 'e'; // now 101 string character = String.int2char(101); // now "e"
write("Number %d is character %c\n", 101, 101);
array ascii_character_numbers = (array)"sample"; write("%s\n", ascii_character_numbers*" ");
string word = (string)ascii_character_numbers; string word = (string)({ 115, 97, 109, 112, 108, 101 }); // same write(word+"\n"); sample
string hal ="HAL"; array ascii = (array)hal; for(int i=0; i<sizeof(ascii); i++) { ascii[i]++; }
string ibm = (string)ascii; write(ibm+"\n"); // prints "IBM"
pike7.4 debian woody build seems almost done... :-)
greetings, martin.
/ Brevbäraren
Or why not use the mighty might of sprintf:
write("%{%d %}\n", ascii_character_numbers);
/ Martin Nilsson (bygger parser
Previous text:
2003-01-03 03:07: Subject: Re: PLEAC
I suggest you test your code examples too;
array ascii_character_numbers = (array)"sample"; write("%s\n", ascii_character_numbers*" ");
this needs a cast to array(string) before it will work as intended. Casting the string to an array(int) explicitly might also help up understandability a bit.
/ Johan Sundström (a hugging punishment!)
write("Number %d is character %c\n", num, num); is more fun as write("Number %d is character %[0]c\n", num);
Also, we should not teach people to make loops of their own... string hal ="HAL"; array ascii = (array)hal; array ibm = ascii[*]+1; // or array ibm = map(ascii, `+, 1) write(ibm+"\n"); // prints "IBM"
/ Martin Nilsson (bygger parser
Previous text:
2003-01-03 02:54: Subject: Re: PLEAC
On Fri, Jan 03, 2003 at 02:30:01AM +0100, Martin Nilsson (bygger parser @ Pike (-) developers forum wrote:
You are probably on the right track. The problem description isn't a description but a title and a some Perl code. The most useful thing to do is what you have done, to interpret it in a context that makes sense for the language and make a useful example of how to solve an actual problem.
yup, very true, that i don't come up with these myself just shows my lack of experience, yet on with it:
Converting Between ASCII Characters and Values:
string char="foo"; int num = char[0]; // gets the ascii value from the first char (that's // what ord() in perl does) char = String.int2char(num);
char = sprintf("%c",num); // the same as String.int2char(num) :-) write("Number %d is character %c\n", num, num); Number 101 is character e
string str; array arr; arr = (array)str; str = (string)arr;
int ascii_value = 'e'; // now 101 string character = String.int2char(101); // now "e"
write("Number %d is character %c\n", 101, 101);
array ascii_character_numbers = (array)"sample"; write("%s\n", ascii_character_numbers*" ");
string word = (string)ascii_character_numbers; string word = (string)({ 115, 97, 109, 112, 108, 101 }); // same write(word+"\n"); sample
string hal ="HAL"; array ascii = (array)hal; for(int i=0; i<sizeof(ascii); i++) { ascii[i]++; }
string ibm = (string)ascii; write(ibm+"\n"); // prints "IBM"
pike7.4 debian woody build seems almost done... :-)
greetings, martin.
/ Brevbäraren
i went aread and submitted my first batch to pleac after including all your suggestions. (thanks)
i'll forward any contributions you make...
On Fri, Jan 03, 2003 at 05:11:32AM +0100, Martin Baehr wrote:
i went aread and submitted my first batch to pleac
the submission has been published. looking forwatd to your contributions...
greetings, martin.
Looking at their first integer example, checking whether a string is a valid number, shouldn't we let zero_type((int)"") be one?
/ Martin Nilsson (Åskblod)
Previous text:
2003-01-10 18:23: Subject: Re: PLEAC
On Fri, Jan 03, 2003 at 05:11:32AM +0100, Martin Baehr wrote:
i went aread and submitted my first batch to pleac
the submission has been published. looking forwatd to your contributions...
greetings, martin.
interested in doing pike programming, sTeam/caudium/pike/roxen training, sTeam/caudium/roxen and/or unix system administration anywhere in the world. -- pike programmer working in europe csl-gmbh.net open-steam.org (www.archlab|(www|db).hb2).tuwien.ac.at unix bahai.or.at iaeste.(tuwien.ac|or).at systemadministrator (stuts|black.linux-m68k).org is.(schon.org|root.at) Martin Bähr http://www.iaeste.or.at/~mbaehr/
/ Brevbäraren
And should (float) really behave like this?
(float)"";
(5) Result: 0.000000
/ Martin Nilsson (Åskblod)
Previous text:
2003-01-10 18:29: Subject: Re: PLEAC
Looking at their first integer example, checking whether a string is a valid number, shouldn't we let zero_type((int)"") be one?
/ Martin Nilsson (Åskblod)
It's more consistent than an error, considering that casts from strings to numbers always succeeds by simply ignoring trailing garbage. I wouldn't mind if that policy was changed to something more stringent, though.
/ Martin Stjernholm, Roxen IS
Previous text:
2003-01-10 18:31: Subject: Re: PLEAC
And should (float) really behave like this?
(float)"";
(5) Result: 0.000000
/ Martin Nilsson (Åskblod)
On Fri, Jan 03, 2003 at 02:25:01AM +0100, Johan Sundström (a hugging punishment!) @ Pike (-) developers forum wrote:
Where does one find the assignment descriptions?
you mean the book?
well, in the book :-)
that's what i meant earlier, instead of mindlessly translating we should actually have to read the book to see what the intentions of the examples are, so that we can give an example that fits the intention and not just the code...
i'll just continue though until pike is built. (is anybody gonna join? :-)
greetings, martin.
I thought we already did, helping you out with helpful suggestions and criticism. :-)
/ Johan Sundström (a hugging punishment!)
Previous text:
2003-01-03 02:34: Subject: Re: PLEAC
On Fri, Jan 03, 2003 at 02:25:01AM +0100, Johan Sundström (a hugging punishment!) @ Pike (-) developers forum wrote:
Where does one find the assignment descriptions?
you mean the book?
well, in the book :-)
that's what i meant earlier, instead of mindlessly translating we should actually have to read the book to see what the intentions of the examples are, so that we can give an example that fits the intention and not just the code...
i'll just continue though until pike is built. (is anybody gonna join? :-)
greetings, martin.
/ Brevbäraren
On Fri, Jan 03, 2003 at 03:10:02AM +0100, Johan Sundström (a hugging punishment!) @ Pike (-) developers forum wrote:
I thought we already did, helping you out with helpful suggestions and criticism. :-)
oh sure. but as you know, it's never enough ;-) translate some examples too;
if everybody does a few, we should be able to chew off a sizable bit of this.
I'll try to help out in two/three weeks time (if there's anything left ;-)
/ Peter Lundqvist (disjunkt)
Previous text:
2003-01-03 03:25: Subject: Re: PLEAC
On Fri, Jan 03, 2003 at 03:10:02AM +0100, Johan Sundström (a hugging punishment!) @ Pike (-) developers forum wrote:
I thought we already did, helping you out with helpful suggestions and criticism. :-)
oh sure. but as you know, it's never enough ;-) translate some examples too;
if everybody does a few, we should be able to chew off a sizable bit of this.
/ Brevbäraren
On Fri, Jan 03, 2003 at 06:30:00AM +0100, Peter Lundqvist (disjunkt) @ Pike (-) developers forum wrote:
I'll try to help out in two/three weeks time (if there's anything left ;-)
great! btw. i have asked around in out office, and found two people who have the perl cookbook. this means that i am now able to provide the problem descriptions that the examples are meant to solve.
doing that we can come up with pike examples that are not just copies of the perl code.
the problem descriptions are very short (and i rephrased them and made them even shorter :-) so i may be willing to go through the whole book and provide them. i am certainly willing to provide some on request.
if you want to help, try to come up with various examples that fit the description without looking at the perl code.
here goes the first chapter: 1.5: handle a string one char at a time. 1.6: reverse a string by chars or by words 1.7: convert tabs to spaces if you are not sure that tabs will look right. convert spaces to tabs to make the string smaller. 1.8: evaluate a variable contained inside a string like: "You owe $debt to me." this is not possible in pike, but an example could be made trying to evaluate a shell variable for a system command or a simple example of pike evaluation: you want to value of a variable whose name is contained in a string 1.9: convert upper to lower case and back 1.10: evaluate functioncalls or expressions from a string. typical perl application here, the best i can think of is sprintf, which i always use if i have to mix a lot of text and functioncalls. 1.11: you want to indent text when using #"...", to make your code look more nice, but you don't want that indentation to appear in your string value. (my) solution: stop reading that perl cookbook, it gives you funny ideas. not even in perl i would want to indent the text, because the idea should be, to see the text exactly as it would appear. comment: if you can think of a reason why i am wrong, i am sure you can come up with an example for a solution too :-) 1.12: wordwrapping ling strings to fit a certain line length 1.13: escape certain characters eg % for sprintf... a good place to show the various quoting functions html, mysql, ... 1.14: remove leading or trailing whitespace 1.15: handle csv files with quoted commas and escaped quotes 1.16: match strings according to similar sounds (is there anything for that in pike?) 1.17: program example: this program takes a two column table, and an input string. the words of the first column are replaces with the second in the inputstring (turn the table into a mapping, and apply replace()) 1.18: program example: grep from ps according to your search criteria: % psgrep '/sh\b/' // all lines with "sh" at the end of a word % psgrep 'command =~ /sh$/' // processes with the command ending in "sh" % psgrep 'uid < 10' // processes with a uid below 10 % psgrep 'command =~ /^-/' 'tty ne "?"' // loginshells with active ttys % psgrep 'tty =~ /^[p-t]/' // processes with pseudo ttys % psgrep 'uid && tty eq "?"' // non root without tty % psgrep 'size > 10 * 2**10' 'uid != 0' // huge nonroot processes
dir = arrayp(ARGV) ? ARGV[0] : "/tmp";
In the natural application ARGV is defined as array and is always assigned an array of size at least 1. The following is not unreasonable though:
ARGV = ARGV[1..]; // remove program dir = sizeof(ARGV) ? ARGV[0] : "/tmp";
/ Martin Nilsson (bygger parser
Previous text:
2003-01-03 02:09: Subject: Re: PLEAC
On Fri, Jan 03, 2003 at 12:20:02AM +0100, Mirar @ Pike developers forum wrote:
Don't forget, | > str/-5; | "45123", | > str/-5.0; | "123", | "45123",
cool! :-)
lets get on with it: (gotta do something while i attempt to get the pike 7.4 debian packages to compile on woody)
Establishing a Default Value //----------------------------- // use b if b is true, else c a = b || c;
// set x to y unless x is already true if(!x) x=y;
// use b if b is defined, else c // an undefined variable would be a compile time error. a= b?b:c; foo = bar || "DEFAULT VALUE"; dir = argv[0] || "/tmp"; dir = arrayp(ARGV) ? ARGV[0] : "/tmp"; count[shell||"/bin/sh"]++;
user = getenv("USER") || getenv("LOGNAME") || getpwuid(getuid())[0] || "Unknown uid number "+getuid();
if(!starting_point) starting_point = "Greenwich";
if(!sizeof(a)) a=b; // copy only if empty a=(sizeof(b)?b:c); // assign b if nonempty, else c
greetings, martin.
/ Brevbäraren
Truncation.
"abcdefg"/3;
(1) Result: ({ /* 2 elements */ "abc", "def" })
"abcdefg"/3.0;
(2) Result: ({ /* 3 elements */ "abc", "def", "g" })
/ Martin Nilsson (bygger parser
Previous text:
2003-01-02 22:10: Subject: Re: PLEAC
<curios> I have no pike handy at the moment. What is the difference between using a float and an integer? </curios>
/ Peter Lundqvist (disjunkt)
Not at all; it's even better than Martin's code, which generated an array(array(string)). :-)
/ Johan Sundström (a hugging punishment!)
Previous text:
2003-01-02 21:40: Subject: Re: PLEAC
// split at five byte boundaries array fivers = array_sscanf(str, "%{%5s%}");
What about
array fivers = str/5;
then? Is that considered uggly?
/ Peter Lundqvist (disjunkt)
On Fri, Jan 03, 2003 at 02:00:03AM +0100, Johan Sundström (a hugging punishment!) @ Pike (-) developers forum wrote:
Not at all; it's even better than Martin's code, which generated an array(array(string)). :-)
oops, quite right, didn't look close enough :-)
the best part of this excercize is actually that i learn something new with every bit i get done.
greetings, martin.
pike-devel@lists.lysator.liu.se