Author Topic: Please teaching me .  (Read 7627 times)

0 Members and 1 Guest are viewing this topic.

AIberto

  • Guest
Please teaching me .
« on: July 17, 2015, 01:57:03 AM »
Dear all Lisp Master

Please patience to check  these two codes .please teaching me where is not reasonable .

Grammatical Structure reasonable ?
Local variables used are correct ?

Thanks very much!

Example 1
Code - Auto/Visual Lisp: [Select]
  1. (defun main (/ v1 v3 subfun1 subfun2)
  2.   (setq v1 (......))
  3.   (defun subfun1(/ v2)
  4.                 (setq v2 (.....))
  5.                 (setq v3 (......))
  6.     ......
  7.   );;end_defun_subfun1
  8.   (defun subfun2(/ subb v4 v5 v6)
  9.     (defun subb(/ a b c)
  10.       (setq a (...))
  11.                   (setq b (...))
  12.                   (setq c (*(atoi v6) 10))
  13.     );;end_defun_subb
  14.     (setq v4 (.....))
  15.     (setq v5 (*(atoi v3) 13))
  16.     (setq v6 (.....))
  17.     (subb)
  18.   );;end_defun_subfun2
  19. );;end_defun_main
  20.  

Example 2
Code - Auto/Visual Lisp: [Select]
  1. (defun main (/ v1 v3 subfun1 subfun2 subb)
  2.   (setq v1 (......))
  3.   (defun subfun1(/ v2)
  4.     (setq v2 (.....))
  5.     (setq v3 (......))
  6.     ......
  7.   );;end_defun_subfun1
  8.   (defun subfun2(/  v4 v5 v6)
  9.     (setq v4 (.....))
  10.     (setq v5 (*(atoi v3) 13))
  11.     (setq v6 (.....))
  12.     (subb)
  13.   );;end_defun_subfun2
  14.   (defun subb(/ a b c)
  15.     (setq a (...))
  16.     (setq b (...))
  17.     (setq c (*(atoi v6) 10))
  18.   );;end_defun_subb
  19. );;end_defun_main
  20.  
« Last Edit: July 17, 2015, 02:19:21 AM by AIberto »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Please teaching me .
« Reply #1 on: July 17, 2015, 02:56:30 AM »
I don't qualify as a master, but I'll comment anyway.
Where/how are you calling the nested functions?

The construction looks fine at first glance.

Keep in mind that 'form follows functionality'
... There is no "ideal" structure as such because the code design depends on what problem you are trying to solve.

Personally I prefer to keep my code modular; that is, use lots of smaller functions rather than one big one.
I find that this makes testing easier and helps to simplify changes to the code.

Something that a lot of people forget is to document the function.
NOT write comments every second line but rather explain the purpose of the function, the parameter types and the expected input and output.
Here's an example of a function signature that explains at a glance the purpose of the function. This becomes important when you re-visit the code later.
http://www.theswamp.org/index.php?topic=49771.msg549351#msg549351


Regards,

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.

AIberto

  • Guest
Re: Please teaching me .
« Reply #2 on: July 17, 2015, 03:26:18 AM »
I want know Local variable definition is reasonable ?  ??? yes or no.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Please teaching me .
« Reply #3 on: July 17, 2015, 03:52:03 AM »

As I said,
'The construction looks fine at first glance.'
the V6 variable is the only one that I had to look at twice :)


Something that will make your life easier :
Prefix ALL your nested functions with an underscore
eg: _subb

Some projects I will also prefix variable with recognisable characters.
This helps when you're dealing with 1000+ lines of code that share variables.
 




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.

AIberto

  • Guest
Re: Please teaching me .
« Reply #4 on: July 17, 2015, 04:22:17 AM »

As I said,
'The construction looks fine at first glance.'
the V6 variable is the only one that I had to look at twice :)


Something that will make your life easier :
Prefix ALL your nested functions with an underscore
eg: _subb

Some projects I will also prefix variable with recognisable characters.
This helps when you're dealing with 1000+ lines of code that share variables.

Thank you kerry.

Yes ,use V6 variable  twice,  This is a problem?






« Last Edit: July 17, 2015, 04:40:16 AM by AIberto »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Please teaching me .
« Reply #5 on: July 17, 2015, 04:31:14 AM »
No, not a problem.
As I said,
'The construction looks fine at first glance.'

