Author Topic: ==={ Challenge }=== General dyadic operation  (Read 8252 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Gator
  • Posts: 3180
  • Marko Ribar, architect
Re: ==={ Challenge }=== General dyadic operation
« Reply #30 on: March 19, 2014, 11:21:28 AM »
maybe:
Code - Auto/Visual Lisp: [Select]
  1. (defun dyadic (f x y)
  2.   (cond ((or (null x) (null y)) nil)
  3.         ((atom x) ((eval f)  x y))
  4.         ((cons (dyadic f (car x) (car y)) (dyadic f (cdr x) (cdr y))))
  5.   )
  6. )
:-)

maybe:
Code - Auto/Visual Lisp: [Select]
  1. (defun mapTree (f l)
  2.   (cond ((apply 'or (mapcar 'null l)) nil)
  3.         ((apply 'and (mapcar 'atom l)) (eval (cons (eval f) l)))
  4.         ((cons (mapTree f (mapcar 'car l)) (mapTree f (mapcar 'cdr l))))
  5.   )
  6. )
  7.  
:-)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

bruno_vdh

  • Guest
Re: ==={ Challenge }=== General dyadic operation
« Reply #31 on: March 19, 2014, 12:02:37 PM »
@ribarm
_$ (mapTree 'and '(((1 2) (3 . 4) 5) ((1 2) (3 . 4) 5))); form special
; erreur: Impossible d'appliquer la feuille spéciale: AND

@ElpanovEvgeniy
_$ (dyadic '+ '((1 2) (3 . 4) 5) '((1 2 3) (3 . 4) 5)); case of unbalanced arguments
((2 4) (6 . 8 ) 10); Not too sure if that's a "good" thing.
« Last Edit: March 19, 2014, 12:20:55 PM by bruno_vdh »

ribarm

  • Gator
  • Posts: 3180
  • Marko Ribar, architect
Re: ==={ Challenge }=== General dyadic operation
« Reply #32 on: March 19, 2014, 12:17:18 PM »
You're right Bruno, my prvious version was OK...

Code: [Select]
Command: (maptree 'and '(((1 2) (3 . 4) 5) ((1 2) (3 . 4) 5) ((1 2) (3 . 4) 5)))
((T T) (T . T) T)

Command: (maptree and '(((1 2) (3 . 4) 5) ((1 2) (3 . 4) 5) ((1 2) (3 . 4) 5)))
; error: cannot apply special form: AND

Command: (maptree '+ '(((1 2) (3 . 4) 5) ((1 2) (3 . 4) 5) ((1 2) (3 . 4) 5)))
((3 6) (9 . 12) 15)

Command: (maptree + '(((1 2) (3 . 4) 5) ((1 2) (3 . 4) 5) ((1 2) (3 . 4) 5)))
((3 6) (9 . 12) 15)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

bruno_vdh

  • Guest
Re: ==={ Challenge }=== General dyadic operation
« Reply #33 on: March 19, 2014, 12:26:48 PM »
maybe:

Code: [Select]
(defun mapTree (f l)
  (cond ((null (apply 'or l)) nil)
        ((atom (car l)) (eval (cons f l)))
        ((cons (mapTree f (mapcar 'car l)) (mapTree f (mapcar 'cdr l))))
  )
)


Code: [Select]
(defun dyadic (fun x y)
  (cond ((null (or x y)) nil)
        ((atom x) (eval (cons fun '(x y))))
        ((cons (dyadic fun (car x) (car y)) (dyadic fun (cdr x) (cdr y))))
  )
)

chlh_jd

  • Guest
Re: ==={ Challenge }=== General dyadic operation
« Reply #34 on: March 20, 2014, 11:44:31 AM »
All of yours about Maptree and Dyadic function are very good . Cheers  :-)

Just a question: Does the function always take 2 atomic values as argument? I.e. it never expects a list?
Still not answered. Similar to the dotted pair problem, this makes the generalized function very different. E.g. what if you're using a function like distance to obtain the distances between 2 lists of points?

Same type of thing applies for the dotted pair. Should such even be allowed? I mean, this is a form of mapcar, and since mapcar doesn't allow dotted pairs, should this allow it?

As for recursion (or even tail-call) over mapcar, that is a bit dangerous to use as iteration loop over the list. I think it should be fine to use recursion to iterate over the tree's depth, but it's length might become too long for AutoLisp's stack (i.e. around 15000 iterations).

1+
"Maptree"  is the work of VLIDE . Why do not Vlide give "Maptree" function , we don't know . But we know it has a lot problems to solve .
        1. What the 'fun want , a beautiful girl or a barbecue or a group of dudes ? It must be detected before execution , it's difficult such as write a check-engine of GPU .
       
Code - Auto/Visual Lisp: [Select]
  1.  (append 4 '(1 2 3));_must be pre-checked fuction append want not a atom .
  2.                               (distance '(1 2) '(2 2))-->1.0;_two single lists are not atom
  3.                               (matrix-fun '((...)...) '((...)...))-->?;_double-linked list .
        2.  Can give the result like (+ Man Woman)--> New child . It's clear, if the varients are not same will give the same result ,  Errors . It may Crash AutoCAD programe .
       
Code - Auto/Visual Lisp: [Select]
  1.  (while (not (+ 1 "2."));_would you like working with a lot of error or interruption tips ?
  2.                             (progn ...))
        3.  How to select the size of the shoes, some one like smaller , some one feel comfortable when he catch bigger ,but some one like both.
         
Code - Auto/Visual Lisp: [Select]
  1.  (+  '(1 2) (1 2 3)) -->(2 4) or (2 4 3);_They are all right ,depends on what you need .
  2.          (distance '(1 2) '(1 2 3))-->0.0

        So take the girl or the suitable shoes you like .
 
        Thank you .