Author Topic: Tell me why I did it like this. :)  (Read 19219 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Tell me why I did it like this. :)
« Reply #30 on: September 24, 2010, 05:26:03 PM »
Smarty-pants  :lol:

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
Re: Tell me why I did it like this. :)
« Reply #31 on: September 24, 2010, 06:58:52 PM »
`Smarty-pants'? If you a referring to my IQ, yes. If you are referring to my code, *meh* more like experience and a few books (In AutoLISP: it is better to operate on a list. In programming: it is always better to K.I.S.S.).

But you had to see something like that coming didn't you (I thought I taught you how to build a substitution model)? ...You were putting a heck of a lot of information on the Stack; you would have done better to use a recursive procedure with an iterative process instead. I would be willing to bet that my procedure would still have been faster but at least yours would have been able to handle a longer string then it currently does.

Anyways, I'm going to a friends house for food and a movie. Take care.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Tell me why I did it like this. :)
« Reply #32 on: September 24, 2010, 08:31:39 PM »
Lee,
This would be a far faster method (NOTE: I reformatted this function in the VLIDE for Kerry :D ).
Code: [Select]
;; < .. >

I thank you, my therapist thanks you.  :-)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Tell me why I did it like this. :)
« Reply #33 on: September 24, 2010, 08:43:42 PM »
Don't know how this performs comparably but it's how I would do it:

Code: [Select]
(defun SplitByCaps ( text / lst )
    (vl-list->string
        (cons
            (car (setq lst (vl-string->list text)))
            (apply 'append
                (mapcar
                    (function (lambda (x) (if (zerop (logand 32 x)) (list 32 x) (list x))))
                    (cdr lst)
                )
            )    
        )    
    )
)

Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Tell me why I did it like this. :)
« Reply #34 on: September 25, 2010, 12:06:05 AM »
my contribution...

Code: [Select]
(defun AT:SplitByCaps (s)
  (apply
    (function strcat)
    (cons (substr s 1 1)
          (mapcar (function (lambda (i)
                              (if (<= 65 i 90)
                                (strcat " " (chr i))
                                (chr i)
                              )
                            )
                  )
                  (cdr (vl-string->list s))
          )
    )
  )
)

Code: [Select]
(defun AT:SplitByCaps-2 (s / l)
  (apply
    (function strcat)
    (cons (chr (car (setq l (vl-string->list s))))
          (mapcar (function (lambda (i)
                              (if (<= 65 i 90)
                                (strcat " " (chr i))
                                (chr i)
                              )
                            )
                  )
                  (cdr l)
          )
    )
  )
)

slight change on MP's
Code: [Select]
(defun SplitByCaps (text / lst)
  (vl-list->string
    (cons
      (car (setq lst (vl-string->list text)))
      (apply (function append)
             (mapcar
               (function (lambda (x)
                           (if (<= 65 i 90)
                             (list 32 x)
                             (list x)
                           )
                         )
               )
               (cdr lst)
             )
      )
    )
  )
)
« Last Edit: September 25, 2010, 12:10:03 AM by alanjt »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
Re: Tell me why I did it like this. :)
« Reply #35 on: September 25, 2010, 12:26:47 AM »
I don't think i saved the string i used to test but i just constructed it with a minor bit of code. I can see if i can get some time to do it again on Monday but i will place my bet now that MP will take first place and alanjt (third version) will be second place.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Tell me why I did it like this. :)
« Reply #36 on: September 25, 2010, 09:41:48 AM »
Nice coding guys (as always lol)

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Tell me why I did it like this. :)
« Reply #37 on: September 25, 2010, 09:52:17 AM »
MP,

Nice idea, but a few other chars don't have the 32-bit set...

Code: [Select]
(SplitByCaps "This[is]a^Te_st")
>> "This [is ]a ^ Te _st"

I like your thinking however.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Tell me why I did it like this. :)
« Reply #38 on: September 25, 2010, 11:29:53 AM »
I hear what you're sayin' I've never seen those characters in camel cased enum names.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Tell me why I did it like this. :)
« Reply #39 on: September 25, 2010, 12:58:22 PM »
I hear what you're sayin' I've never seen those characters in camel cased enum names.

Fair point - I was in the 'generic function' mindset...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Tell me why I did it like this. :)
« Reply #40 on: September 25, 2010, 03:23:58 PM »
Good point Lee / Concede, genericized:

Code: [Select]
(defun SplitByCaps ( text / lst )
    (vl-list->string
        (cons
            (car (setq lst (vl-string->list text)))
            (apply (function append)
                (mapcar
                    (function (lambda (x) (if (< 64 x 91) (list 32 x) (list x))))
                    (cdr lst)
                )
            )   
        )   
    )
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Tell me why I did it like this. :)
« Reply #41 on: September 25, 2010, 04:15:07 PM »
 :-)

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
Re: Tell me why I did it like this. :)
« Reply #42 on: September 27, 2010, 09:31:09 AM »
*GACK* MP, your second function was the exact same route i was planning at first too but i couldn't think of how to append it (I tried appending after the uppermost cons) and i gave up and went the easy route. Ah, its so obvious now that i seen how you applied the append I should make myself sit on the floor the rest of the day. *lol*

Anyways, i am assembling a speed test right now. I will report back when i get it done.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Tell me why I did it like this. :)
« Reply #43 on: September 27, 2010, 09:37:54 AM »
*GACK* MP, your second function was the exact same route i was planning at first too but i couldn't think of how to append it (I tried appending after the uppermost cons) and i gave up and went the easy route. Ah, its so obvious now that i seen how you applied the append I should make myself sit on the floor the rest of the day. *lol*

Anyways, i am assembling a speed test right now. I will report back when i get it done.

slight change on MP's
Code: [Select]
(defun SplitByCaps (text / lst)
  (vl-list->string
    (cons
      (car (setq lst (vl-string->list text)))
      (apply (function append)
             (mapcar
               (function (lambda (x)
                           (if (<= 65 i 90)
                             (list 32 x)
                             (list x)
                           )
                         )
               )
               (cdr lst)
             )
      )
    )
  )
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
Re: Tell me why I did it like this. :)
« Reply #44 on: September 27, 2010, 09:45:14 AM »
alanjt, *ACK!*
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org