Author Topic: Newbie to world of (Lost in Stupid Parentheses) errr..(List)  (Read 50480 times)

0 Members and 1 Guest are viewing this topic.

amgirard2003

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« on: November 03, 2003, 05:21:55 PM »
What up everyone?
A newbie here to the world of Lisp and just wanted to check in and let you all know that i am completely lost!!  :?
I've recently been doin a lot of reading and working on a little routine..
I currently don't have the file with me but i'll post it tomorrow from work.
I'm lookin for any help possible..
Would like to keep it as simple as possible as i am a beginner..

Take a look tomorrow for my little routine and any help would be greatly
appreciated..

Thanks,
Andre

SMadsen

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #1 on: November 03, 2003, 05:27:28 PM »
Hello Andre,
Welcome to a world of fellow lispers (well, in here at least)

Looking forward have a look at your routine.

hendie

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #2 on: November 04, 2003, 04:10:31 AM »
welcome Andre,
it's good to have a new face around the forum.

amgirard2003

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #3 on: November 04, 2003, 07:57:27 AM »
Here's my little routine...
I'm looking for comments and suggestions on how i can improve my coding..
If you could e-mail me back at amgirard2003@yahoo.com with a revised copy of my file that would be great...

Code: [Select]
;New Command: Newline
;Purpose is to set linetypes and layer upon selection of a new line
;to be drawn.

;Code in English

;Prompt User: "Select Linetype: Three Phase, Double Phase, Single Phase, Secondary, 600/347V, 120/208V
;Variable Answer = User Input

;if Answer = T (Three Phase) then
;Linetype = Three Phase
;Layer = 612
;Lwpolyline

;if Answer = D (Double Phase) then
;Linetype = Double Phase
;Layer = 612
;Lwpolyline

;if Answer = Si (Single Phase) then
;Linetype = Single Phase
;Layer = 612
;Lwpolyline

;if Answer = E (600/347V) then
;Linetype = Hidden
;Linetype Scale = 0.5
;Layer = 622
;Lwpolyline

;if Answer = F (120/208V) then
;Linetype = Custome Linetype
;Linetype Scale = 0.5
;Layer = 622
;Lwpolyline

;************************************************************
;************************************************************

;Coding

(defun c:nl (/ answer oldblip oldlayer oldplinewidth oldortho)
(initget 1 "Three Double Single seCondary E600 F208")
; Prevents the user from responding to the request by entering only ENTER
(setq answer (getkword "\nSelect Phase: Three/Double/Single/seCondary/E600/F208 <> "))
 oldblip (getvar "blipmode"); set old variable to variable for call back
 oldlayer (getvar "clayer"); set old variable to variable for call back
 oldplinewidth (getvar "plinewid"); set old variable to variable for call back
 oldortho (getvar "osmode"); set old variable to variable oldortho for call back



(cond ((= answer "seCondary") ; Secondary
    (setvar "plinewid" 0.5); set polyline width to 0.5
  (setvar "clayer" "622"); set layer to 622
  (setvar "osmode" 0); set orthomode to off
  (setvar "blipmode" 0); set blips to off
        (princ answer)
      )
     
      ((= answer "Three") ; Three Phase
      (setvar "plinewid" 0); set polyline width to 0
  (setvar "clayer" "612"); set layer to 612
  (setvar "osmode" 0); set orthomode to off
  (setvar "blipmode" 0); set blips to off
(princ answer)
      )

      ((= answer "Double") ; Double Phase
      (setvar "plinewid" 0); set polyline width to 0
  (setvar "clayer" "612"); set layer to 612
  (setvar "osmode" 0); set orthomode to off
  (setvar "blipmode" 0); set blips to off
(princ answer)
      )

      ((= answer "Single") ; Single Phase
      (setvar "plinewid" 0); set polyline width to 0
  (setvar "clayer" "612"); set layer to 612
  (setvar "osmode" 0); set orthomode to off
  (setvar "blipmode" 0); set blips to off
(princ answer)
      )

      ((= answer "E600") ; 600/347V
      (setvar "plinewid" 0); set polyline width to 0
  (setvar "clayer" "622"); set layer to 622
  (setvar "osmode" 0); set orthomode to off
  (setvar "blipmode" 0); set blips to off
(princ answer)
      )

      ((= answer "F208") ; 120/208V
      (setvar "plinewid" 0); set polyline width to 0
  (setvar "clayer" "622"); set layer to 622
  (setvar "osmode" 0); set orthomode to off
  (setvar "blipmode" 0); set blips to off
(princ answer)
      )
)

(princ)


)

