(defun isCordEqual (pa pb)
(vl-every '= pa pb)
)
(< (distance '(0 0 0) a) (distance '(0 0 0) b))
(setq lst (list
(cons "a" (list '( (0 2 4) (0 7 0) (4 2 0))))
(cons "b" (list '( (8 2 0) (0 5 0) (7 7 0))))
(cons "c" (list '( (3 2 0) (0 2 0) (9 3 0))))
)
)
i want to know which list (a,b or c) has the highest/lowest point
What do you mean by 'smaller than' for 3d points ???
What do you mean by 'smaller than' for 3d points ???
It is a little tedious talking to myself.
by highest i meant the coordinate with the largest y valuei want to know which list (a,b or c) has the highest/lowest point
Highest meaning largest y-coordinate value?
Largest z-coordinate value?
Furthest from the origin?
Here's a simple way to approach it:Code - Auto/Visual Lisp: [Select]Code - Auto/Visual Lisp: [Select]
(setq lst '( ("a" ((0 2 4) (0 7 0) (0 2 0))) ("b" ((0 2 0) (0 5 0) (0 2 0))) ("c" ((3 2 0) (0 2 0) (9 3 0))) ) )Code - Auto/Visual Lisp: [Select]
_$ (foo lst) ("a" (0 7 0))
Here's a simple way to approach it:Code - Auto/Visual Lisp: [Select]Code - Auto/Visual Lisp: [Select]
(setq lst '( ("a" ((0 2 4) (0 7 0) (0 2 0))) ("b" ((0 2 0) (0 5 0) (0 2 0))) ("c" ((3 2 0) (0 2 0) (9 3 0))) ) )Code - Auto/Visual Lisp: [Select]
_$ (foo lst) ("a" (0 7 0))
(defun foo ( lst / key rtn )
(setq key (caar lst)
rtn (caadar lst)
)
(foreach grp lst
(foreach pnt (cadr grp)
(if (< (cadr rtn) (cadr pnt))
(setq rtn pnt
key (car grp)
)
)
)
)
(list key rtn)
)
;_rtn is the first point to be compared to
;_compare each delivered point's Y to rtn's Y
;_if the delivered point is bigger
;_replace rtn with that point
;_replace the key with the delivered key
;_
;_
i need to learn what you did. :-o
thanks for the meantime....
i understand it, but i dont know how i would explain it to someone else....what logical steps i need to plan in order to the solution?
;_rtn is the first point to be compared to
;_compare each delivered point's Y to rtn's Y
;_if the delivered point is bigger
;_replace rtn with that point
;_replace the key with the delivered key
;_
;_
;_rtn is the first point to be compared to
;_compare each delivered point's Y to rtn's Y
;_if the delivered point is bigger
;_replace rtn with that point
;_replace the key with the delivered key
;_
;_
Your understanding looks to be correct.
how do you map this logic to human language? :-)
how do you map this logic to human language? :-)
I don't see the point of your question - you have already described each step of the algorithm in 'human language', which shows that you already understand the algorithm; why then would you need this to be written in such a way to explain to someone else? Is this for a homework assignment?
how do you map this logic to human language? :)You mean something like this:
I was always thinking there was a way to tell the machine what to do as it was your employee, but I cant really see it possible, (otherwise there wasnt a need for programing language i guess).That's still just a pipe dream ... one that was thought up in the 50s - 60s: What's referred to as a 4th generation programming language, i.e. a natural human language. 3rd being the normal programming languages we use mostly (e.g. Lisp / C / Python / etc.), 2nd being assembly code (i.e. CPU instructions as abreviated words), 1st being the 1s and 0s representing the on/off signals the CPU actually receives and sends.
how do you map this logic to human language? :)You mean something like this:
- Keep track of the first point and its key in some local variables.
- Look at each key+point pair in turn, comparing its Y value to the one in that local variable.
- If the current point's Y is larger than the Y in the local variable, replace the contents of the local variables with the current point and its key.
- Once all points have finished being compared, the local variables should now contain the values of the largest point, so return them as the last statement in the function.
I was always thinking there was a way to tell the machine what to do as it was your employee, but I cant really see it possible, (otherwise there wasnt a need for programing language i guess).That's still just a pipe dream ... one that was thought up in the 50s - 60s: What's referred to as a 4th generation programming language, i.e. a natural human language. 3rd being the normal programming languages we use mostly (e.g. Lisp / C / Python / etc.), 2nd being assembly code (i.e. CPU instructions as abreviated words), 1st being the 1s and 0s representing the on/off signals the CPU actually receives and sends.
Unfortunately human languages are very complex with lots of ambiguity, not the best thing for a computer to "understand". For these to actually work, you'd need a computer with "true" artificial intelligence, i.e. it would need to "understand" your meaning instead of just following a set of steps.
(cons (cadr lst) (cddr lst))
:-o
@ Lee: take another look at line 6 of the code in your last post:Code: [Select](cons (cadr lst) (cddr lst))
:-o
@ Lee: take another look at line 6 of the code in your last post:Code: [Select](cons (cadr lst) (cddr lst))
:-o
Sorry roy, I don't follow? :?
(setq lst '(0 1 2 3 4))
(cons (cadr lst) (cddr lst)) => (1 2 3 4)
(cdr lst) => (1 2 3 4)
@ Lee: take another look at line 6 of the code in your last post:Code: [Select](cons (cadr lst) (cddr lst))
:-o
Sorry roy, I don't follow? :?Code: [Select](setq lst '(0 1 2 3 4))
(cons (cadr lst) (cddr lst)) => (1 2 3 4)
(cdr lst) => (1 2 3 4)
Lee and Roy...can u speak English please :police: :police: :police:Maybe you don't know the meaning of '=>'?
(setq lst
'(
("a" ((0 2 4) (0 7 0) (0 2 0)))
("b" ((0 2 0) (0 5 0) (0 2 0)))
("c" ((3 2 0) (0 2 0) (9 3 0)))
)
)
(defun reduceKey (operation funKey lst)
(if (cdr lst)
(reduceKey operation funKey (cons ((eval operation) funKey (car lst) (cadr lst)) (cddr lst)))
(car lst)
)
)
(defun PointMaxRank (Rank pt1 pt2)
(setq Rank (eval Rank))
(if (> (Rank pt2) (Rank pt1))
pt2
pt1
)
)
(("a" ((0 2 4) (0 7 0) (0 2 0))) ("b" ((0 2 0) (0 5 0) (0 2 0))) ("c" ((3 2 0) (0 2 0) (9 3 0))))
_$ (reduceKey 'PointMaxRank 'cadadr (mapcar '(lambda (item) (list (car item) (reduceKey 'PointMaxRank 'cadr (cadr item)))) lst))
("a" (0 7 0))
(defun fun (lst / key pt)
(mapcar '(lambda (l)
(mapcar '(lambda (xyz) (if (< (cadr pt) (cadr xyz)) (setq pt xyz key (car l))))
(cadr l)
)
)
lst
)
(list key pt)
)
Hello,I think that Irneb (reduce) function is intended as a generic function. Adding an argument, as in your (reduceKey), makes the function less so.
Irneb reading your excellent speech, makes me want to continue on this path
By adding arguments to functions "Reduce" and "PointMaxY"
I think that Irneb (reduce) function is intended as a generic function. Adding an argument, as in your (reduceKey), makes the function less so.Yes, I totally agree with that
(Fold is) The fundamental list iterator.
Inspired by irneb's REDUCE:Nice! 8)
roy, I think you'd enjoy this thread: http://www.theswamp.org/index.php?topic=37362 :wink:Thanks for pointing that topic out. Food for thought indeed...
@ Shay:
Can you explain how/why you create this list?:Code: [Select](setq lst
'(
("a" ((0 2 4) (0 7 0) (0 2 0)))
("b" ((0 2 0) (0 5 0) (0 2 0)))
("c" ((3 2 0) (0 2 0) (9 3 0)))
)
)
(setq lst
'(
("front" ((0 3 4) (0 4 0) (0 2 0)))
("back" ((0 1 3) (0 5 0) (0 3 0)))
("exist" ((3 2 0) (0 4 0) (9 3 0)))
)
)
(defun foo3 (lst)
(vl-sort
(mapcar
(function
(lambda (grp)
(list (car grp)
(vl-sort (cadr grp)
(function
(lambda (a b)
(> (cadr a) (cadr b))
)
)
)
)
)
)
lst
)
(function
(lambda (a b)
(> (cadr (caadr a)) (cadr (caadr b)))
)
)
)
)
(("back" ((0 5 0) (0 3 0) (0 1 3))) ("front" ((0 4 0) (0 3 4) (0 2 0))) ("exist" ((0 4 0) (9 3 0) (3 2 0))))
(setq lst
'(
("front" (0 3 4))
("front" (0 4 0))
("front" (0 2 0))
("back" (0 1 3))
("back" (0 5 0))
("back" (0 3 0))
("exist" (3 2 0))
("exist" (0 4 0))
("exist" (9 3 0))
)
)