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

0 Members and 1 Guest are viewing this topic.

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9267
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #30 on: November 04, 2003, 09:19:45 PM »
Correct (sort of. Lets clean those thoughts up a bit. They were good, I just want to make sure you think of it 'this' way.)

A variable is basically a "container" of sorts. A function is a set of processes and  returns a value --A procedure--. When you define a variable you are essentially associating a name that identifies a variable which has a value.

You define a name by using "setq".
-e.g. (setq a 1)

We have just named the value "1" to the name "a".

So theoretically, we can test a value and perform a process --or set of processes-- based on the results.

Taking the information we have just learned, let's create a function that returns a True/False value. We are going to create a procedure that will return either True or False based on the value of a test.  Side note: This procedure will be a procedure you can use over and over again in many programs you create over the years so you should keep track of this procedure. (I have a system that seems to work for me. I keep a file I call my "Utils" file that holds all my finished products and I also keep a "Junk" file for my daily program scratchings. I suggest devising a system of your own and sticking to it.)

I'll start with an easy one so I don't loose you sofar. How about a function to test to see if a layer exists in the drawing?

Start a new drawing and run this line of code in either the command line or the VLIDE and see what it returns.
(tblsearch "layer" "0")

What does it return? How do you think we can make a procedure return either true or false using this function? HINT: Find a function that will return True or False. -e.g. Daron used the "or" function earlier, what task does it preform?
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

hendie

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #31 on: November 05, 2003, 03:54:22 AM »
I don't want to side track anybody or anything but wouldn't this topic be better served in the Teach Me forum ?

amgirard2003

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #32 on: November 05, 2003, 07:44:05 AM »
(tblsearch "layer" "0")
Returns this:
((0 . "LAYER") (2 . "0") (70 . 0) (62 . 7) (6 . "Continuous"))
which in turn means true.. it found a layer that = 0

Using the OR function that Daron had mentioned earlier will check all the variables that are within that function, once it finds a match you then tell the routine where to go from there...

