Author Topic: Recursion.. not really right now but trying.  (Read 11535 times)

0 Members and 2 Guests are viewing this topic.

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Recursion.. not really right now but trying.
« Reply #15 on: March 21, 2006, 04:52:03 AM »
(...) An aside ... using cddr to strip out "." and ".." unconditionally is a little dangerous, as the vl-directory-files function will not include them if you run said function on a root directory like (vl-directory-files "c:\\" nil -1). (...) Hope (that makes sense and) that helps some.
That makes really sense... thanks Michael! I've overlooked that... :ugly:
Must be:
Code: [Select]
;
; == Function MeGetSubFolders
; Returns a recursive list of all folders behind a start folder.
; Arguments [Type]:
;   Fld = Start folder [STR]
; Return [Type]:
;   > List of all (sub)folders [LIST]
;   > Nil if nothing found [BOOLEAN]
; Notes:
;   - Deep folder structures slow down the function.
;
(defun MeGetSubFolders (Fld / CurFld TmpLst)
 (mapcar
 '(lambda (l)
   (setq CurFld (strcat Fld "\\" l))
   (cons CurFld (apply 'append (MeGetSubFolders CurFld)))
  )
  (if (vl-position "." (setq TmpLst (vl-directory-files Fld nil -1)))
   (cddr TmpLst)
   TmpLst
  )
 )
)
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Recursion.. not really right now but trying.
« Reply #16 on: March 21, 2006, 09:09:55 AM »
No prob Jürg, it's an easy one to miss. I do the redef thing because it would only be a factor on the very first call, even tho the function may be called hundreds or more times thereafter. Tho the performance hit appears nominal when testing for it on every call, I'm so retentive I just couldn't leave it that way.

:-D

Now back to nursing my headache.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Recursion.. not really right now but trying.
« Reply #17 on: March 21, 2006, 09:26:14 AM »
(...) I do the redef thing because it would only be a factor on the very first call, even tho the function may be called hundreds or more times thereafter. Tho the performance hit appears nominal when testing for it on every call, I'm so retentive I just couldn't leave it that way.

Fully agree, but I've chosen the 'second best' way because the time the HW need to scan drive/network is remarkable bigger
than the tiny amount of time for the repetitive call of this comparison - just a guess... :-)
Now back to nursing my headache.
Hope you feel better soon... I know headache only just at the morning after to much single malt... :doa:
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Recursion.. not really right now but trying.
« Reply #18 on: March 21, 2006, 09:56:22 AM »
Hope you feel better soon... I know headache only just at the morning after to much single malt... :doa:

Thanks Jürg. I had a bowl of ibuprofen so it should be gone in a bit.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Recursion.. not really right now but trying.
« Reply #19 on: March 21, 2006, 05:16:07 PM »
<snip>
Speaking of Vladimir, it was Vladimir who had recommended a book Structure And Interpretation of Computer Programs that was instrumental in pushing my lispin' knowledge to the next level. It really changed the landscape for me and "took the reigns and blinders completely off" so to speak (tho I've still lots to learn). I don't know what ever happened to Vladimir, he stopped posting to the ngs long ago (as did Mr. Urban) but I'm sure he excelled at whatever he set his mind to and I'm grateful to this day that he mentioned said book. Thank you Vladimir.
<snip>

I spoke to him a little bit ago and he said hes still doing a little AutoLisp and C++ but mostly hes into Prolog and Haskel now. He said hes still doing some Scheme too.

