[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to exit out of a function ? what is try-catch-throw in terms of
From: |
gnuist006 |
Subject: |
Re: How to exit out of a function ? what is try-catch-throw in terms of Program Counter |
Date: |
Tue, 23 Oct 2007 18:06:58 -0000 |
User-agent: |
G2/1.0 |
On Oct 20, 3:55 pm, "Alf P. Steinbach" <al...@start.no> wrote:
> * gnuist...@gmail.com:
>
>
>
> > I have some code like this:
>
> > (if (test)
> > (exit)
> > (do something))
>
> > or
>
> > (if (test)
> > ( do something)
> > (exit))
>
> > Various levels of nestings.
>
> > I have several questions, basic to sophisticated.
>
> > (1) What is the lisp equivalent idiom for (exit) as in bash or
> > in C.
>
> C++ does not have a built-in 'exit' command. There is a library
> function 'exit' which exits the process. One must assume that's not
> what you mean, and that you're not asking C and C++ programmers to teach
> you Lisp.
>
> Therefore, assuming you want to exit the function or the block.
>
> > (2) What is the best practice to handle this kind of problems?
>
> It's not a general class of problem.
>
> Appropriate solutions depend on the problem at hand.
>
> E.g., in C++,
>
> // (if (test) (exit) (do something))
>
> void foo()
> {
> if( !test )
> {
> doSomething();
> }
> }
>
> void bar()
> {
> if( test ) { return; }
> doSomething();
> }
>
> > (3) What is the intermediate practice to handle this kind of
> > problems.
>
> ?
>
> > NOTE: I am really afraid of try-catch-throw. I have never been
> > able to understand it since it does not exist in C and I cant
> > really visualize the construct in terms of C. That is what my
> > brain can process. If you understand it so well, you can show
> > me how one would really implement that kind of construct in
> > C and then by extension I can see that kind of program flow
> > in LISP. Whether its imperative programming or functional,
> > beneath there is program counter and assembly. C is close
> > to machine so much that it is almost assembly. So understanding try-c-
> > t in C is equivalent to understanding at
> > the level of machine language.
>
> The closest equivalent in C would be a 'longjmp'. However, a C++
> exception is more limited, in that it will only jump up the call chain,
> and it's more powerful, in that it will destroy local objects as it does
> so. Also, if you use 'longjmp' in C++ you're practically doomed (unless
> you use it to jump between co-routines with their own stacks), because
> 'longjmp' doesn't destroy local objects.
Sure you have good ideas.
I still would like an equivalent implementation explained. Ofcourse,
smart
companies and smart programmers were doing all this before C++ came
and even in LISP they have atleast two of try catch throw.
- How to exit out of a function ? what is try-catch-throw in terms of Program Counter, gnuist006, 2007/10/20
- Re: How to exit out of a function ? what is try-catch-throw in terms of Program Counter, gnuist006, 2007/10/20
- Re: How to exit out of a function ? what is try-catch-throw in terms of Program Counter, Alf P. Steinbach, 2007/10/21
- Re: How to exit out of a function ? what is try-catch-throw in terms of Program Counter,
gnuist006 <=
- Re: How to exit out of a function ? what is try-catch-throw in terms of Program Counter, Keith Thompson, 2007/10/21
- Re: How to exit out of a function ? what is try-catch-throw in terms of Program Counter, Kenny McCormack, 2007/10/21
- Re: How to exit out of a function ? what is try-catch-throw in terms of Program Counter, Malcolm McLean, 2007/10/21
- Re: How to exit out of a function ? what is try-catch-throw in terms of Program Counter, Kenny McCormack, 2007/10/21
- Re: How to exit out of a function ? what is try-catch-throw in terms of Program Counter, santosh, 2007/10/21
- Re: How to exit out of a function ? what is try-catch-throw in terms of Program Counter, Malcolm McLean, 2007/10/21
- Re: How to exit out of a function ? what is try-catch-throw in terms of Program Counter, Kenny McCormack, 2007/10/21
- Re: How to exit out of a function ? what is try-catch-throw in terms of Program Counter, santosh, 2007/10/21
- Re: How to exit out of a function ? what is try-catch-throw in terms of Program Counter, Richard Heathfield, 2007/10/21