Re: Apocalypse 3
by blakem (Monsignor) on Oct 04, 2001 at 02:14 UTC
|
I grepped it for the forbidden information that put my life in jeopardy a few days ago:
Binary //
A binary // operator is the defaulting operator. That is:
$a // $b
is short for:
defined($a) ?? $a :: $b # [note: this is the new ?: -- bla
+kem]
except that the left side is evaluated only once. It will work on arrays and hashes as well as scalars. It also has a corresponding assignment operator, which only does the assignment if the left side is undefined:
$pi //= 3;
That's actually quite cool... currently when people use
$a ||= b they often times really mean $a = defined ($a) ? $a : $b and now we'll have an easy way to do it..
//= gets a ++ in my book
-Blake
| [reply] [d/l] [select] |
|
| [reply] |
|
What if you want to divide by a regex? That could also have two slashes after a term.
| [reply] |
|
Perl might try to correct the parsing of:
$x = $y //foo/;
from
$x = $y // foo/;
to
$x = $y / /foo/;
_____________________________________________________
Jeff[japhy]Pinyan:
Perl,
regex,
and perl
hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??; | [reply] [d/l] [select] |
|
|
|
|
/// or // should be more like s/// or m//
but what is $foo // or $brr /// (nothing if i remember correctly)
$foo // expr has nothing to do with regex
oh "divide" by a regex, mmmkay, maybe something like
$_ = "2k4";
print ( 49 / /\d/); #?
(i can't see how what you're suggesting can occur, or i'm misunderstanding) | [reply] [d/l] [select] |
|
Can you give one example where dividing by a regexp is not hopelessly obfuscatory? If I saw someone trying to do that in production code, I would hesitate between shooting them first and then throwing them out the window, or doing it the other way around :)
Although I would be slightly more worried about the ambiguity between // "that unless defined this" and // "rematch according to the last successfully compiled regexp" (although maybe that's going away in Perl 6, I've lost track). And anyway, I'll let Larry and Damian worry about that for the time being.
--g r i n d e r
| [reply] [d/l] |
Re (tilly) 1: Apocalypse 3
by tilly (Archbishop) on Oct 04, 2001 at 16:32 UTC
|
Hmmm...
:=, laziness, he is thinking big. I hope he thinks through
the consequences. Otherwise he may just find me submitting
a bug report about the following code:
$x := $y + 5;
$y := $x -3;
print "Answer: ($x, $y)\n";
Unless, of course, it works. In which case I shall probably
sacrifice burnt offerings at TheDamian's altar. (And then
try to break it with a non-linear system of equations.)
In a similar and more reasonable vein, I hope that his
thinking about laziness, :=, and slice mechanics goes far
enough that you can readily (for instance) define the
Fibonacci sequence as a lazy list and have it work right... | [reply] [d/l] |
|
I'm afraid := isn't the fully fledged unification operator you're hoping for. As I'll explain in
Exegesis 3, it's really just an aliasing mechanism.
So your declarative emergent $x and
$y values aren't actually being declared, or emerging
either. :-(
In fact, you'd just get $x aliased to the
(constant) result of $y+5 (which will
be 5 if there's no prior assignment to
$y), and then $y aliased to
the (constant) result of $x-3 (which will be
2 under the previous assumption).
However, as a consolation prize for having suggested
human sacrifice to me (you did intend it to be a human burnt offering, didn't you???), I have now added a Data::Unification module to my
ToDo list. ;-)
Damian
| [reply] [d/l] [select] |
|
Hi Damian,
In the Section "Applied Laziness 101" of the third Exegesis, you wrote:
Of course, if we'd written:
my ($name, $vers, $status, $costs, @and_the_rest) = <fh>;
The the entire file would have been read
Did you mean:
my ($name, $vers, $status, $costs, *@and_the_rest) = <fh>;
or will array assignment work differently on the diamond operator?
Simon Flack ($code or die)
$,=reverse'"ro_';s,$,\$,;s,$,lc ref sub{},e;$,
=~y'_"' ';eval"die";print $_,lc substr$@,0,3;
| [reply] |
|
Re: Apocalypse 3
by chipmunk (Parson) on Oct 06, 2001 at 19:15 UTC
|
Maybe I just haven't gotten my head around these new semantics for colons, but I can't resolve the described uses of colon with a function call, both for following an indirect object and for preceding an adverb.
First, Damian explains that colon is used to mark the indirect object for print:
print $filehandle : $text_to_print;
Later, Damian explains that colon is used to mark the adverb for a function:
print sum @numbers_to_sum : $filter;
In the first case, the syntax is function indirect-object : direct-object, and in the second case function direct-object : adverb. How is this apparent ambiguity resolved? | [reply] [d/l] [select] |
|
...colon is used to mark the indirect object...colon is used to mark the adverb...How is this apparent ambiguity resolved?
Ambiguity
Is a pebble on the road
To enlightenment.
There is no "adverb",
Nor an indirect object,
Nor direct objects.
There's only colon --
With arguments before it
And others after.
What we call those args --
"Indirect", "adverb", "direct" --
Is pure convention.
It's up to each sub
To decide how arguments
Are interpreted.
print may choose to treat
Pre-colon as filehandle,
Post-colon as list.
On the other hand,
sum might choose: Pre-colon -- list,
Post-colon -- adverb.
It's like the story
Of two monks and Hui-neng
Discussing a flag:
"The flag is moving?"
"Or is it the wind moving?"
"It's your mind that moves!"
Now we have the tale
Of Chipmunk-san and Con Wei
Discussing colons:
"Colons mean 'adverb'?"
"Colons mean 'indirectly'?"
"Colons mean...colon!"
It's how you use them
In your sub that determines
What purpose they serve.
| [reply] |
|
| [reply] |
|
Re: Apocalypse 3
by petral (Curate) on Oct 05, 2001 at 23:07 UTC
|
| [reply] |