Re: Trying to make a new operator
Steffen Schwigon wrote: snip Thanks for reporting the solution back. And it even works with unicode operators. Looks like we finally really get our ankh, pentagram, and that smiley teddy bear from that Grateful Dead album. (*) :-) Thanks to Unicode, thanks to Pugs So hopefully in the same spirit : sub infix:☥ {...}; sub infix:☆ {...}; sub infix:☺ {...}; (3 ☥ 40 ☆ 7 ☺ 50).say; sub infix:☥ ($l,$r) { The ~ $l ~ wise men spent ~ $r ~ days }; sub infix:☆ ($l,$r) { $l ~ following a star in the ~ $r ~ -th heaven }; sub infix:☺ ($l,$r) { $l ~ to become very happy for ~ $r ~ days and nights }; Biggest problems are the following: a) finding the symbols - I had to use two editors, and getting them to show them on screen b) mixing types. My version of pugs does not respect the white space at the start and end of strings. Also if the functions are given as text $l more text, all the white space is excluded. Not sure if this is a feature or a non-feature. Richard
Re: Trying to make a new operator
On 9/22/06, Richard Hainsworth [EMAIL PROTECTED] wrote: Biggest problems are the following: a) finding the symbols - I had to use two editors, and getting them to show them on screen Good place to see all of the symbols in Unicode is http://unicode.org/charts/symbols.html (a lot of PDF-files there) You could also try to find the proper symbol from http://www.iam.uni-bonn.de/~alt/html/unicode_3.html and then copy-pasting it to your editor. This seemed to work for me with Firefox+KWrite after I changed the encoding to UTF-8 (but my font didn't show all the symbols). b) mixing types. My version of pugs does not respect the white space at the start and end of strings. Also if the functions are given as text $l more text, all the white space is excluded. Not sure if this is a feature or a non-feature. text more text creates a list, not a string, and is meant to ignore the extra spaces because spaces are only used to delimit the list-items. (I'm not sure about ...) If you want to create strings, just use the quotes like here: sub infix:☥ {...}; sub infix:☆ {...}; sub infix:☺ {...}; (3 ☥ 40 ☆ 7 ☺ 50).say; sub infix:☥ ($l,$r) { return The $l wise men spent $r days; }; sub infix:☆ ($l,$r) { return $l following a star in the $r-th heaven; }; sub infix:☺ ($l,$r) { return $l to become very happy for $r days and nights }; -- Markus Laire
Re: Trying to make a new operator
Thanks for help. For anyone else, the following works. sub infix:grew_by_to {...}; (32 grew_by_to 48).say; sub infix:grew_by_to ($left, $right) { return ($right/$left - 1) * 100 ~ '%'; }; Yuval Kogman wrote: On Sun, Sep 17, 2006 at 16:35:39 +0100, Daniel Hulme wrote: What am I doing wrong? Sounds like you need to define (or at least declare) the new operator before you use it. Perl 6, like Perl 5 compiles with a single pass, so when you are using your random operator, it hasn't yet read the declaration further down the file. s/use/parse/;
Re: Trying to make a new operator
Richard Hainsworth [EMAIL PROTECTED] writes: Thanks for help. For anyone else, the following works. sub infix:grew_by_to {...}; (32 grew_by_to 48).say; sub infix:grew_by_to ($left, $right) { return ($right/$left - 1) * 100 ~ '%'; }; Thanks for reporting the solution back. And it even works with unicode operators. Looks like we finally really get our ankh, pentagram, and that smiley teddy bear from that Grateful Dead album. (*) :-) Thanks to Unicode, thanks to Pugs. (*) The senior ones of us possibly remember the good old days: http://www.perl.org/yapc/2002/movies/themovie/ GreetinX Steffen -- Steffen Schwigon [EMAIL PROTECTED] Dresden Perl Mongers http://dresden-pm.org/
Trying to make a new operator
I tried to make a new growth operator. The code was (32 + 48).say; sub infix:+ ($left,$right) { return 100 * ($right/$left -1); }; $pugs ./p6test.p6 returns with 50 But if I change the + character to (say) a cyrillic letter Д, I get the following error: $ pugs ./p6test.p6 *** unexpected \1041 expecting operator or ) at ./p6test.p6 line 1, column 5 I also tried other latin characters, but I get errors. It seems I can change an existing operator, but not introduce another. What am I doing wrong?
Re: Trying to make a new operator
What am I doing wrong? Sounds like you need to define (or at least declare) the new operator before you use it. Perl 6, like Perl 5 compiles with a single pass, so when you are using your random operator, it hasn't yet read the declaration further down the file. It does its best to DTRT with most functions, but when you're defining arbitrarily random operators, it can only be so clever. -- Sufficiently advanced humour is indistinguishable from tedium. corollary: Humour distinguishable from tedium is insufficiently advanced. http://surreal.istic.org/ Hack code until it works, then stop. pgptQIbTaHijD.pgp Description: PGP signature
Re: Trying to make a new operator
On Sun, Sep 17, 2006 at 16:35:39 +0100, Daniel Hulme wrote: What am I doing wrong? Sounds like you need to define (or at least declare) the new operator before you use it. Perl 6, like Perl 5 compiles with a single pass, so when you are using your random operator, it hasn't yet read the declaration further down the file. s/use/parse/; -- Yuval Kogman [EMAIL PROTECTED] http://nothingmuch.woobling.org 0xEBD27418 pgpecCgUDpDGS.pgp Description: PGP signature