discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

children()

ME
Mark Erbaugh
Mon, Nov 11, 2024 4:37 AM

Hello,

I am new to OpenSCAD and functional programming, so bear with me.

Is it possible to pass a parameter to a module using the children() feature?

module test(which)
{
echo(which);
}

module main()
{
children(0)(1);  // error here
children(0,2);    // and here
}

main()
{
test();
}

This doesn’t work, but should illustrate what I’m trying to do. An alternate approach that does work, but isn’t quite what I want:

module test(which)
{
echo(which);
}

module main()
{
children(0);
children(1);
}

main()
{
test(0);
test(1);
}

Thanks,
Mark

Hello, I am new to OpenSCAD and functional programming, so bear with me. Is it possible to pass a parameter to a module using the children() feature? module test(which) { echo(which); } module main() { children(0)(1); // error here children(0,2); // and here } main() { test(); } This doesn’t work, but should illustrate what I’m trying to do. An alternate approach that does work, but isn’t quite what I want: module test(which) { echo(which); } module main() { children(0); children(1); } main() { test(0); test(1); } Thanks, Mark
JB
Jordan Brown
Mon, Nov 11, 2024 4:52 AM

On 11/10/2024 8:37 PM, Mark Erbaugh via Discuss wrote:

Is it possible to pass a parameter to a module using the children()
feature?

Not directly, because the things that children() processes are module
invocations rather than modules per se.  There is, however, an indirect
mechanismsusing $ variables.

module foo() {
echo($i);
}

module bar() {
children($i = 1);
children($i = 2);
}

bar() {
foo();
}

On 11/10/2024 8:37 PM, Mark Erbaugh via Discuss wrote: > Is it possible to pass a parameter to a module using the children() > feature? Not directly, because the things that children() processes are module invocations rather than modules per se.  There is, however, an indirect mechanismsusing $ variables. module foo() { echo($i); } module bar() { children($i = 1); children($i = 2); } bar() { foo(); }
ME
Mark Erbaugh
Mon, Nov 11, 2024 11:10 AM

Thanks for the tip.  I expanded your example slightly to do what I needed.

module foo() {
if ($i == 1)
echo("This is foo() level 1.");
else
echo("This is foo() not level one.");
}

module bar() {
echo(str("bar ", $i));
}

module main() {
children(0, $i = 1);
children(0, $i = 2);
children(1, $i = 1);
children(1, $i = 2);
}

main() {
foo();
bar();
}

Thanks for the tip. I expanded your example slightly to do what I needed. module foo() { if ($i == 1) echo("This is foo() level 1."); else echo("This is foo() not level one."); } module bar() { echo(str("bar ", $i)); } module main() { children(0, $i = 1); children(0, $i = 2); children(1, $i = 1); children(1, $i = 2); } main() { foo(); bar(); }