Author Topic: -={ Challenge }=- Nested Summing  (Read 9078 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8706
  • AKA Daniel
Re: -={ Challenge }=- Nested Summing
« Reply #30 on: July 17, 2010, 08:19:19 PM »
It gives a compiler error

Code: [Select]
error C2664: '_AdsRegisteredSymbol::_AdsRegisteredSymbol(const _AdsFuncPtr,const ACHAR *,const bool,const UINT)' :
cannot convert parameter 1 from 'int (__cdecl *)(resbuf *)' to 'const _AdsFuncPtr'

Maybe your getting the args from lisp another way ?
« Last Edit: July 17, 2010, 08:22:33 PM by eAmbiguousOutput »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8706
  • AKA Daniel
Re: -={ Challenge }=- Nested Summing
« Reply #31 on: July 17, 2010, 08:24:47 PM »
Oh I see from looking at your shell routine, you use another function "DoFunc" whereas I'm using a macro

ACED_ADSSYMBOL_ENTRY_AUTO(CBrxApp, nsum, false)

pkohut

  • Guest
Re: -={ Challenge }=- Nested Summing
« Reply #32 on: July 17, 2010, 08:28:13 PM »
Oh I see from looking at your shell routine, you use another function "DoFunc" whereas I'm using a macro

ACED_ADSSYMBOL_ENTRY_AUTO(CBrxApp, nsum, false)

Ya, I don't have the ARX wizard installed in VC2008 so I just grabbed some boiler plate code from the
frac sample. (edit) and didn't think about the fact you are.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8706
  • AKA Daniel
Re: -={ Challenge }=- Nested Summing
« Reply #33 on: July 17, 2010, 09:25:50 PM »
Yes, I tend to use the wizard or grab one of my templates (based off the wizard) . I've never seen the resbuf passed through dofun though, I always used

Code: [Select]
rc = (*exfun[val].fptr)();
learn something new everyday  8-)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: -={ Challenge }=- Nested Summing
« Reply #34 on: July 18, 2010, 03:45:24 PM »
my variant:
Code: [Select]
(defun f (l)
 (if (listp l)
  (apply '+ (mapcar 'f l))
  l
 )
)
test:
Code: [Select]
(f '(1 2 (3 4 (1)))) ;=>> 11

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: -={ Challenge }=- Nested Summing
« Reply #35 on: July 18, 2010, 03:59:22 PM »
Very concise Evgeniy!

Great solution for lists with no dotted pairs  :wink:

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: -={ Challenge }=- Nested Summing
« Reply #36 on: July 18, 2010, 04:12:44 PM »
Very concise Evgeniy!

Great solution for lists with no dotted pairs  :wink:

variant 2:

Code: [Select]
(defun f (l)
 (cond ((not l) 0)
       ((numberp l) l)
       ((+ (f (car l)) (f (cdr l))))
 )
)
test:
Code: [Select]
(f '( 1 2 ( 3 4 ( 1 ) (3 . 4)))) ;=>> 18

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: -={ Challenge }=- Nested Summing
« Reply #37 on: July 18, 2010, 04:16:11 PM »
variant 2.5 (optimized)
Code: [Select]
(defun f (l)
 (cond ((numberp l) l)
       (l (+ (f (car l)) (f (cdr l))))
       (0)
 )
)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: -={ Challenge }=- Nested Summing
« Reply #38 on: July 18, 2010, 04:31:45 PM »
 8-)
You're a master Evgeniy !
Speaking English as a French Frog

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: -={ Challenge }=- Nested Summing
« Reply #39 on: July 18, 2010, 04:35:47 PM »
8-)
You're a master Evgeniy !
Thanks!
You took the best of my!  :-)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: -={ Challenge }=- Nested Summing
« Reply #40 on: July 18, 2010, 06:23:54 PM »
8-)
You're a master Evgeniy !

x2  8-)

pkohut

  • Guest
Re: -={ Challenge }=- Nested Summing
« Reply #41 on: July 18, 2010, 06:52:06 PM »
variant 2.5 (optimized)


Masterful.  :kewl:

highflyingbird

  • Bull Frog
  • Posts: 415
  • Later equals never.
Re: -={ Challenge }=- Nested Summing
« Reply #42 on: July 18, 2010, 08:36:27 PM »
variant 2.5 (optimized)
Code: [Select]
(defun f (l)
 (cond ((numberp l) l)
       (l (+ (f (car l)) (f (cdr l))))
       (0)
 )
)

I think it will be better.
Code: [Select]
(defun f (l)
  (cond ((numberp l) l)
((atom l) 0)
(t (+ (f (car l)) (f (cdr l))))
  )
)

for example:

(f (list 1 (list (ssget) 1) (entsel "select:") (cons 2 (cons nil (cons nil 1)))))
I am a bilingualist,Chinese and Chinglish.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: -={ Challenge }=- Nested Summing
« Reply #43 on: July 19, 2010, 02:09:26 PM »
variant 2.5 (optimized)
Code: [Select]
(defun f (l)
 (cond ((numberp l) l)
       (l (+ (f (car l)) (f (cdr l))))
       (0)
 )
)

I think it will be better.
Code: [Select]
(defun f (l)
  (cond ((numberp l) l)
((atom l) 0)
(t (+ (f (car l)) (f (cdr l))))
  )
)

for example:

(f (list 1 (list (ssget) 1) (entsel "select:") (cons 2 (cons nil (cons nil 1)))))

Perhaps, but the original spec was for lists of purely numerical elements.