Re: exit case body/prog/function
Hi John Yes...you're right...I was using an (if (or (stop test 1) (stop test 2)) (do nothing) (do all the stuff) but your "unless" is much more direct. Hi Alex Yes I like that a lot! Thank you both for your further help. Best Regards Dean On 19 January 2017 at 17:02, Alexander Burgerwrote: > On Thu, Jan 19, 2017 at 05:50:00PM +0100, Alexander Burger wrote: > > Note that (setq Do_it NIL) is (off Do_it), and you could also use an > 'or' for > > the two equal consequences. Then the above becomes: > > > >(setq > > Pg_bks 7 > > Lns_from_top 6 > > Do_it T ) > >(case 2 > > (1 (prinl "in 1")) > > (2 > > (cond > > ((or (> 2 Pg_blks) (> 6 Lns_from_top)) > >(off Do_it) ) > > (Do_it > >(prinl "yes doing a") > >(prinl "yes doing b") > >(prinl "yes doing c") ) ) ) ) > > > Normally, of course, you will use 'let' instead of 'setq': > >(let (Pg_bks 7 Lns_from_top 6 Do_it T) > (case 2 > (1 (prinl "in 1")) > (2 > (cond >((or (> 2 Pg_blks) (> 6 Lns_from_top)) > (off Do_it) ) >(Do_it > (prinl "yes doing a") > (prinl "yes doing b") > (prinl "yes doing c") ) ) ) ) ) > > ♪♫ Alex > -- > UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe >
Re: exit case body/prog/function
On Thu, Jan 19, 2017 at 05:50:00PM +0100, Alexander Burger wrote: > Note that (setq Do_it NIL) is (off Do_it), and you could also use an 'or' for > the two equal consequences. Then the above becomes: > >(setq > Pg_bks 7 > Lns_from_top 6 > Do_it T ) >(case 2 > (1 (prinl "in 1")) > (2 > (cond > ((or (> 2 Pg_blks) (> 6 Lns_from_top)) >(off Do_it) ) > (Do_it >(prinl "yes doing a") >(prinl "yes doing b") >(prinl "yes doing c") ) ) ) ) Normally, of course, you will use 'let' instead of 'setq': (let (Pg_bks 7 Lns_from_top 6 Do_it T) (case 2 (1 (prinl "in 1")) (2 (cond ((or (> 2 Pg_blks) (> 6 Lns_from_top)) (off Do_it) ) (Do_it (prinl "yes doing a") (prinl "yes doing b") (prinl "yes doing c") ) ) ) ) ) ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: exit case body/prog/function
Hi Dean, > (setq Pg_bks 7) > (setq Lns_from_top 6) > (setq Do_it T) > (case 2 >(1 (prinl "in 1")) >(2 > (if (> 2 Pg_blks) (setq Do_it NIL)) > (if (> 6 Lns_from_top) (setq Do_it NIL)) > (if (Do_it) (prinl "yes doing a")) > (if (Do_it) (prinl "yes doing b")) > (if (Do_it) (prinl "yes doing c"))) > > > I'm really after this. > I like it because of the very flat structure, I can write the "stop" rules > in a very natural way and One objection stops any further execution. I have > had some very experienced programmers comment that this style is > uglyMaybe but I find it very easy to understand/maintain. > > #fn some_fn or in lisp (prog..) > # if cond1 then exit fn > # if cond2 then exit fn > # do a > # do b > # do c > #end fn This is a typical 'cond' case (cond ((> 2 Pg_blks) (setq Do_it NIL)) ((> 6 Lns_from_top) (setq Do_it NIL)) (Do_it (prinl "yes doing a") (prinl "yes doing b") (prinl "yes doing c") ) ) Note that (setq Do_it NIL) is (off Do_it), and you could also use an 'or' for the two equal consequences. Then the above becomes: (setq Pg_bks 7 Lns_from_top 6 Do_it T ) (case 2 (1 (prinl "in 1")) (2 (cond ((or (> 2 Pg_blks) (> 6 Lns_from_top)) (off Do_it) ) (Do_it (prinl "yes doing a") (prinl "yes doing b") (prinl "yes doing c") ) ) ) ) ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: exit case body/prog/function
Hi Alex Thank you for confirming no return and the alternative. Best Regards Dean On 19 January 2017 at 14:44, Alexander Burgerwrote: > Hi Dean, > > > I'd like to do this but am not sure if it's possible > > > > ( case > >#= start of match clause > >( > >(prog > >(if () (EXIT THIS MATCH CLAUSE/PROG)) > >(otherwise you'll execute this statement) > >) > > ) > > #= end of match clause > > . > > . > > . > > I also wonder if there's a similar... (if (T) (EXIT FUNCTION)) > > If I understand you right, you are looking for an exit out of a nested > expression, like a 'return' statment in C or Java. > > Such a return does not exist, there is catch/throw for that > >(catch 'something > (for (..) > (if (..) > (throw 'something) > (elseStuff) > .. > > Catch/throw is more general then 'return', but the latter can be emulated > with > it. > > ♪♫ Alex > -- > UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe >
Re: exit case body/prog/function
Hi Dean, > I'd like to do this but am not sure if it's possible > > ( case >#= start of match clause >( >(prog >(if () (EXIT THIS MATCH CLAUSE/PROG)) >(otherwise you'll execute this statement) >) > ) > #= end of match clause > . > . > . > I also wonder if there's a similar... (if (T) (EXIT FUNCTION)) If I understand you right, you are looking for an exit out of a nested expression, like a 'return' statment in C or Java. Such a return does not exist, there is catch/throw for that (catch 'something (for (..) (if (..) (throw 'something) (elseStuff) .. Catch/throw is more general then 'return', but the latter can be emulated with it. ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: exit case body/prog/function
Ok here we are... This is the nearest I can get in PL with my limited familarity i.e. a very flat structure (setq Pg_bks 7) (setq Lns_from_top 6) (setq Do_it T) (case 2 (1 (prinl "in 1")) (2 (if (> 2 Pg_blks) (setq Do_it NIL)) (if (> 6 Lns_from_top) (setq Do_it NIL)) (if (Do_it) (prinl "yes doing a")) (if (Do_it) (prinl "yes doing b")) (if (Do_it) (prinl "yes doing c"))) I'm really after this. I like it because of the very flat structure, I can write the "stop" rules in a very natural way and One objection stops any further execution. I have had some very experienced programmers comment that this style is uglyMaybe but I find it very easy to understand/maintain. #fn some_fn or in lisp (prog..) # if cond1 then exit fn # if cond2 then exit fn # do a # do b # do c #end fn On 19 January 2017 at 14:01, deanwrote: > Thank you very much Joe.,,,I see what you mean and don't think I've been > clear enough. > I'll try and put a better example together. > It might be because of Lisps "everything returns a value" my constructs > aren't compatible. > We'll seeback soon. > > On 19 January 2017 at 13:13, Joe Bogner wrote: > >> dean, I would use unless. >> >> See this control structure below as an alternative to the prog/if >> >> : (setq Test1 1) >> -> 1 >> : (case Test1 (1 (unless Test2 (prinl "true" >> true >> -> "true" >> >> : (setq Test2 "Nope") >> -> "Nope" >> : (case Test1 (1 (unless Test2 (prinl "true" >> -> NIL >> >> >> >> On Thu, Jan 19, 2017 at 7:55 AM, dean wrote: >> >>> I'd like to do this but am not sure if it's possible >>> >>> ( case >>>#= start of match clause >>>( >>>(prog >>>(if () (EXIT THIS MATCH CLAUSE/PROG)) >>>(otherwise you'll execute this statement) >>>) >>> ) >>> #= end of match clause >>> . >>> . >>> . >>> I also wonder if there's a similar... (if (T) (EXIT FUNCTION)) >>> >> >> >
Re: exit case body/prog/function
Thank you very much Joe.,,,I see what you mean and don't think I've been clear enough. I'll try and put a better example together. It might be because of Lisps "everything returns a value" my constructs aren't compatible. We'll seeback soon. On 19 January 2017 at 13:13, Joe Bognerwrote: > dean, I would use unless. > > See this control structure below as an alternative to the prog/if > > : (setq Test1 1) > -> 1 > : (case Test1 (1 (unless Test2 (prinl "true" > true > -> "true" > > : (setq Test2 "Nope") > -> "Nope" > : (case Test1 (1 (unless Test2 (prinl "true" > -> NIL > > > > On Thu, Jan 19, 2017 at 7:55 AM, dean wrote: > >> I'd like to do this but am not sure if it's possible >> >> ( case >>#= start of match clause >>( >>(prog >>(if () (EXIT THIS MATCH CLAUSE/PROG)) >>(otherwise you'll execute this statement) >>) >> ) >> #= end of match clause >> . >> . >> . >> I also wonder if there's a similar... (if (T) (EXIT FUNCTION)) >> > >
Re: exit case body/prog/function
dean, I would use unless. See this control structure below as an alternative to the prog/if : (setq Test1 1) -> 1 : (case Test1 (1 (unless Test2 (prinl "true" true -> "true" : (setq Test2 "Nope") -> "Nope" : (case Test1 (1 (unless Test2 (prinl "true" -> NIL On Thu, Jan 19, 2017 at 7:55 AM, deanwrote: > I'd like to do this but am not sure if it's possible > > ( case >#= start of match clause >( >(prog >(if () (EXIT THIS MATCH CLAUSE/PROG)) >(otherwise you'll execute this statement) >) > ) > #= end of match clause > . > . > . > I also wonder if there's a similar... (if (T) (EXIT FUNCTION)) >
exit case body/prog/function
I'd like to do this but am not sure if it's possible ( case #= start of match clause ( (prog (if () (EXIT THIS MATCH CLAUSE/PROG)) (otherwise you'll execute this statement) ) ) #= end of match clause . . . I also wonder if there's a similar... (if (T) (EXIT FUNCTION))