Newsgroups: perl.perl6.language
From: w...@sci.fi (Wolverian)
Date: Thu, 7 Jul 2005 20:18:40 +0300
Local: Thurs, Jul 7 2005 1:18 pm
Subject: File.seek() interface
Hello, gaal is porting the Perl 5 filehandle functions to a Perl 6 OO $fh.seek(-10, SEEK_END); Instead of globals, how about a :from adverb? $fh.seek(-10, :from<end>); Or maybe we don't need such an adverb at all, and instead use $fh.seek($fh.end - 10); I'm a pretty high level guy, so I don't know about the performance Subject to change when it comes to the Perl 6 Unicode semantics, of Any thoughts/decisions? --
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| |||||||||||||||||
Newsgroups: perl.perl6.language
From: d...@whipp.name (Dave Whipp)
Date: Thu, 07 Jul 2005 11:44:00 -0700
Subject: Re: File.seek() interface
Wolverian wrote: We should approach this from the perspective that $fh is an iterator, so > Or maybe we don't need such an adverb at all, and instead use > $fh.seek($fh.end - 10); > I'm a pretty high level guy, so I don't know about the performance the general problem is "how do we navigate a random-access iterator?". I have a feeling that the "correct" semantics are closer to: $fh = $fh.file.end - 10 though the short form ($fh = $fh.end - 10) is a reasonable shortcut. You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
Newsgroups: perl.perl6.language
From: par...@seamons.com (Paul Seamons)
Date: Thu, 7 Jul 2005 14:15:19 -0600
Local: Thurs, Jul 7 2005 4:15 pm
Subject: Re: File.seek() interface
> We should approach this from the perspective that $fh is an iterator, so Well - I kind of thought that $fh was a filehandle that knew how to behave > the general problem is "how do we navigate a random-access iterator?". like an iterator if asked to do so. There are too many applications that need to jump around using seek. The options that need to be there are: Now it could be simplified a bit to the following cases: $fh.seek(10); # from the beginning forward 10 Paul You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
Newsgroups: perl.perl6.language
From: la...@wall.org (Larry Wall)
Date: Thu, 7 Jul 2005 17:58:53 -0700
Local: Thurs, Jul 7 2005 8:58 pm
Subject: Re: File.seek() interface
On Thu, Jul 07, 2005 at 02:15:19PM -0600, Paul Seamons wrote: : > We should approach this from the perspective that $fh is an iterator, so : > the general problem is "how do we navigate a random-access iterator?". : : Well - I kind of thought that $fh was a filehandle that knew how to behave : like an iterator if asked to do so. Yes, basically. And they fall into that class of iterators that may : There are too many applications that We need to have a POSIXly correct layer, but that's no reason not to have I realize we most of us come from the POSIXly-correct worldview In the discussion of seek(), this primarily means that you must keep At the same time, all relative navigation *must* specify the units. : The options that need to be there are: Apart from the units and allignment problem, does $fh.seek(-0) mean : $fh.seek(10, :relative); # from the current location forward 10 Again, 10 whats? Bytes? Codepoints? Lines? I think I'd actually like to divorce the notion of going to a $fh.pos = $fh.pos + 10`lines Arguably, we could probably admit $fh.pos = 10`bytes for the case of seeking from the begining. But I'd kind of like $fh.pos = 10 to be considered an error. Note also that we can treat string positions exactly the same way. Larry You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
Newsgroups: perl.perl6.language
From: ydbx...@yahoo.com (Paul Hodges)
Date: Thu, 7 Jul 2005 18:15:03 -0700 (PDT)
Local: Thurs, Jul 7 2005 9:15 pm
Subject: Re: File.seek() interface
--- Larry Wall <la...@wall.org> wrote: > Arguably, we could probably admit It seems a logical extension also to say > $fh.pos = 10`bytes > for the case of seeking from the begining. But I'd kind of like > $fh.pos = 10 > to be considered an error. $fh.pos += 10`bytes as shorthand for $fh.pos = $fh.cur + 10`bytes Likewise for -= But then that begs the questions of *= (not too nuts), /= (same), Am I reaching? Paul ____________________________________________________ You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
Newsgroups: perl.perl6.language
From: la...@wall.org (Larry Wall)
Date: Thu, 7 Jul 2005 20:17:59 -0700
Local: Thurs, Jul 7 2005 11:17 pm
Subject: Re: File.seek() interface
On Thu, Jul 07, 2005 at 06:15:03PM -0700, Paul Hodges wrote: : : : --- Larry Wall <la...@wall.org> wrote: : > Arguably, we could probably admit : > : > $fh.pos = 10`bytes : > : > for the case of seeking from the begining. But I'd kind of like : > : > $fh.pos = 10 : > : > to be considered an error. : : It seems a logical extension also to say : : $fh.pos += 10`bytes : : as shorthand for : : $fh.pos = $fh.cur + 10`bytes .pos and .cur are the same thing. So just call them both .pos, I think. : Likewise for -= No. The stupid people are the ones proposing to outlaw stupidity. :-) Larry You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
Newsgroups: perl.perl6.language
From: w...@sci.fi (Wolverian)
Date: Fri, 8 Jul 2005 05:03:21 +0300
Local: Thurs, Jul 7 2005 10:03 pm
Subject: Re: File.seek() interface
sub *infix:<`> (Num $amount, Unit $class) { $class.new($amount) } Or so? Now I'm tempted to make it a generic infix .new. (args)`Class; It's almost as confusing as SML! --
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| |||||||||||||||||
| |||||||||||||
Newsgroups: perl.perl6.language
From: ja...@mastros.biz (James Mastros)
Date: Sat, 09 Jul 2005 08:02:35 +0200
Local: Sat, Jul 9 2005 2:02 am
Subject: Re: backtick units (Was: File.seek() interface)
Wolverian wrote: I was hoping it was going to be in the standard library, but non-core. > On Thu, Jul 07, 2005 at 05:58:53PM -0700, Larry Wall wrote: >> $fh.pos = $fh.pos + 10`lines > I'm sorry if this has been discussed, but is the ` going to be in Using it for manipulating .pos, OTOH, would seem to make it core, which I suppose is probably worth it. > How does it work, though? The problem with it is that somehow we have to get 5`m / 30`s to work, > sub *infix:<`> (Num $amount, Unit $class) { $class.new($amount) } > Or so? > Now I'm tempted to make it a generic infix .new. > (args)`Class; even though m is an operator, which AFAIK means it needs to be a macro, or the moral equivalent (is parsed). Also, having every unit be a like-named class would very much crowd the -=- James Mastros You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
| |||||||||||||
Newsgroups: perl.perl6.language
From: w...@sci.fi (Wolverian)
Date: Thu, 7 Jul 2005 23:22:41 +0300
Local: Thurs, Jul 7 2005 4:22 pm
Subject: Re: File.seek() interface
Would it be possible to make this work, efficiently: for =$fh[-10 ...] -> $line { ... } to iterate over the last ten lines? Can we generalise that to be as performance-effective as seek()? Okay, that was two questions. --
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| |||||||||||||||||
Newsgroups: perl.perl6.language
From: lrpal...@gmail.com (Luke Palmer)
Date: Thu, 7 Jul 2005 16:42:57 -0600
Local: Thurs, Jul 7 2005 6:42 pm
Subject: Re: File.seek() interface
On 7/7/05, wolverian <w...@sci.fi> wrote:
> On Thu, Jul 07, 2005 at 08:18:40PM +0300, wolverian wrote: No. Most notably because -10 ... gives (-10, -9, ... -1, 0, 1, 2, 3, > > I'm a pretty high level guy, so I don't know about the performance > > implications of that. Maybe we want to keep seek() low level, anyway. > Sorry about replying to myself, but I want to ask a further question on > Would it be possible to make this work, efficiently: > for =$fh[-10 ...] -> $line { ... } > to iterate over the last ten lines? ...). I also don't think that without a special interface filehandles can behave as an array of lines. If they could, then you'd have: for $fh[-10..-1] -> $line {...} > Can we generalise that to be as performance-effective as seek()? Perhaps. That's what tail(1) does. But it's a tricky problem. You have to guess where the end should be, then do a binary search on the number of lines after your position. Sounds like a job for a specialized module to me. If you don't care about speed, then I suppose you could even do: for [ =$fh ].[-10..-1] -> $line {...} Which won't be speed efficient, and may or may not be memory Luke You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
| Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy |
| ©2009 Google |