Author Topic: passing a parameter or argument  (Read 2263 times)

0 Members and 1 Guest are viewing this topic.

cadman6735

  • Guest
passing a parameter or argument
« on: September 05, 2012, 11:57:06 AM »
Not sure of the right term, parameter or argument but can someone explain to me why my code does not work?

I am only studying how to pass a paramete nothing more

Thanks for any advise thrown my way...

Code: [Select]
(defun test (*layout* / )

    (foreach layout (layoutlist)
      (if (eq (strcase layout) (strcase *layout*))
(print "yes " *layout* " is here")
(print "no " *layout* " is not here")
      )
    ) 

  (princ)
)

Jeff H

  • Needs a day job
  • Posts: 6150
Re: passing a parameter or argument
« Reply #1 on: September 05, 2012, 12:08:27 PM »
General programming statement below, but I would think applies to AutoLisp
 
You pass information to a function by means of arguments specified when you invoke it. These arguments need to correspond with parameters that appear in the definition of the function. The arguments that you specify replace the parameters used in the definition of the function when the function executes.
 

ronjonp

  • Needs a day job
  • Posts: 7529
Re: passing a parameter or argument
« Reply #2 on: September 05, 2012, 12:12:41 PM »
If you're looking for a layout name try something like this:
vl-position will return the index if the item is found in the list. If not found it will return NIL.
Code: [Select]
(defun test (*layout*) (vl-position (strcase *layout*) (mapcar 'strcase (layoutlist))))
So we can check with a simple if statement like so
Code: [Select]
(if (test "LAYOUt1")
  (alert "YES")
  (alert "NO")
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: passing a parameter or argument
« Reply #3 on: September 05, 2012, 12:14:13 PM »
You need the strcat function to gather the sting message .

Code: [Select]
(print (strcat "yes " *layout* " is here"))
(print (strcat "no " *layout* " is not here"))

cadman6735

  • Guest
Re: passing a parameter or argument
« Reply #4 on: September 05, 2012, 12:56:13 PM »
Thank you all

Tharwat you solved my mystery for me...  Thank you

ronjonp, thank you for the alternate code...  I was more interested in passing parameters than finding the layout.  But I will come back to your code to explore it further too.

Jeff, is the parameter in the defun  (defun test (*layout* / )?  and the argument in the body?  or the other way around?

Thanks again all

Jeff H

  • Needs a day job
  • Posts: 6150
Re: passing a parameter or argument
« Reply #5 on: September 05, 2012, 02:28:36 PM »
I not familiar with AutoLisp and the docs for defun use wordings which would be better answered by one of the gurus here.
 
But in general a parameter is a special variable used in a function, method, procedure(or whatever the languge calls them) definition.
 
The arguments are what are passed and assigned to the parameters either passing a copy or reference.
 
As a little simple example of a function ADD that adds 2 numbers in pseudocode
 
Function Add(integer x, integer y)
(
return x + y
)
 
the parameters or parameter list is x,y
 
Add(2,4)
2 & 4 are arguments and are assigned to x & y.
So
return (x=2) + (y=4) -- where '=' is an assignment operator.
 
That was a simple dumbed down example as also to take in consideration are you passing a copy of the value, copy of the address, actual reference, etc..

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: passing a parameter or argument
« Reply #6 on: September 06, 2012, 04:13:57 AM »
Jeff's described the concept pretty well. Many programmers (not just Lispers) use the two words interchangeably, since the idea behind both are pretty much the same thing.

Strictly speaking, it's as Jeff indicated: Parameter=definition of input / output variable to a function/procedure/method. Argument=runtime data sent to the function/procedure/method, or if you language allows by-reference parameters it could also include output variables.

Even in C# I see lots of examples calling the Result Buffer parameter when creating a LispFunction by the name of args. In most console programs (even made in C) the command line options are called arguments inside the code. Sometimes you might find a programmer called such thing params instead, but they both mean much the same thing. So it seems there's no strict adherence to the above definitions, it's more like splitting hairs actually.

The issue with your code however (as Tharwat's indicated) is you're passing the wrong pattern of arguments to the print function. The print function's definition states it receives one data parameter (which could be anything) and one optional destination parameter (usually a file handle - else output to command line). Some languages define their equivalents to print to accept multiple data parameters (e.g. Pascal's write/writeln allows multiple arguments, but also has an overloaded version accepting an output file as the first argument). So your code fails because of AutoLisp's definition of the print function, in some other languages you wouldn't need to combine several data variables into one to send to print as a single arg.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.