Oh yes I agree, that man is amazing. I study his code for days trying to catch all the little neuonces about it. I think im still working on his (Or was it Reni's) Backquoting. I pick it up every once and a while, only to put it down with a hurting head. *smile*

Recursion is a beast. Just when you think you "have it" you learn something new. Just when you think you understand how stack-calls &or info works you get smoked with a weird result in some seeming simple app that throws you back to the begining.

Lately, all the recursion I use is as a simple loop if you will. For instance: (This is the first one I came accross when I searched upwards in my junk file ...its been awhile since ive played arround *huh*)

Code: [Select]
(defun my-getpoint ( pt str / a getpt )
  ;; a general getpoint function for a test I am running.
  ;; Se7en
  ;; 02.24.06
  ;;
  ;; Just a getpoint function that uses grread so that I can tell
  ;; if the user right clicks.
  ;; I am going to STOP the right click for now, I want to add the
  ;; ability to do somethign when the user right clicks later.
  (if (eq pt 'nil)
    (set 'getpt (getpoint str))
    (set 'getpt (getpoint pt str)))
  (setq a (grread getpt 2))
  (if (and a (not (= (car a) 12)))
    (cadr a)
    (my-getpoint pt str)) )
But what all that garbage is doing is something simple like this: If a condition isnt met, do it again. That simple.(This is obviously a bit diff int functionality, but the recurstion is the same.)

Code: [Select]
(defun my-getpoint ( / a )
  (setq a (getpoint "\nPlease pick a point: "))
  (if a
    a
    (my-getpoint)
    )
  )

As MP said, this makes it easier on me to write. (Less code)

SICP is an awesome book. I refer to it constantly. Im always studing that book. I would bet I refer to it at least twice a week. (Well I guess its been about a month since ive actualy played arround with code but when im goofing arround with code I do.)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Recursion.. not really right now but trying.
« Reply #20 on: March 21, 2006, 06:06:05 PM »
Speaking of Vladimir, it was Vladimir who had recommended a book (Structure And Interpretation of Computer Programs that was instrumental in pushing my lispin' knowledge to the next level. It really changed the landscape for me and "took the reigns and blinders completely off" so to speak (tho I've still lots to learn). I don't know what ever happened to Vladimir, he stopped posting to the ngs long ago (as did Mr. Urban) but I'm sure he excelled at whatever he set his mind to and I'm grateful to this day that he mentioned said book. Thank you Vladimir.
Thanks for the tip, ordered the book last night. Found a used Hardback in V. good condition for only $40.00. :)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Recursion.. not really right now but trying.
« Reply #21 on: March 22, 2006, 12:58:36 AM »
Some time back, I have started to write lessons about recursive functions...
"Lessons of the creation of the recursive functions"
Look, it will be possible interestingly.

The original (RU):
http://www.autocad.ru/cgi-bin/f1/board.cgi?t=25113OT

Machine translation (EN):
http://babelfish.altavista.com/babelfish/trurl_pagecontent?lp=ru_en&trurl=http%3a%2f%2fwww.autocad.ru%2fcgi-bin%2ff1%2fboard.cgi%3ft%3d25113OT

I wish to add, it only the beginning, continuation will be later :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Recursion.. not really right now but trying.
« Reply #22 on: March 22, 2006, 08:06:01 AM »
Thanks, I tried the English link but got an error.
Sent a message to babelfish about the error.
I hope they can fix it.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Recursion.. not really right now but trying.
« Reply #23 on: March 22, 2006, 08:20:53 AM »
Thanks, I tried the English link but got an error.
Sent a message to babelfish about the error.
I hope they can fix it.
If you wish, I can make machine translation, but his quality is doubtful...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Recursion.. not really right now but trying.
« Reply #24 on: March 22, 2006, 09:17:34 AM »
<snip>I spoke to him [Vladimir] a little bit ago and he said hes still doing a little AutoLisp and C++ but mostly hes into Prolog and Haskel now. He said hes still doing some Scheme too.</snip>

Thanks for the update John. I'm not surprised Vladimir plays with Haskell -- a lot of my profs at university were very smitten with it, and said lisp programmers in particular tend to fall real hard for it. I recall hearing "you'd love it" more than once. Anyways, I wish him well.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Recursion.. not really right now but trying.
« Reply #25 on: March 22, 2006, 09:39:56 AM »
I will help Elpanov, clean up his translated article.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Recursion.. not really right now but trying.
« Reply #26 on: March 22, 2006, 11:21:22 AM »
Some time back, I have started to write lessons about recursive functions...
"Lessons of the creation of the recursive functions"
Look, it will be possible interestingly.

The original (RU):
http://www.autocad.ru/cgi-bin/f1/board.cgi?t=25113OT

Machine translation (EN):
http://babelfish.altavista.com/babelfish/trurl_pagecontent?lp=ru_en&trurl=http%3a%2f%2fwww.autocad.ru%2fcgi-bin%2ff1%2fboard.cgi%3ft%3d25113OT

I wish to add, it only the beginning, continuation will be later :-)
Thanks.  I was able to view the page, but the code doesn't come out right.  I will look, and study it more when I have the time.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.