Pseudo Code
(or(tblsearch "layer" "0") ;then go to step 1
    (tblsearch "layer" "1") ;then go to setp 2
    (tblsearch "layer" "2") ;then go to step 3

Is this what you were looking for?
To Hendie's previous message.. if you want to move this to the Teach Me forum i don't have a problem with that..

hendie

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #33 on: November 05, 2003, 08:01:20 AM »
Quote from: amgirard2003
...will check all the variables that are within that function, once it finds a match you then tell the routine where to go from there...

partly correct. ~ it will search within that function for a match
Code: [Select]
(or
   (tblsearch "layer" "0")
   (tblsearch "layer" "1")
   (tblsearch "layer" "2")
)

will return TRUE if any of Layer "0" OR Layer "1" OR layer "2" are found.
i.e. if only layer 0 is present and layer 1 & layer 2 are NOT present it will still return TRUE
and if all 3 layers are present it will return TRUE. it will only return NIL if none of the layers are present

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9267
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #34 on: November 05, 2003, 08:41:11 AM »
Correct. The "or" expression evaluates its arguments and returns True for the first non-nil argument it finds.

If you guys want me to I'll split this thread. But I was only trying to demonstrate Smadsen's and Darons points.

OBTW, My department just got a big job that is kinda fast paced untill the 60% review. (In a couple of days.) So I prolly wont be able to put as much detail into my posts, ok?
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

SMadsen

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #35 on: November 05, 2003, 08:47:09 AM »
Quote from: hendie
... i.e. if only layer 0 is present and layer 1 & layer 2 are NOT present it will still return TRUE
Actually, you wouldn't know if layer 1 and/or layer 2 are present if layer 0 is present (so it might not be a perfect test in every case)   :wink:

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9267
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #36 on: November 05, 2003, 09:07:25 AM »
Alright I want you to do some testing here. Let's set up some variables and give each a value.

(setq a 1 b 2 c nil)

As you can see I set the "c" varialble to hold the value of "nil". (In other words; its "empty") This is for testing purposes only.

Now run these processes:
(or a b c)
(or a)
(or b)
(or c)
(and a b c)
(and a)
(and b)
(and c)
(not a b c)
(not a)
(not b)
(not c)

Let me know if you can come up with a procedure of your own to test to see if a layer exists in the drawing.
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9267
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #37 on: November 05, 2003, 09:08:07 AM »
Quote from: SMadsen
... Actually, you wouldn't know if layer 1 and/or layer 2 are present if layer 0 is present (so it might not be a perfect test in every case)   :wink:
:lol: I was thinking the same thing.
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

amgirard2003

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #38 on: November 05, 2003, 10:07:35 AM »
(or a b c) = True
(or a) = True
(or b) = True
(or c) = nil (false)
(and a b c) = nil (false)
(and a) = True
(and b) = True
(and c) = nil (false)
(not a b c) = too few arguements ( What does this mean? )
(not a) = nil (false)
(not b) = nil (false)
(not c) = True

That's one check to see if it exists
(if
   (tblsearch "layer" "0") ;then go to step 1
*******************************************************
(if (not
        (tblsearch "layer" "0") ; then go to step 1 and create new layer

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9267
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #39 on: November 05, 2003, 10:21:09 AM »
Quote from: amgirard2003
...
(not a b c) = too few arguements ( What does this mean? ) ...


Oh im sorry.  :oops:  I cut and pasted when i shouldnt have. The "not" expression only excepts one argument and we suplied it three.  (Sorry 'bout that, but i guess it was a good test anyways. --It helps you see that you cant use "not" to test all three values. :lol: )

Your getting the idea. But how about taking a steping back and just creating a function to test if the layer exists.  We'll work on a conditional expression in a second.

Here look this over and make sure you understand it.
Code: [Select]
;;;===================================================================;
;;; Layer-p                                                           ;
;;;-------------------------------------------------------------------;
;;; Determines if a layer exists in drawing.                          ;
;;;                                                                   ;
;;; Arguments: Layer - The name of a layer.(In string format.)        ;
;;;                                                                   ;
;;; Returns: "T" if the layer was found, "nil" if not.                ;
;;;                                                                   ;
;;; Date: 10.5.03                                                     ;
;;;===================================================================;
(defun layer-p (layer)
  (and (tblsearch "LAYER" layer)))
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

daron

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #40 on: November 05, 2003, 10:22:22 AM »
Quote from: hendie
I don't want to side track anybody or anything but wouldn't this topic be better served in the Teach Me forum ?

Nope, and I think you understand why now.

Quote from: Se7en
As you can see I set the "c" varialble to hold the value of "nil". (In other words; its "empty")

It is empty, but something has happened to the value of c. Here's a test to run and tell me what your findings are:
(setq a 1 b 2 c nil)
(setq a (append c a b))
(setq a (append c (list a b))

Why does the first append not work and the second append does? The fact that I make a list of value a and b is the obvious answer. The question I want answered is what makes c so special that it doesn't need to be listed?

hendie

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #41 on: November 05, 2003, 10:25:35 AM »
yup

amgirard2003

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #42 on: November 05, 2003, 10:36:54 AM »
O.k... little confused here..
I started a new drawing..
I've gone into Vlide

I've gone into my drawing and created a layer called "andre"

So in the code you've given me

(defun layer-p (layer)
   (and (tblsearch "layer" layer)))

I've replaced layer with andre

(defun layer-p (andre)
   (and (tblsearch "layer" "andre")))

now how do i test this to see if it comes out true?

nivuahc

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #43 on: November 05, 2003, 10:39:08 AM »
tblsearch

nivuahc

  • Guest
Newbie to world of (Lost in Stupid Parentheses) errr..(List)
« Reply #44 on: November 05, 2003, 10:42:38 AM »
(layer-p "andre")

You don't need to change (layer) to (andre) as (layer) is just a name for the required argument (i.e. what layer you're looking for).

Try running this

(layer-p)

and you'll get this from AutoCAD:

Quote
; error: too few arguments