Re: Is it possible to implement break or return in Lisp?

2009-11-04 Thread Christopher Wilson
On Tue, Nov 3, 2009 at 10:58 PM, rob r.p.l...@gmail.com wrote: I'm pretty sure there was an example of this using continuations in Dybvig's book on Scheme.  I just flipped through it and didn't readily find it, but I think that is where I saw it. You can do something like this (PLT Scheme):

Re: Is it possible to implement break or return in Lisp?

2009-11-03 Thread James Reeves
On Nov 3, 12:03 am, CuppoJava patrickli_2...@hotmail.com wrote: But I'm writing a DSL for others to use. People that don't have experience with functional programming, and for them it's easier to have a break/return. That doesn't seem like a good idea to me. Clojure is a functional

Re: Is it possible to implement break or return in Lisp?

2009-11-03 Thread rob
I'm pretty sure there was an example of this using continuations in Dybvig's book on Scheme. I just flipped through it and didn't readily find it, but I think that is where I saw it. On Nov 1, 8:04 pm, CuppoJava patrickli_2...@hotmail.com wrote: Hi, For the purposes of a DSL that I'm writing,

Re: Is it possible to implement break or return in Lisp?

2009-11-02 Thread Sean Devlin
Could you do this w/ a lazy seq cond? The seq terminates early if cond x is met. On Nov 1, 8:04 pm, CuppoJava patrickli_2...@hotmail.com wrote: Hi, For the purposes of a DSL that I'm writing, it would be very convenient to have a break/return statement that early exits from a subroutine.

Re: Is it possible to implement break or return in Lisp?

2009-11-02 Thread Brian Hurt
On Sun, Nov 1, 2009 at 8:04 PM, CuppoJava patrickli_2...@hotmail.comwrote: Hi, For the purposes of a DSL that I'm writing, it would be very convenient to have a break/return statement that early exits from a subroutine. I'm not sure why you need this. The body of a function in clojure

Re: Is it possible to implement break or return in Lisp?

2009-11-02 Thread CuppoJava
Thanks Brian. For my own purposes, yes I have no need for a break or return statement. But I'm writing a DSL for others to use. People that don't have experience with functional programming, and for them it's easier to have a break/return. And for me, it's easier to implement break/return using

Re: Is it possible to implement break or return in Lisp?

2009-11-02 Thread Jarkko Oranen
On Nov 3, 2:03 am, CuppoJava patrickli_2...@hotmail.com wrote: Thanks Brian. For my own purposes, yes I have no need for a break or return statement. But I'm writing a DSL for others to use. People that don't have experience with functional programming, and for them it's easier to have a

Is it possible to implement break or return in Lisp?

2009-11-01 Thread CuppoJava
Hi, For the purposes of a DSL that I'm writing, it would be very convenient to have a break/return statement that early exits from a subroutine. Is it possible to implement this in Clojure? or any Lisp-like language? I've given it some thought and it seems it has to be a compiler level feature.

Re: Is it possible to implement break or return in Lisp?

2009-11-01 Thread Richard Newman
I've given it some thought and it seems it has to be a compiler level feature. Am I right? You could implement Common Lisp-style return-from with a custom exception class: public class BlockException extends Exception { String name; Object val; public BlockException(String name,

Re: Is it possible to implement break or return in Lisp?

2009-11-01 Thread John Harrop
On Sun, Nov 1, 2009 at 9:14 PM, Richard Newman holyg...@gmail.com wrote: I've given it some thought and it seems it has to be a compiler level feature. Am I right? You could implement Common Lisp-style return-from with a custom exception class: public class BlockException extends

Re: Is it possible to implement break or return in Lisp?

2009-11-01 Thread CuppoJava
Thanks for the pointer! I haven't considered using Exceptions to influence the control-flow. This will work perfectly. -Patrick PS: I've always found it a little strange for exception-handling to be treated as a special case in language design. It seems like it ought able to be expressed in

Re: Is it possible to implement break or return in Lisp?

2009-11-01 Thread Warren
Maybe could be done using continuation passing style? (http:// en.wikipedia.org/wiki/Continuation-passing_style) On Nov 1, 7:04 pm, CuppoJava patrickli_2...@hotmail.com wrote: Hi, For the purposes of a DSL that I'm writing, it would be very convenient to have a break/return statement that

Re: Is it possible to implement break or return in Lisp?

2009-11-01 Thread Chris Dean
CuppoJava patrickli_2...@hotmail.com writes: I've always found it a little strange for exception-handling to be treated as a special case in language design. It seems like it ought able to be expressed in terms of some simpler elements (eg. a function Note sure exactly what you want, but you

Re: Is it possible to implement break or return in Lisp?

2009-11-01 Thread Richard Newman
For this to work, you'd first have to implement Common Lisp style unquoting. :) Heh, good catch :) I've been switching between the two too much recently! At least I didn't miss out the semicolons in the Java code ;) --~--~-~--~~~---~--~~ You received this

Re: Is it possible to implement break or return in Lisp?

2009-11-01 Thread John Harrop
On Mon, Nov 2, 2009 at 12:19 AM, Richard Newman holyg...@gmail.com wrote: For this to work, you'd first have to implement Common Lisp style unquoting. :) Heh, good catch :) I've been switching between the two too much recently! At least I didn't miss out the semicolons in the Java code