(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?
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.
s/use/parse/;
--
Yuval Kogman <nothi...@woobling.org>
http://nothingmuch.woobling.org 0xEBD27418
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 <schw...@webit.de>
Dresden Perl Mongers <http://dresden-pm.org/>
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
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