Bluebird1973 Posted October 12, 2017 Share Posted October 12, 2017 Hi together, I'm looking for a "jump mark" or a "goto-function" but there is no one. I need a simplification of my code because I don't want to write the programs e.g.(program 1), (program 2),... twice under each (progn because there are the same. ... (if (/= 0 checkPINstate) (progn (requestPIN) (if (= checkPIN inputPIN) (program 1) (program 2) ... ... ) ) (progn (program 1) (program 2) ... ... ) ) ... kind regards Bluebird1973 Quote Link to comment Share on other sites More sharing options...
David Bethel Posted October 12, 2017 Share Posted October 12, 2017 There are a lot of different ways to approach this [b][color=BLACK]([/color][/b]while [b][color=FUCHSIA]([/color][/b]/= 0 checkPINstate[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]requestPIN[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]checkPINstate[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]program1[b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]program2[b][color=BLACK])[/color][/b] This will force a correct PIN, leaving only esc as a alternate exit ( probably not the most elegant nor best solution ) -David Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 12, 2017 Share Posted October 12, 2017 (edited) My 2c... (cond ((and (/= 0 checkpinstate) (requestpin) (= checkpin inputpin)) (program 1) (program 2)) ((program 1) (program 2)) ) Edited October 13, 2017 by ronjonp Quote Link to comment Share on other sites More sharing options...
Bluebird1973 Posted October 17, 2017 Author Share Posted October 17, 2017 Hi David, Hi ronjonp, Thanks for your try, but it didn't work. kind regards Bluebird1973 Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 17, 2017 Share Posted October 17, 2017 Hi David,Hi ronjonp, Thanks for your try, but it didn't work. kind regards Bluebird1973 With your example above, (program1) and (program2) will always run so not sure where you're going with this? Perhaps: (cond ;; Pin already validated .. run programs ((= 0 checkpinstate) (program 1) (program 2)) ;; Pin not validated, get the pin, if pin checks out then run programs ((and (requestpin) (= checkpin inputpin)) (program 1) (program 2)) ) Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 17, 2017 Share Posted October 17, 2017 What if (requestpin) asigns a global variable 'checkpinstate' and then the funciton itself returns nil. Another 2c.. (if (member checkpinstate '(nil 0)) (requestpin)) (cond ( (and checkpinstate (/= 0 checkpinstate)) (program1) (program2) )) Thanks for your try, but it didn't work. When requesting for hints, the copy-paste approach doesn't work always with the examples. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 17, 2017 Share Posted October 17, 2017 Perhaps: (cond ;; Pin already validated .. run programs ((= "0" (getenv "checkpinstate")) (program 1) (program 2)) ;; Pin not validated, get the pin, if pin checks out set the 'checkpinstate' variable then run programs ((and (requestpin) (= checkpin inputpin)) (setenv "checkpinstate" "0") (program 1) (program 2)) ) Kind of hard to come to a solution when 1/2 of this requires reading minds LOL. Quote Link to comment Share on other sites More sharing options...
Bluebird1973 Posted October 18, 2017 Author Share Posted October 18, 2017 I found now a solution. [color=RED]([/color][color=BLUE]progn[/color] [color=RED]([/color][color=BLUE]cond[/color] [color=RED]([/color] [color=RED]([/color][color=BLUE]/=[/color] [color=#009900]0[/color] checkPINstate[color=RED])[/color] [color=RED]([/color][color=BLUE]progn[/color] [color=RED]([/color]requestPIN[color=RED])[/color] [color=RED]([/color][color=BLUE]cond[/color] [color=RED]([/color] [color=RED]([/color][color=BLUE]/=[/color] checkPIN inputPIN[color=RED])[/color] [color=RED]([/color][color=BLUE]progn[/color] [color=RED]([/color][color=BLUE]princ[/color] [color=#a52a2a]"\nError: bad argument pw"[/color][color=RED])[/color] [color=RED]([/color][color=BLUE]exit[/color][color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]=[/color] [color=BLUE]Prog[/color] checkProg[color=RED])[/color] [color=RED]([/color][color=BLUE]progn[/color] [color=RED]([/color][color=BLUE]cond[/color] [color=RED](([/color]program [color=#009900]1[/color][color=RED]))[/color] [color=RED](([/color]program [color=#009900]2[/color][color=RED]))[/color] [color=RED](([/color]program [color=#009900]3[/color][color=RED]))[/color] [color=DARKRED].[/color][color=DARKRED].[/color][color=DARKRED].[/color] kind regards Bluebird1973 Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 18, 2017 Share Posted October 18, 2017 I found now a solution. [color=RED]([/color][color=BLUE]progn[/color] [color=RED]([/color][color=BLUE]cond[/color] [color=RED]([/color] [color=RED]([/color][color=BLUE]/=[/color] [color=#009900]0[/color] checkPINstate[color=RED])[/color] [color=RED]([/color][color=BLUE]progn[/color] [color=RED]([/color]requestPIN[color=RED])[/color] [color=RED]([/color][color=BLUE]cond[/color] [color=RED]([/color] [color=RED]([/color][color=BLUE]/=[/color] checkPIN inputPIN[color=RED])[/color] [color=RED]([/color][color=BLUE]progn[/color] [color=RED]([/color][color=BLUE]princ[/color] [color=#a52a2a]"\nError: bad argument pw"[/color][color=RED])[/color] [color=RED]([/color][color=BLUE]exit[/color][color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]=[/color] [color=BLUE]Prog[/color] checkProg[color=RED])[/color] [color=RED]([/color][color=BLUE]progn[/color] [color=RED]([/color][color=BLUE]cond[/color] [color=RED](([/color]program [color=#009900]1[/color][color=RED]))[/color] [color=RED](([/color]program [color=#009900]2[/color][color=RED]))[/color] [color=RED](([/color]program [color=#009900]3[/color][color=RED]))[/color] [color=DARKRED].[/color][color=DARKRED].[/color][color=DARKRED].[/color] kind regards Bluebird1973 FWIW .. this will accomplish the same thing without a messy exit. ;; Assumes that your (requestpin) actually returns something (if (or (= 0 checkpinstate) (and (requestpin) (/= checkpin inputpin) (= prog checkprog))) (progn (program 1) (program 2) (program 3)) (princ "\nError: bad argument pw") ) Quote Link to comment Share on other sites More sharing options...
Bluebird1973 Posted October 19, 2017 Author Share Posted October 19, 2017 Hi ronjonp, Yes, you are right. It is really the better way. Thank you for the lesson!!! kind regards Bluebird1973 Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 20, 2017 Share Posted October 20, 2017 Glad to help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.