0
$\begingroup$

I am looking to do a generalist job. For that I need to know the number of parameters. For now I'm using a true/false:

ExtrudeTranform3[sketch_, vector_, 
  transfo_, {tx_, ty_, tz_}, {rg_, rx_, ry_, rz_}] :=
 If[transfo = true, 
  GeometricTransformation[RegionProduct[skech, line], 
   Composition[TranlationTranform[{tx, ty, tz}], 
    RotationTransform[rg, {rx, ry, rz}]]], 
  GeometricTransformation[Extrude[sketch, vector]]]

But I would like to know how to count the number of parameters in order to perform, for example, the transformation here only if the parameters tx, ty, tz, tg, rx, ry, rz are entered by the user. Thanks in advance

$\endgroup$

2 Answers 2

1
$\begingroup$

First, this code doesn't work as is because of the misspellings and missing data. It would be more helpful if you provided code that was at least syntactically correct.

Second, transfo = true is setting the value of the symbol transfo to the symbol true, and since this isn't a boolean value, the If will return unevaluated (since you didn't provide a fourth argument). I assume that what you wanted was If[transfo == True,...], or more simply If[transfo,...].

I don't understand how having transfo be True or False will help you "know the number of parameters", so I don't know how to help you there. But, if you want to know "if the parameters tx, ty, tz, tg, rx, ry, rz are entered by the user", that's what pattern matching on arguments gives you. Your function won't evaluate if the user-supplied arguments don't match the pattern of your definition. Since your particular argument pattern specifies an exact number of arguments, then you'll get this check for free.

$\endgroup$
0
$\begingroup$

To count the numbers of elements in an vector argument you may proceed as:

  1. define a vector argument by a pattern: vec__
  2. Inside the function user Length[vec] to get the numbers of elements.

Here is an example:

f[vec1__, vec2__] := Print[StringForm[
   "Number of params in first argument: ``,  Number pf params in \
second argument: ``", Length[vec1], Length[vec2]]]

f[{a, b}, {a, b, c}]
  
Number of params in first argument: 2,  Number pf params in second argument: 3
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.