samifox Posted April 20, 2014 Share Posted April 20, 2014 hi making some researches on list manipulation, this is the (vl-every) issue: (vl-every '= '(1 2 3) '(1 2 3)) and this is my (while) equivalent, somehow i get hard time with how to return nil or T, finally i came up with a solution, is that right? (setq lst1 '(1 2 4) lst2 '(1 2 3) i 0 ) (while (or (< i (length lst1)) (< i (length lst2))) (if (= (nth i lst1) (nth i lst2)) (setq a T) (setq a nil) ) (setq i (1+ i)) a ) Thanks S Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 20, 2014 Share Posted April 20, 2014 variable 'a' would either be equal to T and nil in your example and that is not correct . Quote Link to comment Share on other sites More sharing options...
samifox Posted April 20, 2014 Author Share Posted April 20, 2014 variable 'a' would either be equal to T and nil in your example and that is not correct . that function suppose to return either T or nil Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 20, 2014 Share Posted April 20, 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))) ) ) ([color=BLUE]defun[/color] every2 ( prd ls1 ls2 ) ([color=BLUE]apply[/color] '[color=BLUE]and[/color] ([color=BLUE]mapcar[/color] 'prd ls1 ls2)) ) ([color=BLUE]defun[/color] every3 ( prd ls1 ls2 [color=BLUE]/[/color] x y ) ([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)) ) Example: _$ (vl-every '= '(1 2) '(1 2 3)) T _$ (every1 = '(1 2) '(1 2 3)) T _$ (every2 = '(1 2) '(1 2 3)) T _$ (every3 = '(1 2) '(1 2 3)) T _$ (vl-every '= '(1 2 4) '(1 2 3)) nil _$ (every1 = '(1 2 4) '(1 2 3)) nil _$ (every2 = '(1 2 4) '(1 2 3)) nil _$ (every3 = '(1 2 4) '(1 2 3)) nil Quote Link to comment Share on other sites More sharing options...
samifox Posted April 20, 2014 Author Share Posted April 20, 2014 LEE..if you weren't exist we had to invent you Thanks you! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 20, 2014 Share Posted April 20, 2014 You're welcome Shay Quote Link to comment Share on other sites More sharing options...
Bhull1985 Posted April 21, 2014 Share Posted April 21, 2014 If Lee didn't exist, autodesk may have done something crazy and gotten rid of autoLISP, honestly. With all these APIs, someone needs to be a constant reminder of the flexibility and power of LISP.....and my vote goes to Lee that's for sure. Quote Link to comment Share on other sites More sharing options...
Snownut Posted April 21, 2014 Share Posted April 21, 2014 Sure seems like in the past couple of years there seems to be more interest in LISP. One huge benefit is its ability to run cross platforms and multiple versions without the need to recompile for each. Quote Link to comment Share on other sites More sharing options...
Bhull1985 Posted April 21, 2014 Share Posted April 21, 2014 Again, I believe Lee to be (not solely, but hugely) responsible for the interest. I can attest to the fact that if there was a prominent JavaScript coder posting on the forums and making autocad do anything he wanted it to.......then I may have picked up Java as the preferred API (assuming of course it was a viable option but this is just for arguments sake anyways), but Lee for the last very many years has been attracting at least myself to autoLISP and I very seriously doubt i'm the only one. He's shown how just about anything can be done using lisp or Vlisp, concise and prompt too, it's amazing how much can be accomplished with a few lines of code, in some routines.... Basically what I'm trying to get at is that if we lived in a universe with no Lee Mac and the autocad forums never saw a single post from him I'm not sure if I'd be lisping right now. Ripples man, ripples and waves. Perpetuating a good thing has always been something I've tried to do.....aint broke don't fix it, sort of thinking (though improvements aren't a FIX)... and with the way the internet works...Lee being able to show the world that lisp is a powerful beast and consistently show us how it's done.......well if it wasn't Lee, and was say some other Guru doing Java or some other language- autodesk may have dropped LISP by now because it's so ancient. That's pretty far-fetched I know but the point is that we are all fortunate to have such a brilliant mind living and posting during the same time as we are (or that's how I feel at least) I don't mean to take anything from the other Gurus, as they're quite incredible as well. Henrique MS, Msasu, Marko, cldh_jh, Kerry, pBe, MP, Irneb, etc etc you know who you are.....and many of these gurus have been lisping for longer than Lee but I am not sure any are more prominent. Only one I can think who comes close is JTB over at JTB world just because he's got a fairly popular and visited website showcasing his lisp in the same manner that Lee does, although with different intentions. But to each their own and ... tldr, we're fortunate to have lee lisping instead of coding using another language....autoLISP is fortunate, rather... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 21, 2014 Share Posted April 21, 2014 Again, I believe Lee to be (not solely, but hugely) responsible for the interest. I can attest to the fact that if there was a prominent JavaScript coder posting on the forums and making autocad do anything he wanted it to.......then I may have picked up Java as the preferred API (assuming of course it was a viable option but this is just for arguments sake anyways), but Lee for the last very many years has been attracting at least myself to autoLISP and I very seriously doubt i'm the only one. He's shown how just about anything can be done using lisp or Vlisp, concise and prompt too, it's amazing how much can be accomplished with a few lines of code, in some routines.... Basically what I'm trying to get at is that if we lived in a universe with no Lee Mac and the autocad forums never saw a single post from him I'm not sure if I'd be lisping right now. Ripples man, ripples and waves. Perpetuating a good thing has always been something I've tried to do.....aint broke don't fix it, sort of thinking (though improvements aren't a FIX)... and with the way the internet works...Lee being able to show the world that lisp is a powerful beast and consistently show us how it's done.......well if it wasn't Lee, and was say some other Guru doing Java or some other language- autodesk may have dropped LISP by now because it's so ancient. That's pretty far-fetched I know but the point is that we are all fortunate to have such a brilliant mind living and posting during the same time as we are (or that's how I feel at least) I don't mean to take anything from the other Gurus, as they're quite incredible as well. Henrique MS, Msasu, Marko, cldh_jh, Kerry, pBe, MP, Irneb, etc etc you know who you are.....and many of these gurus have been lisping for longer than Lee but I am not sure any are more prominent. Only one I can think who comes close is JTB over at JTB world just because he's got a fairly popular and visited website showcasing his lisp in the same manner that Lee does, although with different intentions. But to each their own and ... tldr, we're fortunate to have lee lisping instead of coding using another language....autoLISP is fortunate, rather... That's incredibly flattering of you to say Brandon - many thanks indeed! As they say, we all stand on the shoulders of giants - and needless to say, there were several 'giants' around when I first started with LISP who were certainly inspirational to my learning. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted April 21, 2014 Share Posted April 21, 2014 Oooo! A bandwagon.... While I was introduced to the world of development through the prism that is LISP for very different reasons, I too quickly came to recognize, and respect the wisdom Lee kindly offers... You truly are a master of your chosen crafts, and I sincerely wish you well in all of your endeavors. Point of fact, I never attempted to master LISP to the level you frequently demonstrate with such ease, however, I would not have become the .NET developer I am today, in what I consider such a very short period of time, had I not known you, Lee... And for that, I thank you. Cheers Quote Link to comment Share on other sites More sharing options...
samifox Posted April 22, 2014 Author Share Posted April 22, 2014 John McCarthy would be proud or insecure if he was alive. LEE come on..write a book...it will be a best seller ! Quote Link to comment Share on other sites More sharing options...
pBe Posted April 22, 2014 Share Posted April 22, 2014 Hear, hear @Samifox To truly emulate the vl-very function, the code should evaluate to T or nil regardless the length of the list is equal or not. As shown on LM's sample codes. Otherwise stick with equal function. Also problem with your code is you only see the value of the last evaluation , so '(1 2 4) would be evaluate to T if the other list is '( 0 1 4). Now for your homework, figure out how to make your existing code to work under the two conditions i mentioned above. Holler if you need help @brandon Thank you for the honorable mention Quote Link to comment Share on other sites More sharing options...
Bhull1985 Posted April 22, 2014 Share Posted April 22, 2014 Well deserved Quote Link to comment Share on other sites More sharing options...
samifox Posted April 22, 2014 Author Share Posted April 22, 2014 Hear, hear @Samifox To truly emulate the vl-very function, the code should evaluate to T or nil regardless the length of the list is equal or not. As shown on LM's sample codes. Otherwise stick with equal function. Also problem with your code is you only see the value of the last evaluation , so '(1 2 4) would be evaluate to T if the other list is '( 0 1 4). Now for your homework, figure out how to make your existing code to work under the two conditions i mentioned above. Holler if you need help @brandon Thank you for the honorable mention (setq st1 '(1 2 3 4) st2 '(1 2 3) ) (while (and (car st1)(car st2 )(equal (car st1) (car st2))) (setq st1 (cdr st1) st2 (cdr st2)) T ) (vl-every '= (setq st1 '(1 2 2) st2 '(1 2 3) )) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 22, 2014 Share Posted April 22, 2014 While I was introduced to the world of development through the prism that is LISP for very different reasons, I too quickly came to recognize, and respect the wisdom Lee kindly offers... You truly are a master of your chosen crafts, and I sincerely wish you well in all of your endeavors. Point of fact, I never attempted to master LISP to the level you frequently demonstrate with such ease, however, I would not have become the .NET developer I am today, in what I consider such a very short period of time, had I not known you, Lee... And for that, I thank you. That's incredibly kind of you to say BlackBox - and 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...! John McCarthy would be proud or insecure if he was alive.LEE come on..write a book...it will be a best seller ! If only I had the time! Quote Link to comment Share on other sites More sharing options...
pBe Posted April 23, 2014 Share Posted April 23, 2014 (while (and (car st1)(car st2 )(equal (car st1) (car st2))) (setq st1 (cdr st1) st2 (cdr st2)) T ) 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. Quote Link to comment Share on other sites More sharing options...
samifox Posted April 23, 2014 Author Share Posted April 23, 2014 That's incredibly kind of you to say BlackBox - and 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...! what you saying LEE? if you could go back in tmie you start stright to .NET? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 23, 2014 Share Posted April 23, 2014 (edited) Another . (defun every-p (l1 l2 / l) (and (mapcar '(lambda (j k) (and (eq j k) (setq l (cons 't l)))) l1 l2) (= (min (length l1) (length l2)) (length l)) ) ) To test the function . (every-p '(1 2 3 4) '(1 2 3 4)) Edited April 23, 2014 by Tharwat to work with minimum equal lists Quote Link to comment Share on other sites More sharing options...
pBe Posted April 23, 2014 Share Posted April 23, 2014 Watch out... To truly emulate the vl-every function, ..... (vl-every '= '(1 2 3 )'(1 2 3 4)) T (EVERY-P '(1 2 3 )'(1 2 3 4)) nil 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.