SMadsen

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #4 on: November 04, 2003, 08:32:52 AM »
Quote from: amgirard2003
If you could e-mail me back at ...
No way, you asked for it in public, now you're getting the comments in public, too :D

Before suggesting any changes, here are some questions and comments:

- You say that the routine is for changing the linetype, yet I don't see where it changes the current linetype?
- Are you sure that you want to force the user to hit escape in order to exit from the routine without doing changes? INITGET 1 is for very rare cases where input is essential for further processing. It's not for irritating the user.
- You forgot to include the initial oldxxx assignments in a SETQ
- Are you sure you want to force OSMODE and BLIPMODE to 0? If that is the case, why are you saving their current values?? It's not necessary, either, to save the current values of CLAYER and PLINEWID if your intention is that the routine will change them.
- Setting OSMODE and BLIPMODE to 0 within all conditions are unnecessary repetitions.
- If setting OSMODE and BLIPMODE to 0 and leaving them that way is NOT intentional, then you need to include code that restore their values.
- What will happen if the layers are not present in the drawing when using CLAYER to set a layer currently active? (if you include CELTYPE to change the current linetype then the same question applies)

daron

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #5 on: November 04, 2003, 09:34:59 AM »
Also, why are you supplying the answer back to the user when the user knows what he supplied. Also, using the "or" expression for conditions that have the same body results, like single, double and three will help you keep your code short and easier to read. Ex.
Code: [Select]
((or (= answer "Double")
      (= answer "Single")
      (= answer "Three")
 )
(setvar 'clayer 612)
);end condition


That is an example of how to use the "or" expression. Do consider what SMadsen said about existing layers and everything else.

SMadsen

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #6 on: November 04, 2003, 09:40:40 AM »
*smadsen holds a hand for his mouth and whispers discretely, ahem, don't you mean OR, Daron?*

daron

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #7 on: November 04, 2003, 09:42:41 AM »
DOH! I'll go change it. It's early, here. Thank you. I was reading the code that was supplied and thinking to myself that condition 1 and 2 and 3 are all the same, so I put my thoughts down without thinking about what would happen in the code.

amgirard2003

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #8 on: November 04, 2003, 09:54:02 AM »
WO WO WO WO... Hold on horses...
Like i said i'm a NEWBIE.... everything you are tellin me i should do and not do is complete chinese to me... I'm not understanding what you are tellin me.. Remember this is the first time i've ever written any kind of programming code... I know by your experience that you're lookin at this thing and sayin what a joke this is.. I'm lookin for some guidance and to take some small steps.. I don't want to be runnin a mile when i'm not ready for it.

- You say that the routine is for changing the linetype, yet I don't see where it changes the current linetype?

   Well i haven't gotten to that point... i don't know how to use tables to determine if linetypes have been defined or not, and how to create them if there not defined.


- Are you sure that you want to force the user to hit escape in order to exit from the routine without doing changes? INITGET 1 is for very rare cases where input is essential for further processing. It's not for irritating the user.

  I don't understand what you're tellin me with this comment

- You forgot to include the initial oldxxx assignments in a SETQ

  Like the previous comment... don't understand what you're sayin

- Setting OSMODE and BLIPMODE to 0 within all conditions are unnecessary repetitions.

  I understand that i've repeated this part over and over but don't understand code syntax so i don't have to re-itterate the same code over and over


- If setting OSMODE and BLIPMODE to 0 and leaving them that way is NOT intentional, then you need to include code that restore their values.

  I haven't gotten to that part... the routine as you can see is FAR from being done.


- What will happen if the layers are not present in the drawing when using CLAYER to set a layer currently active? (if you include CELTYPE to change the current linetype then the same question applies)

  Again... i know there's error traping that i will have to develop but again don't know how to develop that at this moment..



To finish this off... I don't want anyone to take it in the wrong manner.. Like i said i'm a NEWBIE to the world of programming...
I'm lookin for all the help i can get to help me learn this, As there's no places around where i live that offer courses in LISP..

Thanks for your input.

Andre

P.S- is there any way to add attachments to this forum?




[/b]

Mark

  • Custom Title
  • Seagull
  • Posts: 28685
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #9 on: November 04, 2003, 10:02:16 AM »
Quote
P.S- is there any way to add attachments to this forum?

No, but as a member of TheSwamp you are allowed to use the lilly pond to upload/download files if you wish.
http://theswamp.org/lilly.pond/
TheSwamp.org  (serving the CAD community since 2003)

daron

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #10 on: November 04, 2003, 10:16:04 AM »
Quote from: amgirard2003
everything you are tellin me i should do and not do is complete chinese to me... I'm not understanding what you are tellin me.. Remember this is the first time i've ever written any kind of programming code... I know by your experience that you're lookin at this thing and sayin what a joke this is.. I'm lookin for some guidance and to take some small steps.. I don't want to be runnin a mile when i'm not ready for it.
No need to run a mile. Take what you can now, ask questions about it and come back for more (often). I'm sure there will be plenty of comments your next time around.

Quote
- Are you sure that you want to force the user to hit escape in order to exit from the routine without doing changes? INITGET 1 is for very rare cases where input is essential for further processing. It's not for irritating the user.

  I don't understand what you're tellin me with this comment

1 (bit 0)  Prevents the user from responding to the request by entering only ENTER. There's the help file on initget 1. Now the question: What if the user decides he doesn't want to change anything after invoking this command? Can he hit enter to get out of it clean? You are forcing your user to hit escape to get out of it, which is bad practice.

Quote
- Setting OSMODE and BLIPMODE to 0 within all conditions are unnecessary repetitions.

  I understand that i've repeated this part over and over but don't understand code syntax so i don't have to re-itterate the same code over and over

Instead of changing variables inside each condition, you can change them before the conditional statement, unless they are needing to be changed to different values as a result of the condition. Ex. would be osmode. In some cases you might feel that it's better to give the user nothing but nearest or in other conditions you might want end/int.

Quote
Again... i know there's error traping that i will have to develop but again don't know how to develop that at this moment..



To finish this off... I don't want anyone to take it in the wrong manner.. Like i said i'm a NEWBIE to the world of programming...
I'm lookin for all the help i can get to help me learn this, As there's no places around where i live that offer courses in LISP..

Error trapping? You've got a better start than when I got started. Initget is a good error trapping tool as is cond. As far as places to learn, many of us here will help you get through problems as you ask them.

hendie

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #11 on: November 04, 2003, 10:23:49 AM »
Quote from: amgirard2003
... I know by your experience that you're lookin at this thing and sayin what a joke this is.. I'm lookin for some guidance and to take some small steps..

No  we are not treating this as a joke by any means ~ we all started somewhere (and some of us haven't travelled far from that point yet !)

lets take a step back for a moment. Lay aside the code you have written for the time being. Now what would really be helpful is pseudo-code defining what you want to do step by step.
That will let us see what you are trying to do. Then we can take it a step at a time.
pseudo code is something like:
Quote

prompt use for type of line
get current variables
if line type 1 then
    set these variables
    check for layer and linetype
    do this code
    [/list:u]
    or if line type 2 then
      set those variables
      check for layer and linetype
      do this code
      [/list:u]
      or if line type 3 then
        set those other variables
        check for layer and linetype
        do this code
        [/list:u]
        restore variables
        and exit

get the drift ?

daron

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #12 on: November 04, 2003, 10:32:02 AM »
No offense Hendie, but I thought he did a fairly decent job of pseudo-coding it. Not complete, but what is ever complete in the initial thinking of code? Here's the p-c he originally stated
Quote
;Code in English

;Prompt User: "Select Linetype: Three Phase, Double Phase, Single Phase, Secondary, 600/347V, 120/208V
;Variable Answer = User Input

;if Answer = T (Three Phase) then
;Linetype = Three Phase
;Layer = 612
;Lwpolyline

;if Answer = D (Double Phase) then
;Linetype = Double Phase
;Layer = 612
;Lwpolyline

;if Answer = Si (Single Phase) then
;Linetype = Single Phase
;Layer = 612
;Lwpolyline

;if Answer = E (600/347V) then
;Linetype = Hidden
;Linetype Scale = 0.5
;Layer = 622
;Lwpolyline

;if Answer = F (120/208V) then
;Linetype = Custome Linetype
;Linetype Scale = 0.5
;Layer = 622
;Lwpolyline


It could definately use some updating and complete direction for a finish, but it's better than I ever did when I got started. Heh, I still hate writing that stuff. I feel like I can write the code just as fast as I could write the p-c, most of the time.

hendie

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #13 on: November 04, 2003, 10:38:29 AM »
none taken, it's just that (I thought) I'd read he hadn't got to a few things yet so wondered if there was anything that we should be aware of at this time (just in case)

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9267
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #14 on: November 04, 2003, 11:02:36 AM »
I have a sugestion; Why dont you comment your code as well as you can. Read, evaluate, and look up as much as you can. Comment everything you can as we will tell you if your right/wrong/close/ etc. and offer help from there.  We are here to teach you. Test everyline and ask any questions you have. We are not here to pick on you, we are here to give you the oppertunity to create the best code out there.
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--