trivia:
Did you know that you could ( if you wanted to do so) just have all the variables listed in the main ? ..
But I prefer the way you've done it, declaring the variables for each nested function.
« Last Edit: July 17, 2015, 04:35:24 AM by Kerry »
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.

AIberto

  • Guest
Re: Please teaching me .
« Reply #6 on: July 17, 2015, 04:41:54 AM »
eg.
 func1 need  variable  "current_time ", so  I put "current_time"  in main function local variables list.
 not in get_time function local variables list.

 This is a problem?

Code - Auto/Visual Lisp: [Select]
  1. (defun main (/ get_time func1  current_time )
  2.  ;; func1 need  variable  "current_time ", so  I put "current_time"  in main function local variables list
  3. (defun get_time (/ tm)
  4.   (if (and (null *itime*) (setq tm (LM:InternetTime "YYYYMODD")))
  5.     (progn
  6.           (setq Current_time (LM:InternetTime "YYYYMODD"))
  7.           (setq ju_time (DTOJ (atof tm)))        
  8.     );end_progn
  9.     (progn
  10.           (setq Current_time (thedate (getvar "cdate") ""))
  11.           (setq ju_time (DTOJ (atof (thedate (getvar "cdate") ""))))
  12.     );end_progn
  13.   );;end_if
  14. );end_defun
  15.  
  16. ..........
  17. ..........
  18.  
  19. (defun func1()
  20. (get_time)
  21. (if (= Current_time .................);;(need function "get_time" 's variable "current_time )
  22. ......
  23. ......
  24. );;end_defun
  25.  
« Last Edit: July 17, 2015, 04:53:32 AM by AIberto »

AIberto

  • Guest
Re: Please teaching me .
« Reply #7 on: July 17, 2015, 05:00:03 AM »
trivia:
Did you know that you could ( if you wanted to do so) just have all the variables listed in the main ? ..
But I prefer the way you've done it, declaring the variables for each nested function.

Hi kerry .

Example 1 and Example 2 ,  Which do you prefer ?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Please teaching me .
« Reply #8 on: July 17, 2015, 05:06:15 AM »
I prefer Example 1.

I recall reading something years ago that suggested that nested functions in lisp were slower than un-nested functions.
My testing at that time could not determine a discernable difference.

Regards,

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.

AIberto

  • Guest
Re: Please teaching me .
« Reply #9 on: July 17, 2015, 05:16:00 AM »
I prefer Example 1.

 nested functions in lisp were slower than un-nested functions.

Regards,

My understanding is
un-nested functions loaded in memory . other functions can call it.
After the end of the main function. nested functions will unloading and release . not in memory. and other functions can not call

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Please teaching me .
« Reply #10 on: July 17, 2015, 05:29:18 AM »
Yes,
and what happens when you run the routine again ??
Very few people actually know the exact mechanism used.



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.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Please teaching me .
« Reply #11 on: July 17, 2015, 05:33:39 AM »
I prefer example 3 (see below).
In many code samples on this forum you will find nested functions. But there are some arguments against this practice:
  • As Kerry mentions: nested functions will make the code slower. Every time the main function is entered the nested functions will be redefined.
  • Unnested functions can be reused by other functions allowing for a modular coding style.
  • It is easier to debug unnested functions.
  • Related to the previous: Nested functions can easily lead to spaghetti code.

EXAMPLE 3:
Code: [Select]
(defun fun1 (a0 / v0)
  (setq a0 ...)
  ...
  (setq v0 ...)
  ...
  v0
)

(defun fun2 (a0 / v0 v1 v2)
  (setq v0 ...)
  (setq v1 (* (atoi a0) 13))
  (setq v2 (fun3 v2))
  ...
  v2
)

(defun fun3 (a0 / v0 v1 v2)
  (setq v0 ...)
  (setq v1 ...)
  (setq v2 (* (atoi a0) 10))
  ...
  v2
)

(defun main ( / v0 v1)
  (setq v0 ...)
  (setq v1 (fun2 v0))
  ...
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Please teaching me .
« Reply #12 on: July 17, 2015, 05:42:09 AM »
Hi Roy,
The issue I've noticed with non-nested functions in code I've reviewed is that global variables are not treated findly and the scope of variables usually becomes an issue.
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.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Please teaching me .
« Reply #13 on: July 17, 2015, 06:55:47 AM »
Hi Roy,
The issue I've noticed with non-nested functions in code I've reviewed is that global variables are not treated findly and the scope of variables usually becomes an issue.
Do you mean global variables used by non-nested functions as opposed to variables within the scope of a main function that are (also) used by its nested functions?

77077

  • Guest
Re: Please teaching me .
« Reply #14 on: July 17, 2015, 06:55:56 AM »
I prefer example 3 (see below).
In many code samples on this forum you will find nested functions. But there are some arguments against this practice:
  • As Kerry mentions: nested functions will make the code slower. Every time the main function is entered the nested functions will be redefined.
  • Unnested functions can be reused by other functions allowing for a modular coding style.
  • It is easier to debug unnested functions.
  • Related to the previous: Nested functions can easily lead to spaghetti code.

EXAMPLE 3:
Code: [Select]
(defun fun1 (a0 / v0)
  (setq a0 ...)
  ...
  (setq v0 ...)
  ...
  v0
)

(defun fun2 (a0 / v0 v1 v2)
  (setq v0 ...)
  (setq v1 (* (atoi a0) 13))
  (setq v2 (fun3 v2))
  ...
  v2
)

(defun fun3 (a0 / v0 v1 v2)
  (setq v0 ...)
  (setq v1 ...)
  (setq v2 (* (atoi a0) 10))
  ...
  v2
)

(defun main ( / v0 v1)
  (setq v0 ...)
  (setq v1 (fun2 v0))
  ...
)

ROY
formal parameter & actual parameter ?
Not for beginners ,,,,,



roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Please teaching me .
« Reply #15 on: July 17, 2015, 07:03:37 AM »
ROY
formal parameter & actual parameter ?
Not for beginners ,,,,,
If you mean that a function with arguments is too hard to understand for a beginner, and I think that is what you mean, I disagree.

AIberto

  • Guest
Re: Please teaching me .
« Reply #16 on: July 17, 2015, 09:42:55 AM »
I prefer example 3 (see below).
In many code samples on this forum you will find nested functions. But there are some arguments against this practice:
  • As Kerry mentions: nested functions will make the code slower. Every time the main function is entered the nested functions will be redefined.
  • Unnested functions can be reused by other functions allowing for a modular coding style.
  • It is easier to debug unnested functions.
  • Related to the previous: Nested functions can easily lead to spaghetti code.

EXAMPLE 3:
Code: [Select]
(defun fun1 (a0 / v0)
  (setq a0 ...)
  ...
  (setq v0 ...)
  ...
  v0
)

(defun fun2 (a0 / v0 v1 v2)
  (setq v0 ...)
  (setq v1 (* (atoi a0) 13))
  (setq v2 (fun3 v2))
  ...
  v2
)

(defun fun3 (a0 / v0 v1 v2)
  (setq v0 ...)
  (setq v1 ...)
  (setq v2 (* (atoi a0) 10))
  ...
  v2
)

(defun main ( / v0 v1)
  (setq v0 ...)
  (setq v1 (fun2 v0))
  ...
)


Hi roy
So many repeated variable name . Why ?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Please teaching me .
« Reply #17 on: July 17, 2015, 02:54:01 PM »
So many repeated variable name . Why ?
Since all functions in Example 3 are independent functions there is no reason why the same argument and variable names shouldn't be reused. This practice is in fact not uncommon. Examples of some frequently used variable names in Lisp code: i, lst, obj and str.

AIberto

  • Guest
Re: Please teaching me .
« Reply #18 on: July 17, 2015, 09:08:15 PM »
So many repeated variable name . Why ?
Since all functions in Example 3 are independent functions there is no reason why the same argument and variable names shouldn't be reused. This practice is in fact not uncommon. Examples of some frequently used variable names in Lisp code: i, lst, obj and str.


Hi roy
Yes,you are right. The variable name will rarely . But how make function with arguments
This e.g at #6

How make function "get_time"  with arguments ?
Code - Auto/Visual Lisp: [Select]
  1. (defun main (/ get_time func1  current_time )
  2.  ;; func1 need  variable  "current_time ", so  I put "current_time"  in main function local variables list
  3. (defun get_time (/ tm)
  4.   (if (and (null *itime*) (setq tm (LM:InternetTime "YYYYMODD")))
  5.     (progn
  6.           (setq Current_time (LM:InternetTime "YYYYMODD"))
  7.           (setq ju_time (DTOJ (atof tm)))        
  8.     );end_progn
  9.     (progn
  10.           (setq Current_time (thedate (getvar "cdate") ""))
  11.           (setq ju_time (DTOJ (atof (thedate (getvar "cdate") ""))))
  12.     );end_progn
  13.   );;end_if
  14. );end_defun
  15.  
  16. ..........
  17. ..........
  18.  
  19. (defun func1()
  20. (get_time)
  21. (if (= Current_time .................);;(need function "get_time" 's variable "current_time )
  22. ......
  23. ......
  24. );;end_defun
  25.  
  26.  

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Please teaching me .
« Reply #19 on: July 18, 2015, 06:16:54 AM »
I don't understand your get_time function. Notably the handling of *itime* is confusing.
But generally speaking not all functions require arguments:
Code: [Select]
; (Add_2_Numbers 3 6) => 9
(defun Add_2_Numbers (num1 num2)
  (+ num1 num2)
)

; (Pi_Divided_By_2) => 1.5708
(defun Pi_Divided_By_2 ()
  (/ pi 2.0)
)

; (Get_DateDay) => 2457222
(defun Get_DateDay ()
  (fix (getvar 'date))
)

AIberto

  • Guest
Re: Please teaching me .
« Reply #20 on: July 18, 2015, 06:27:16 AM »
Hi roy

Code - Auto/Visual Lisp: [Select]
  1. (defun get_time (/ tm)
  2.   (if (setq tm (LM:InternetTime "YYYYMODD"))
  3.     (progn
  4.           (setq Current_time (LM:InternetTime "YYYYMODD"))
  5.           (setq ju_time (DTOJ (atof tm)))        
  6.     );end_progn
  7.     (progn
  8.           (setq Current_time (thedate (getvar "cdate") ""))
  9.           (setq ju_time (DTOJ (atof (thedate (getvar "cdate") ""))))
  10.     );end_progn
  11.   );;end_if
  12. );end_defun
  13.  

How make this function returns two value ? "current_time" and " ju_time"

returns a list ?  and if other function need "current_time" or "ju_time" ,so use "(car list)" or "(cadr list)"  ?? That is right ?

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Please teaching me .
« Reply #21 on: July 18, 2015, 06:35:28 AM »
You can either return the two values in a list:

Code - Auto/Visual Lisp: [Select]
  1. (defun get_time ( / tmp )
  2.     (if (setq tmp (LM:internettime "YYYYMODD"))
  3.         (list tmp (dtoj (atoi tmp)))
  4.         (list (itoa (fix (getvar 'cdate))) (fix (getvar 'date)))
  5.     )
  6. )

...or pass the function two quoted symbols to which the values will be assigned:

Code - Auto/Visual Lisp: [Select]
  1. (defun get_time ( outsym1 outsym2 )
  2.     (if (set outsym1 (LM:internettime "YYYYMODD"))
  3.         (set outsym2 (dtoj (atoi (eval outsym1))))
  4.         (progn
  5.             (set outsym1 (itoa (fix (getvar 'cdate))))
  6.             (set outsym2 (fix (getvar 'date)))
  7.         )
  8.     )
  9.     nil
  10. )
Code - Auto/Visual Lisp: [Select]
  1. (get_time 'mydate 'myjuliandate)

For the latter, note that the supplied symbols cannot be the same as the symbols used to represent the function parameters, else the values will remain local to the function.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Please teaching me .
« Reply #22 on: July 18, 2015, 06:41:40 AM »
@ AIberto:
I think you should think about creating a function that returns a single value. I would advise that the output be a number in the same format as the DATE variable. It would make the most sense to revise Lee's LM:InternetTime for this purpose...

Tip: Take a good look at your code. You are unnecessarily calling functions twice.

AIberto

  • Guest
Re: Please teaching me .
« Reply #23 on: July 19, 2015, 05:21:17 AM »
@ AIberto:
I think you should think about creating a function that returns a single value. I would advise that the output be a number in the same format as the DATE variable. It would make the most sense to revise Lee's LM:InternetTime for this purpose...

Tip: Take a good look at your code. You are unnecessarily calling functions twice.

Hi roy . Thank you

Oops!  I have noticed that calling functions twice. 
 (setq tm (LM:InternetTime "YYYYMODD"))  and  (setq Current_time (LM:InternetTime "YYYYMODD"))

Thank you for your advice .



AIberto

  • Guest
Re: Please teaching me .
« Reply #24 on: July 19, 2015, 05:32:19 AM »
You can either return the two values in a list:

Code - Auto/Visual Lisp: [Select]
  1. (defun get_time ( / tmp )
  2.     (if (setq tmp (LM:internettime "YYYYMODD"))
  3.         (list tmp (dtoj (atoi tmp)))
  4.         (list (itoa (fix (getvar 'cdate))) (fix (getvar 'date)))
  5.     )
  6. )

...or pass the function two quoted symbols to which the values will be assigned:

Code - Auto/Visual Lisp: [Select]
  1. (defun get_time ( outsym1 outsym2 )
  2.     (if (set outsym1 (LM:internettime "YYYYMODD"))
  3.         (set outsym2 (dtoj (atoi (eval outsym1))))
  4.         (progn
  5.             (set outsym1 (itoa (fix (getvar 'cdate))))
  6.             (set outsym2 (fix (getvar 'date)))
  7.         )
  8.     )
  9.     nil
  10. )
Code - Auto/Visual Lisp: [Select]
  1. (get_time 'mydate 'myjuliandate)


Lee ,  Useful !  It will take a little time to study .  Many thanks !

Quote
For the latter, note that the supplied symbols cannot be the same as the symbols used to represent the function parameters, else the values will remain local to the function.

Lee ,you mean can call this function like this : (get_time 'mydate 'myjuliandate) or (get_time 'md  'mj)  ,But can't be like this : ( get_time  'outsym1  'outsym2 ) , yes or no ?
« Last Edit: July 19, 2015, 06:00:47 AM by AIberto »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Please teaching me .
« Reply #25 on: July 19, 2015, 06:01:22 AM »
Quote
For the latter, note that the supplied symbols cannot be the same as the symbols used to represent the function parameters, else the values will remain local to the function.
I can't understand. Can you specifically talk about it?  or  give me an example ? Thanks.

Observe:

Code - Auto/Visual Lisp: [Select]
  1. _$ (defun foo ( a b ) (set a 1) (set b 2) (princ))
  2. FOO
  3. _$ (foo 'c 'd)
  4. _$ c
  5. 1
  6. _$ d
  7. 2
  8. _$ (foo 'a 'b)
  9. _$ a
  10. nil
  11. _$ b
  12. nil

AIberto

  • Guest
Re: Please teaching me .
« Reply #26 on: July 19, 2015, 06:05:45 AM »
Quote
For the latter, note that the supplied symbols cannot be the same as the symbols used to represent the function parameters, else the values will remain local to the function.
I can't understand. Can you specifically talk about it?  or  give me an example ? Thanks.

Observe:

Code - Auto/Visual Lisp: [Select]
  1. _$ (defun foo ( a b ) (set a 1) (set b 2) (princ))
  2. FOO
  3. _$ (foo 'c 'd)
  4. _$ c
  5. 1
  6. _$ d
  7. 2
  8. _$ (foo 'a 'b)
  9. _$ a
  10. nil
  11. _$ b
  12. nil


Lee, Thank you , You reply so quickly . I have already modified previous post . I understand .

DuanJinHui

  • Guest
Re: Please teaching me .
« Reply #27 on: July 19, 2015, 11:01:51 AM »

...or pass the function two quoted symbols to which the values will be assigned:

Code - Auto/Visual Lisp: [Select]
  1. (defun get_time ( outsym1 outsym2 )
  2.     (if (set outsym1 (LM:internettime "YYYYMODD"))
  3.         (set outsym2 (dtoj (atoi (eval outsym1))))
  4.         (progn
  5.             (set outsym1 (itoa (fix (getvar 'cdate))))
  6.             (set outsym2 (fix (getvar 'date)))
  7.         )
  8.     )
  9.     nil
  10. )


Lee, Why use "set" rather than "setq" ?

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Please teaching me .
« Reply #28 on: July 19, 2015, 11:29:41 AM »

...or pass the function two quoted symbols to which the values will be assigned:

Code - Auto/Visual Lisp: [Select]
  1. (defun get_time ( outsym1 outsym2 )
  2.     (if (set outsym1 (LM:internettime "YYYYMODD"))
  3.         (set outsym2 (dtoj (atoi (eval outsym1))))
  4.         (progn
  5.             (set outsym1 (itoa (fix (getvar 'cdate))))
  6.             (set outsym2 (fix (getvar 'date)))
  7.         )
  8.     )
  9.     nil
  10. )


Lee, Why use "set" rather than "setq" ?

Because I require both arguments supplied to the set function to be evaluated: the first argument yields the symbol to which the value should be assigned (that is, the quoted symbol supplied as an argument to the 'get_time' function); the second argument yields the value (as per setq).

If setq were used, the first argument would not be evaluated and the corresponding value would be assigned to the 'outsym1' or 'outsym2' symbols.

Observe:
Code - Auto/Visual Lisp: [Select]
  1. _$ (setq a 'b)
  2. B
  3. _$ (set a 1)
  4. 1
  5. _$ a
  6. B
  7. _$ b
  8. 1
« Last Edit: July 19, 2015, 11:34:18 AM by Lee Mac »

AIberto

  • Guest
Re: Please teaching me .
« Reply #29 on: July 19, 2015, 12:09:56 PM »
Lee, Why use "set" rather than "setq" ?

(setq my-value "my string")

(set (quote my-value) "my string") = (set 'my-value "my string")


Because I require both arguments supplied to the set function to be evaluated: the first argument yields the symbol to which the value should be assigned (that is, the quoted symbol supplied as an argument to the 'get_time' function); the second argument yields the value (as per setq).

If setq were used, the first argument would not be evaluated and the corresponding value would be assigned to the 'outsym1' or 'outsym2' symbols.

Observe:
Code - Auto/Visual Lisp: [Select]
  1. _$ (setq a 'b)
  2. B
  3. _$ (set a 1)
  4. 1
  5. _$ a
  6. B
  7. _$ b
  8. 1

Lee .Good explanation.


I use
Code: [Select]
(defun thedate (date1 sep1 /)
(setq date1 (rtos date1 2 8))
(strcat (substr date1 1 4)
sep1
(substr date1 5 2)
sep1
(substr date1 7 2)
)
)
Code: [Select]
(thedate (getvar "cdate") "")    and  (dtoj (atoi (thedate (getvar "cdate") "")))

you use
Code: [Select]
(itoa (fix (getvar 'cdate)))   and  (fix (getvar 'date))

You are wonderful !!! 
« Last Edit: July 19, 2015, 12:14:36 PM by AIberto »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Please teaching me .
« Reply #30 on: July 19, 2015, 12:16:11 PM »
Thank you AIberto  :-)

DuanJinHui

  • Guest
Re: Please teaching me .
« Reply #31 on: July 19, 2015, 09:07:58 PM »

...or pass the function two quoted symbols to which the values will be assigned:

Code - Auto/Visual Lisp: [Select]
  1. (defun get_time ( outsym1 outsym2 )
  2.     (if (set outsym1 (LM:internettime "YYYYMODD"))
  3.         (set outsym2 (dtoj (atoi (eval outsym1))))
  4.         (progn
  5.             (set outsym1 (itoa (fix (getvar 'cdate))))
  6.             (set outsym2 (fix (getvar 'date)))
  7.         )
  8.     )
  9.     nil
  10. )


Lee, Why use "set" rather than "setq" ?

Because I require both arguments supplied to the set function to be evaluated: the first argument yields the symbol to which the value should be assigned (that is, the quoted symbol supplied as an argument to the 'get_time' function); the second argument yields the value (as per setq).

If setq were used, the first argument would not be evaluated and the corresponding value would be assigned to the 'outsym1' or 'outsym2' symbols.

Observe:
Code - Auto/Visual Lisp: [Select]
  1. _$ (setq a 'b)
  2. B
  3. _$ (set a 1)
  4. 1
  5. _$ a
  6. B
  7. _$ b
  8. 1

@Lee Mac
I really appreciate it.  we’re so proud of you.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Please teaching me .
« Reply #32 on: July 20, 2015, 03:31:58 AM »
You're most welcome DuanJinHui :-)