Author Topic: Global variable as next input  (Read 3334 times)

0 Members and 1 Guest are viewing this topic.

Adesu

  • Guest
Global variable as next input
« on: December 20, 2006, 08:33:41 PM »
Hi Alls,
Here my code simple,this code if you load it, I first set "last_num" variable to set to "nil",then opt variable would ask,with default 36,so I put "55".
if user reload again,the "opt" variable should display last_num with 55,but this fact it's can not display last opt variable.
Does anyone know how to revised that code,thaks for your help.

Code: [Select]
(defun c:test (/ opt)
  (setq last_num '())
  (if
    lnum
    (setq last_num 36)
    )                                    ; if
  (setq opt
(getreal
   (strcat "\nEnter number of segment < "
   (itoa last_num)
   " >: ")))             
  (if
    (= opt nil)
    (setq opt 36)
    (progn
      (setq opt (fix opt))
      (setq last_num opt)
      )                                   ; progn
    )                                     ; repeat
  (princ)
  )

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Global variable as next input
« Reply #1 on: December 20, 2006, 08:41:42 PM »
Like this?
Code: [Select]
(defun c:test (/ opt)
  (or last_num
      (setq last_num 36)
      )                                    ; if
  (setq opt
(getint
   (strcat "\nEnter number of segment < "
   (itoa last_num)
   " >: ")))             
  (if (not opt)
    last_num
    (setq last_num opt)
    )                                     ; if
  (print last_num)
  (princ)
  )

Adesu

  • Guest
Re: Global variable as next input
« Reply #2 on: December 20, 2006, 08:49:44 PM »
Hi Jeff,
It's great and thanks for your quick reply.

Like this?
Code: [Select]
(defun c:test (/ opt)
  (or last_num
      (setq last_num 36)
      )                                    ; if
  (setq opt
(getint
   (strcat "\nEnter number of segment < "
   (itoa last_num)
   " >: ")))             
  (if (not opt)
    last_num
    (setq last_num opt)
    )                                     ; if
  (print last_num)
  (princ)
  )

Patrick_35

  • Guest
Re: Global variable as next input
« Reply #3 on: December 21, 2006, 04:35:27 AM »
Hi

I don't understand this logic

Code: [Select]
(or last_num
      (setq last_num 36)
      )

It seems to to me that if would be more suitable than one or ?

@+

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Global variable as next input
« Reply #4 on: December 21, 2006, 04:40:24 AM »
Nope .. that is perfectly elegant :-)
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Global variable as next input
« Reply #5 on: December 21, 2006, 05:53:25 PM »
I use it alot. When you format the code it will stay on one line.:)
Code: [Select]
(or last_num (setq last_num 36))as opposed to
Code: [Select]
(if last_num
  (setq last_num 36)
)
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.

LE

  • Guest
Re: Global variable as next input
« Reply #6 on: December 21, 2006, 06:10:07 PM »
I always liked the:

Code: [Select]
(if (not tmp) (setq tmp "value"))

or

Code: [Select]
(setq msg (cond (msg)
("Move")))

(setq msg (cond (msg)
("Rotate")))

(setq msg (cond (msg)
("Copy")))

(setq msg "Stretch") ;; set

(setq msg nil) ;; reset

The:

Code: [Select]
(or ... ...)

Use it, but never liked it...

LE

  • Guest
Re: Global variable as next input
« Reply #7 on: December 21, 2006, 06:28:14 PM »
also... before passing the default value to another variable... it can verify for example the var type output, and do the appropriate... I think

ie, making sure it is a string

Code: [Select]
(setq msg (cond ((= (type msg) 'str) msg)
("Move")))

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Global variable as next input
« Reply #8 on: December 21, 2006, 07:08:55 PM »
Luis, I guess I got in the habit of using (or ... ...) for simple checks wasy back when I didn'k tupe tooo wel. (Hmmm, maybe that's why I still use it)
This:
Code: [Select]
(or tmp (setq tmp "value"))
is shorter (i.e. - less typing) than:
Code: [Select]
(if (not tmp) (setq tmp "value"))
yep, I'm lazy at heart.....that's one reason I started writing programs, I couldn't stand performing the same exact steps everytime time I wanted to create such & such. Huh, I said, I could write a slick little proggy to do this for me and then I could just watch the computer work.  :-)

LE

  • Guest
Re: Global variable as next input
« Reply #9 on: December 21, 2006, 07:18:40 PM »
yep, I'm lazy at heart.....that's one reason I started writing programs, I couldn't stand performing the same exact steps everytime time I wanted to create such & such. Huh, I said, I could write a slick little proggy to do this for me and then I could just watch the computer work.  :-)

similar situation Jeff.... :)

Patrick_35

  • Guest
Re: Global variable as next input
« Reply #10 on: December 22, 2006, 03:11:29 AM »
Ok, I understood
Thanks everybody  :-)

@+