Author Topic: Is SET a misunderstood function?  (Read 5663 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Is SET a misunderstood function?
« Reply #15 on: December 07, 2005, 09:06:16 PM »
Quote
try this...

why ?
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: Is SET a misunderstood function?
« Reply #16 on: December 07, 2005, 09:54:05 PM »
Kerry, you're killing me man.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Is SET a misunderstood function?
« Reply #17 on: December 07, 2005, 10:48:45 PM »
Quote
try this...

why ?

beacause seem to work.. :-D
Keep smile...

Peter Jamtgaard

  • Guest
Re: Is SET a misunderstood function?
« Reply #18 on: December 08, 2005, 01:20:41 PM »
I have used set in some programs.
Here is a tricky one.

This function is a generalized error trap. It can "wrap" a function and catch an error if one occurs and will return a nil when an error has occurred.

Like (vla-item colLayers "TEST") should return a the layer object corresponding to the "TEST" layer.

If there isn't a "TEST" layer it will crash.

so

(errortrap (quote (vla-item colLayers "TEST"))) would not crash and just return a nil. It would return the layer object if successfull.

The trick to using the set function is that when you use the vl-catch-all-apply you need to supply a list of arguments to apply the function to.

In this example, the argument that is passed is the result!
In order to do this you need the SET function!

Set is cool.

By the way it was nice to meet you face to face at AU Mark!

Peter Jamtgaard

Code: [Select]
; Standardized Error Trap
(defun ErrorTrap (symFunction / objError result)
 (if (vl-catch-all-error-p
      (setq objError (vl-catch-all-apply
                     '(lambda (X)(set X (eval symFunction)))
                      (list 'result))))
  (progn
   (if DEBUG
    (progn
     (princ "\n")
     (princ (vl-catch-all-error-message objError))
     (princ "\nWhile evaluating the expression: ")
     (princ symfunction)
     (princ "\n")
    )
   )
   nil 
  )
  (if result result 'T)
 )
)



David Bethel

  • Swamp Rat
  • Posts: 656
Re: Is SET a misunderstood function?
« Reply #19 on: December 09, 2005, 11:13:51 AM »
I use set a lot with variable length parameter passing

Code: [Select]
(defun myfoo (input)
  (foreach a input
     (set (read (substr a 1 1))
          (atof (substr a 2)))))

  (setq output '("X24" "Y30" "Z36"))
  (myfoo output)


You can get very imaginative with some additional testing

Code: [Select]
("ALeft" "BRight" "CRight" "DRight" "GL" "HL" "IR" "JR" "LRear" "MCaster" "N8" "QSelfcontained" "RRefrigerator" "S2" "WWorktop" "PValueDesigner" "VAll" "X48" "Y30" "Z36")

-David

R12 Dos - A2K