pBe Posted April 23, 2014 Share Posted April 23, 2014 I'm headed out the door... so @Samifox Your code modified. Look ONLY when you are done with your mod. _SamifoxEvery.LSP No peeking now Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 23, 2014 Share Posted April 23, 2014 Watch out...(vl-every '= '(1 2 3 )'(1 2 3 4)) T (EVERY-P '(1 2 3 )'(1 2 3 4)) nil I knew that , if needed so , we can just replace the function max with min Codes modified . Quote Link to comment Share on other sites More sharing options...
BlackBox Posted April 23, 2014 Share Posted April 23, 2014 That's incredibly kind of you to say BlackBox You're very welcome. ... I'm delighted to be one of those in a position to have inspired you to progress with your programming studies. And now that you have successfully progressed into the more powerful world of .NET, you will be leaving LISPers such as myself in the dust...! This immediately comes to mind, both in terms of having observed you over the past few years, and as something that I often strive to achieve myself: "There are two ways of spreading light: to be the candle or the mirror that reflects it." - Edith Wharton And now that you have successfully progressed into the more powerful world of .NET, you will be leaving LISPers such as myself in the dust...! That is kind of you to jest, Lee; though, you'd laugh.... I'm such a LISPer at heart, that part of my private .NET code library is actually dedicated to new LispFunction Methods, and is part of a 'VisualLispXpanded' plug-in (or 'VLX' to be punny). Quote Link to comment Share on other sites More sharing options...
samifox Posted April 23, 2014 Author Share Posted April 23, 2014 I'm headed out the door... so @Samifox Your code modified. Look ONLY when you are done with your mod. [ATTACH]48280[/ATTACH] No peeking now i like pain Patrick im using autilisp after all:rofl: Quote Link to comment Share on other sites More sharing options...
samifox Posted April 23, 2014 Author Share Posted April 23, 2014 That is almost the same as LM's every3 but missing the vital part , so still no go Samifox , this.. (setq st1 '(1 2 3 4) st2 '(1 1 3) ) Will still evaluate to T. Do not write an entirely different approach. What i need you to do is the modify the code on your first post. I'm pushing you to do that so you would be able to debug your code and have that "A-HA" moment instead of dropping the idea and moving on to another. not that there's anything wrong with that, i'm just saying, finish what you started then move on to another solution. [ATTACH=CONFIG]48278[/ATTACH] (setq lst1 '(1 2 4) lst2 '(1 2 3) i -1 ) (while (< (setq i (1+ i)) (min (length lst1) (length lst2))) (if (= (nth i lst1) (nth i lst2)) T ) ) Quote Link to comment Share on other sites More sharing options...
samifox Posted May 1, 2014 Author Share Posted May 1, 2014 Here are three alternative ways to construct a vl-every function: ([color=BLUE]defun[/color] every1 ( prd ls1 ls2 ) ([color=BLUE]or[/color] ([color=BLUE]not[/color] ls1) ([color=BLUE]not[/color] ls2) ([color=BLUE]and[/color] (prd ([color=BLUE]car[/color] ls1) ([color=BLUE]car[/color] ls2)) (every1 prd ([color=BLUE]cdr[/color] ls1) ([color=BLUE]cdr[/color] ls2))) ) ) hi LEE would it be ok if i ask you to draw a flowchart of the code above? Thanks S Quote Link to comment Share on other sites More sharing options...
aloy Posted May 1, 2014 Share Posted May 1, 2014 If lisp is so powerful why is that Autodesk have to invent a way to enter their own AutoCAD from back door with .NET and runtime extensions?. I wonder. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 1, 2014 Share Posted May 1, 2014 Here are three alternative ways to construct a vl-every function: ([color=BLUE]defun[/color] every1 ( prd ls1 ls2 ) ([color=BLUE]or[/color] ([color=BLUE]not[/color] ls1) ([color=BLUE]not[/color] ls2) ([color=BLUE]and[/color] (prd ([color=BLUE]car[/color] ls1) ([color=BLUE]car[/color] ls2)) (every1 prd ([color=BLUE]cdr[/color] ls1) ([color=BLUE]cdr[/color] ls2))) ) ) Hi Lee would it be ok if i ask you to draw a flowchart of the code above? Here is my explanation: ======================================= Function: ======================================= (defun every1 ( prd ls1 ls2 ) (or (not ls1) (not ls2) (and (prd (car ls1) (car ls2)) (every1 prd (cdr ls1) (cdr ls2))) ) ) ======================================= Background: ======================================= OR: Evaluates supplied expressions until either: - an expression returns non-nil -> OR returns T - no expressions remain -> OR returns nil AND: Evaluates supplied expressions until either: - an expression returns nil -> AND returns nil - no expressions remain -> AND returns T NOT: Returns the logical opposite of the supplied expression: - expression evaluates to nil -> NOT returns T - expression evaluates to non-nil value -> NOT returns nil ======================================= Example 1: ======================================= (setq a '(0 1 2 3) b '(0 1 3 3) ) (every1 = a b) OR NOT '(0 1 2 3) -> nil NOT '(0 1 3 3) -> nil AND 0 = 0 -> T OR NOT '(1 2 3) -> nil NOT '(1 3 3) -> nil AND 1 = 1 -> T OR NOT '(2 3) -> nil NOT '(3 3) -> nil AND 2 = 3 -> nil nil nil nil nil nil nil ======================================= Example 2: ======================================= (setq a '(0 1 3 3) b '(0 1 3 3) ) (every1 = a b) OR NOT '(0 1 3 3) -> nil NOT '(0 1 3 3) -> nil AND 0 = 0 -> T OR NOT '(1 3 3) -> nil NOT '(1 3 3) -> nil AND 1 = 1 -> T OR NOT '(3 3) -> nil NOT '(3 3) -> nil AND 3 = 3 -> T OR NOT '(3) -> nil NOT '(3) -> nil AND 3 = 3 -> T OR NOT nil -> T T T T T T T T T T Quote Link to comment Share on other sites More sharing options...
samifox Posted May 2, 2014 Author Share Posted May 2, 2014 Here is my explanation: ======================================= Function: ======================================= (defun every1 ( prd ls1 ls2 ) (or (not ls1) (not ls2) (and (prd (car ls1) (car ls2)) (every1 prd (cdr ls1) (cdr ls2))) ) ) ======================================= Background: ======================================= OR: Evaluates supplied expressions until either: - an expression returns non-nil -> OR returns T - no expressions remain -> OR returns nil AND: Evaluates supplied expressions until either: - an expression returns nil -> AND returns nil - no expressions remain -> AND returns T NOT: Returns the logical opposite of the supplied expression: - expression evaluates to nil -> NOT returns T - expression evaluates to non-nil value -> NOT returns nil ======================================= Example 1: ======================================= (setq a '(0 1 2 3) b '(0 1 3 3) ) (every1 = a b) OR NOT '(0 1 2 3) -> nil NOT '(0 1 3 3) -> nil AND 0 = 0 -> T OR NOT '(1 2 3) -> nil NOT '(1 3 3) -> nil AND 1 = 1 -> T OR NOT '(2 3) -> nil NOT '(3 3) -> nil AND 2 = 3 -> nil nil nil nil nil nil nil ======================================= Example 2: ======================================= (setq a '(0 1 3 3) b '(0 1 3 3) ) (every1 = a b) OR NOT '(0 1 3 3) -> nil NOT '(0 1 3 3) -> nil AND 0 = 0 -> T OR NOT '(1 3 3) -> nil NOT '(1 3 3) -> nil AND 1 = 1 -> T OR NOT '(3 3) -> nil NOT '(3 3) -> nil AND 3 = 3 -> T OR NOT '(3) -> nil NOT '(3) -> nil AND 3 = 3 -> T OR NOT nil -> T T T T T T T T T T hi LEE thanks for that powerful explination:) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 3, 2014 Share Posted May 3, 2014 thanks for that powerful explination:) You're welcome Shay - I'm glad it helps. Quote Link to comment Share on other sites More sharing options...
aloy Posted May 5, 2014 Share Posted May 5, 2014 Looks like I have posted a daft one at #27. Anyway that is the way it looks to me, using one API to call another. Quote Link to comment Share on other sites More sharing options...
samifox Posted February 8, 2015 Author Share Posted February 8, 2015 ([color=BLUE]while[/color] ([color=BLUE]and[/color] ([color=BLUE]setq[/color] x ([color=BLUE]car[/color] ls1)) ([color=BLUE]setq[/color] y ([color=BLUE]car[/color] ls2)) (prd x y)) ([color=BLUE]setq[/color] ls1 ([color=BLUE]cdr[/color] ls1) ls2 ([color=BLUE]cdr[/color] ls2) ) ) ([color=BLUE]or[/color] ([color=BLUE]not[/color] ls1) ([color=BLUE]not[/color] ls2)) ) hi LEE honestly its took me long time to understand why you did what you did, after lots of struggles i came out with this logic while list1 and list2 and predicate are true subtract list and loop if list1 or list2 or predicate is false stop looping if one of the lists is empty (meaning all predicates were T) return T if one of the lists is not empty (meaning predicate was false) return nil) how do you plan your algorithm ? flowchart? can you post it? (by the way....i sent you P.M long time ago....you didnt reply yet ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 9, 2015 Share Posted February 9, 2015 Well done for understanding the logic - there was no plan or flowchart, I just wrote it. Quote Link to comment Share on other sites More sharing options...
samifox Posted February 9, 2015 Author Share Posted February 9, 2015 How did u observe this on the go? Are u a ginuse? Or u have 25 years programming expierience? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 9, 2015 Share Posted February 9, 2015 Thanks, but I'm far from a genius and I certainly don't have 25 years programming experience... I do have a degree in pure mathematics and so I have studied logic to a high level which goes hand in hand with programming. Quote Link to comment Share on other sites More sharing options...
samifox Posted February 9, 2015 Author Share Posted February 9, 2015 i didnt know that logic can be though. can you refer me to some logic tutorials? (and i do think that you are a genius, sorry:twisted:) Quote Link to comment Share on other sites More sharing options...
Jef! Posted February 9, 2015 Share Posted February 9, 2015 I like these challenges, and the in depth understanding of the function that I get from replicating its exact behavior. I hope you will forgive my intrusion: I've decided to give it a try even if it is an old thread. My approach with these kind of problems is using a flag and including it in the while evaluation. Not as fancy as Lee's but +1 to everything that has been said here, Lee is.... unique (defun everyjef ( sign lst1 lst2 / escapeflag ) (while (and lst1 lst2 (not escapeflag)) (if (sign (car lst1) (car lst2)) (setq lst1 (cdr lst1) lst2 (cdr lst2)) (setq escapeflag t) ) ) (not escapeflag) ) it seems to work as the vl-every... me happy! Command: (everyjef = '(1 2 3 4) '(1 2 3)) T Command: (everyjef = '(1 2 3) '(1 2 4)) nil Command: (everyjef = '(1 2 3) '(1 2 3)) T Command: (everyjef = '(1 2 3) '(1 2 3 "a")) T Command: (everyjef = '(1 2 3 "a" ) '(1 2 3 "a")) T Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 9, 2015 Share Posted February 9, 2015 Well done Jef! - I too enjoy the 'challenge' threads. 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.