Front page | perl.perl6.language |
Postings from April 2003
Synopsis Questions
Thread Next
From:
Angel Faus
Date:
April 10, 2003 16:13
Subject:
Synopsis Questions
Message ID:
200304110322.36698.afaus@corp.vlex.com
Hi,
First of all, thanks very much for the Synopsis 6 (very beautifull
indeed).
Some simple random questions:
- Variable types:
1st) Can we use variable types in subroutines signatures??
2nd) In:
sub add(int $x, int $y) {$x + $y}
Do we have enough information to allow the compiler to optimize this
sub?
I mean: $x and $y could be both tied to some heavyweight
implementation, so the compiler won't ever be able to use the type
system for anything useful (in terms of speed)...
Maybe the solution is to not allow mixing variable types and
lower-case value types:
my bit $b is Persistent; # error
my Bit $b is Persistent; # ok
After all, lower-case types are expected to be really, eh, simple.
They cannot have run-time properties associated to them, and one
could argue that a variable type is just a bunch of
FETCH/STORE/DELETE/etc. properties associated to that variable.
3rd) (more open, philosophical kind of question) What are the
legitimate uses of Variable Types? I mean, what can we do that would
be otherwise be impossible? (assuming a class system and some support
for Aspect-Oriented programming)
This may be look a silly question, but whenever I've used tied
variables in perl, I could have done with class-based overloading of
common operations (assignment, fetch, etc..).
Do we really need the dual type system?
- Hierarchical types:
Run-time time type checking is no problem for "simple" types because
it is reasonably fast. But run-time validation of hierarchical types
can be very expensive.
How do we handle this?
sub third_one(@x of Int) {
return @x[3]
}
my @a = 1..1000;
foo(@a);
Is it compile-time error or run-time slow-down?
- The leave Function:
Just to be sure about it: Are anonymous subs (like the -> sub in for
statements) exited with return or with leave?
If exited with return:
sub foo {
for 1..10 -> $i {
return if $i > 0;
}
print "abrakadabra";
}
foo(); # this prints "abrakadabra"
But if exited with leave:
sub foo {
my &is_long = sub {
if length($_) > 100 {return 1} else {return 0}
}
my $result = is_long("not so long sentence"):
print $result;
}
foo(); # this prints nothing because we jump
# over "print"
Mmm..... This is odd. I am quite sure I got something wrong here..
- Assuming on "use"
(use IO::Logging).assuming(logfile => ".log");
What happens if some subroutine in IO::Logging doesn't have the
"logfile" parameter. Is it a compile-time error, or will it be smart
and only curry on the functions that do use the "logfile" parameter?
That's all for now.. :-) Thanks againt to all for the excellent work.
-angel
Thread Next
-
Synopsis Questions
by Angel Faus