Jump to content

Recommended Posts

Posted

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 :)

  • Replies 37
  • Created
  • Last Reply

Top Posters In This Topic

  • samifox

    13

  • Lee Mac

    9

  • pBe

    4

  • Tharwat

    3

Top Posters In This Topic

Posted Images

Posted
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 .

Posted

That's incredibly kind of you to say BlackBox

 

You're very welcome. :beer:

 

 

 

... 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).

 

:geek: :rofl:

 

visual.lisp.xpanded.png

Posted
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:

Posted
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
   )
   
 )

Posted
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

Posted

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.

Posted
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

Posted
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:)

Posted
thanks for that powerful explination:)

 

You're welcome Shay - I'm glad it helps.

Posted

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.

  • 9 months later...
Posted

   ([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 )

Posted

Well done for understanding the logic - there was no plan or flowchart, I just wrote it.

Posted

How did u observe this on the go? Are u a ginuse? Or u have 25 years programming expierience?

Posted

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.

Posted

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:)

Posted

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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...