(I'm sorry if this topic has already been discussed.)
one day a friend asked if Perl 5 had a REPL facility. (Read-Eval-Print-Loop). I told him it has perl -de0, which is different in that it does not preserve the lexical scope across evaluated lines. This is because eval STRING creates its own scope, in which the string is then evaluated.
You can hack around this with a recursive eval(), which will eventually blow the stack. I wrote a short module to do this, but never released it. Have others done this? :)
To get to the real topic:
In Perl 6, the generic solution to fix this (if one wants to fix it) seems, to me, to be to add a .eval method to objects that represent scopes. I'm not sure if scopes are first class values in Perl 6. Are they? How do you get the current scope as an object? Are scopes just Code objects?
On #perl6, theorbtwo wasn't sure if .eval should be a method on coderefs or blocks. Is there a difference between the two? I always hated this about Ruby; there seems to be no practical value to the separation.
Also, are blocks/coderefs/scopes continuations? Should .eval be a method in Continuation?
On Fri, Apr 08, 2005 at 05:03:11PM +0300, wolverian wrote:
Hi wolverian,
> one day a friend asked if Perl 5 had a REPL facility. > (Read-Eval-Print-Loop). I told him it has perl -de0, which is different > [...] > In Perl 6, the generic solution to fix this (if one wants to fix it) > seems, to me, to be to add a .eval method to objects that represent > scopes. I'm not sure if scopes are first class values in Perl 6. Are > they? How do you get the current scope as an object? Are scopes just > Code objects?
I'm unclear on what you're looking for. Are you trying to get a way to do interactive coding in P6? Or the ability to "freeze" a scope and execute it later? Or something else?
>In Perl 6, the generic solution to fix this (if one wants to fix it) >seems, to me, to be to add a .eval method to objects that represent >scopes. I'm not sure if scopes are first class values in Perl 6. Are >they? How do you get the current scope as an object? Are scopes just >Code objects?
>On #perl6, theorbtwo wasn't sure if .eval should be a method on coderefs >or blocks. Is there a difference between the two? I always hated this >about Ruby; there seems to be no practical value to the separation.
>Also, are blocks/coderefs/scopes continuations? Should .eval be a method >in Continuation?
I'm having a bit of trouble following you, but I can tell you that the VM portion treats continuations as well as lexical scopes or pads as first class Parrot objects (or PMCs).
I cannot say how much Perl6 will expose to the high level language.
Can you tell me what your idea of a "scope" is? I'm thinking a continuation, and if that is what you are thinking, I'm thinking the answer to your question is yes.
On Fri, Apr 08, 2005 at 08:35:30AM -0700, David Storrs wrote: > I'm unclear on what you're looking for. Are you trying to get a way > to do interactive coding in P6? Or the ability to "freeze" a scope > and execute it later? Or something else?
Neither in itself. I'm looking for a way to refer to scopes programmatically. I'm also asking if they are continuations, or blocks, or coderefs, or are those all the same?
The two things you mention are effects of being able to refer to scopes in such a fashion. I do want both, but the real question isn't if they are possible, but about what blocks, coderefs and scopes are.
I'm sorry if I was unclear. I probably should have spent more time writing the post. :)
On Fri, Apr 08, 2005 at 12:18:45PM -0400, MrJoltCola wrote: > I cannot say how much Perl6 will expose to the high level language.
That is what I'm wondering about. I'm sorry I was so unclear.
> Can you tell me what your idea of a "scope" is? I'm thinking a > continuation, and if that is what you are thinking, I'm thinking the > answer to your question is yes.
Yes. I want to know how Perl 6 exposes continuations, and how to get one for, say, the current lexical scope, and if it has a method on it that lets me evaluate code in that context (or some other way to do that).
wolverian <w...@sci.fi> writes: > On Fri, Apr 08, 2005 at 12:18:45PM -0400, MrJoltCola wrote: >> I cannot say how much Perl6 will expose to the high level language.
> That is what I'm wondering about. I'm sorry I was so unclear.
>> Can you tell me what your idea of a "scope" is? I'm thinking a >> continuation, and if that is what you are thinking, I'm thinking the >> answer to your question is yes.
> Yes. I want to know how Perl 6 exposes continuations, and how to get one > for, say, the current lexical scope, and if it has a method on it that > lets me evaluate code in that context (or some other way to do that).
As I understand what Larry's said before. Out of the box, it doesn't. Apparently we're going to have to descend to Parrot to write evalcc/letcc/your-preferred-continuation-idiom equivalent.
On Tue, Apr 12, 2005 at 11:36:02AM +0100, Piers Cawley wrote: : wolverian <w...@sci.fi> writes:
: : > On Fri, Apr 08, 2005 at 12:18:45PM -0400, MrJoltCola wrote: : >> I cannot say how much Perl6 will expose to the high level language. : > : > That is what I'm wondering about. I'm sorry I was so unclear. : > : >> Can you tell me what your idea of a "scope" is? I'm thinking a : >> continuation, and if that is what you are thinking, I'm thinking the : >> answer to your question is yes. : > : > Yes. I want to know how Perl 6 exposes continuations, and how to get one : > for, say, the current lexical scope, and if it has a method on it that : > lets me evaluate code in that context (or some other way to do that). : : As I understand what Larry's said before. Out of the box, it : doesn't. Apparently we're going to have to descend to Parrot to write : evalcc/letcc/your-preferred-continuation-idiom equivalent.
We'll make continuations available in Perl for people who ask for them specially, but we're not going to leave them sitting out in the open where some poor benighted pilgrim might trip over them unawares.
Larry Wall <la...@wall.org> writes: > On Tue, Apr 12, 2005 at 11:36:02AM +0100, Piers Cawley wrote: > : wolverian <w...@sci.fi> writes: > : > : > On Fri, Apr 08, 2005 at 12:18:45PM -0400, MrJoltCola wrote: > : >> I cannot say how much Perl6 will expose to the high level language. > : > > : > That is what I'm wondering about. I'm sorry I was so unclear. > : > > : >> Can you tell me what your idea of a "scope" is? I'm thinking a > : >> continuation, and if that is what you are thinking, I'm thinking the > : >> answer to your question is yes. > : > > : > Yes. I want to know how Perl 6 exposes continuations, and how to get one > : > for, say, the current lexical scope, and if it has a method on it that > : > lets me evaluate code in that context (or some other way to do that). > : > : As I understand what Larry's said before. Out of the box, it > : doesn't. Apparently we're going to have to descend to Parrot to write > : evalcc/letcc/your-preferred-continuation-idiom equivalent.
> We'll make continuations available in Perl for people who ask for > them specially, but we're not going to leave them sitting out in the > open where some poor benighted pilgrim might trip over them unawares.
Oh goody! Presumably we're initially talking of a simple 'call_with_current_continuation'?
On Tue, Apr 12, 2005 at 04:17:56AM -0700, Larry Wall wrote: > We'll make continuations available in Perl for people who ask for > them specially, but we're not going to leave them sitting out in the > open where some poor benighted pilgrim might trip over them unawares.
Sorry for replying so late, but I missed your reply somehow. I just want to ask a little clarification on this; exactly what kind of hiding are you considering for continuations? That is, do you just mean that there will not be a 'call/cc' primitive by default in the global namespace? I'm fine with that, as that's just one method of capturing the calling continuation.
On Thu, Apr 21, 2005 at 04:30:07PM +0300, wolverian wrote:
: On Tue, Apr 12, 2005 at 04:17:56AM -0700, Larry Wall wrote: : > We'll make continuations available in Perl for people who ask for : > them specially, but we're not going to leave them sitting out in the : > open where some poor benighted pilgrim might trip over them unawares. : : Sorry for replying so late, but I missed your reply somehow. I just want : to ask a little clarification on this; exactly what kind of hiding are : you considering for continuations? That is, do you just mean that there : will not be a 'call/cc' primitive by default in the global namespace? : I'm fine with that, as that's just one method of capturing the calling : continuation.
I suspect it's just something like
use Continuations;
at the top to enable the low-level interface. There would be no restriction on using continuation semantics provided by other modules, because then the "use" of that other module implies whatever form of continuation it provides.
My concern is primarily the reader of the code, who needs some kind of warning that one can get sliced while juggling sharp knives. If we were willing to be a little more Ada-like, we'd make it a shouted warning:
use CONTINUATIONS;
Hmm, maybe that's not such a bad policy. I wonder what other "dangerous" modules we might have. Ada had UNCHECKED_TYPE_CONVERSION, for instance.
I am making a presentation about Perl6 this week end. My point will be: the next generation of applicative languages will be scripting languages because they have come of age.
Alternatives don't cut it anymore. Indeed C and C++ are memory allocation nightmare; Java and C# don't have read-eval loop, a necessary condition for rapid learning and development. Functional languages like haskell or ocaml are very powerful but needs massive wetware reconfiguration to get used to the syntax and semantic.
So I will make do a presentation of Perl6 and Parrot features to make my point about upcoming scripting languages.
I have a few questions inspired by my recently acquired knowledge about functional languages. Perl6 being the ultimate syncretist language, I wonder if some functional features will make it into Perl6. I know we already got currying.
A very nice feature of Haskell and *ml is the possibility to define complex datastructures types and the control flow that manipulate these structures: constructors and pattern matching. With these languages, in a very deep sense, control flow is pattern matching. Can we expect Perl6 to propose something similar?