BE
Bob Ewart
Sat, Feb 19, 2022 5:32 PM
I'm working on a set of functions to pretty print arrays.
For example:
include <BOSL2/std.scad> echo(xrot(45));
comes out looking like:
[[1, 0, 0, 0], [0, 0.707107, -0.707107, 0], [0, 0.707107, 0.707107,
0], [0, 0, 0, 1]]
which is hard to read. I have functions to make it look like:
[ [ 1.000000, 0.000000, 0.000000, 0.000000],
[ 0.000000, 0.707107, -1.292893, 0.000000],
[ 0.000000, 0.707107, 0.707107, 0.000000],
[ 0.000000, 0.000000, 0.000000, 1.000000]
which is the way I would format a matrix in code.
I have functions which will display a vector, 2D matrix or 3D matrix and
specify the number of decimal places (f=12.6 above).
I would like to have a function to determine the dimensions of an array:
1=vector, 2=2D matrix and 3 = 3D matrix.
I figured I would drill down with len(array[0]) , len(array[0][0]),
len(array[0][0][0]) until I got "undef"
The user manual says:
a=6; len_a=len(a); echo(a,len_a);
should return:
ECHO: 6, undef
It does NOT, it throws an error
WARNING: len() parameter could not be converted in file...
Is there any other way to determine if the variable is a vector, 2d or
3d array?
There was a request back in 2016 for a way to determine the type of a
variable. I guess that it was never implemented.
--
Bob
Sometimes the heart sees what is invisible to the eye.
I'm working on a set of functions to pretty print arrays.
For example:
include <BOSL2/std.scad> echo(xrot(45));
comes out looking like:
[[1, 0, 0, 0], [0, 0.707107, -0.707107, 0], [0, 0.707107, 0.707107,
0], [0, 0, 0, 1]]
which is hard to read. I have functions to make it look like:
[ [ 1.000000, 0.000000, 0.000000, 0.000000],
[ 0.000000, 0.707107, -1.292893, 0.000000],
[ 0.000000, 0.707107, 0.707107, 0.000000],
[ 0.000000, 0.000000, 0.000000, 1.000000]
which is the way I would format a matrix in code.
I have functions which will display a vector, 2D matrix or 3D matrix and
specify the number of decimal places (f=12.6 above).
I would like to have a function to determine the dimensions of an array:
1=vector, 2=2D matrix and 3 = 3D matrix.
I figured I would drill down with len(array[0]) , len(array[0][0]),
len(array[0][0][0]) until I got "undef"
The user manual says:
a=6; len_a=len(a); echo(a,len_a);
should return:
ECHO: 6, undef
It does NOT, it throws an error
WARNING: len() parameter could not be converted in file...
Is there any other way to determine if the variable is a vector, 2d or
3d array?
There was a request back in 2016 for a way to determine the type of a
variable. I guess that it was never implemented.
--
Bob
Sometimes the heart sees what is invisible to the eye.
- H. Jackson Brown, Jr.
NH
nop head
Sat, Feb 19, 2022 5:36 PM
Yes it is a very annoying warning. You can use is_list() to check if an
item is a list.
On Sat, 19 Feb 2022 at 17:33, Bob Ewart jinnicky@bobsown.net wrote:
I'm working on a set of functions to pretty print arrays.
For example:
include <BOSL2/std.scad> echo(xrot(45));
comes out looking like:
[[1, 0, 0, 0], [0, 0.707107, -0.707107, 0], [0, 0.707107, 0.707107, 0],
[0, 0, 0, 1]]
which is hard to read. I have functions to make it look like:
[ [ 1.000000, 0.000000, 0.000000, 0.000000],
[ 0.000000, 0.707107, -1.292893, 0.000000],
[ 0.000000, 0.707107, 0.707107, 0.000000],
[ 0.000000, 0.000000, 0.000000, 1.000000]
which is the way I would format a matrix in code.
I have functions which will display a vector, 2D matrix or 3D matrix and
specify the number of decimal places (f=12.6 above).
I would like to have a function to determine the dimensions of an array:
1=vector, 2=2D matrix and 3 = 3D matrix.
I figured I would drill down with len(array[0]) , len(array[0][0]),
len(array[0][0][0]) until I got "undef"
The user manual says:
a=6; len_a=len(a); echo(a,len_a);
should return:
ECHO: 6, undef
It does NOT, it throws an error
WARNING: len() parameter could not be converted in file...
Is there any other way to determine if the variable is a vector, 2d or 3d
array?
There was a request back in 2016 for a way to determine the type of a
variable. I guess that it was never implemented.
--
Bob
Sometimes the heart sees what is invisible to the eye.
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
Yes it is a very annoying warning. You can use is_list() to check if an
item is a list.
On Sat, 19 Feb 2022 at 17:33, Bob Ewart <jinnicky@bobsown.net> wrote:
> I'm working on a set of functions to pretty print arrays.
>
> For example:
>
> include <BOSL2/std.scad> echo(xrot(45));
>
> comes out looking like:
>
> [[1, 0, 0, 0], [0, 0.707107, -0.707107, 0], [0, 0.707107, 0.707107, 0],
> [0, 0, 0, 1]]
>
> which is hard to read. I have functions to make it look like:
> [ [ 1.000000, 0.000000, 0.000000, 0.000000],
> [ 0.000000, 0.707107, -1.292893, 0.000000],
> [ 0.000000, 0.707107, 0.707107, 0.000000],
> [ 0.000000, 0.000000, 0.000000, 1.000000]
>
> which is the way I would format a matrix in code.
>
> I have functions which will display a vector, 2D matrix or 3D matrix and
> specify the number of decimal places (f=12.6 above).
>
> I would like to have a function to determine the dimensions of an array:
> 1=vector, 2=2D matrix and 3 = 3D matrix.
>
> I figured I would drill down with len(array[0]) , len(array[0][0]),
> len(array[0][0][0]) until I got "undef"
>
> The user manual says:
>
> a=6; len_a=len(a); echo(a,len_a);
>
> should return:
>
> ECHO: 6, undef
>
> It does NOT, it throws an error
>
> WARNING: len() parameter could not be converted in file...
>
> Is there any other way to determine if the variable is a vector, 2d or 3d
> array?
>
> There was a request back in 2016 for a way to determine the type of a
> variable. I guess that it was never implemented.
>
> --
> Bob
>
> Sometimes the heart sees what is invisible to the eye.
> - H. Jackson Brown, Jr.
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>
AM
Adrian Mariano
Sat, Feb 19, 2022 5:54 PM
Since you're using BOSL2 I suggest first that you take a look at
echo_matrix() and see how close it comes to meeting your needs.
With default options it produces this:
ECHO: "――――――――――"
ECHO: " 1 0 0 0"
ECHO: " 0 0.7071 ‒0.7071 0"
ECHO: " 0 0.7071 0.7071 0"
ECHO: " 0 0 0 1"
ECHO: "――――――――――"
It only handles numeric 2D lists. Note that it is impossible to handle
non-numeric data because there's no way to align it. Getting numeric
data to align was pretty tricky, and I think might be slightly
imperfect. (Maybe it depends on the local font behavior. If there
was a way to force a monospaced font this would be so much easier.)
I think maybe len(3) used to be valid and this changed a few versions
ago. In BOSL2 you can use list_shape() to get the dimensions of
multidimensional arrays. Truly determining if something is a
multidimensional array is complex, because you have to recursively
check all the sublists to see if everything is of a consistent length.
There are some type checking functions like is_list() that you can use
to avoid running len() on non-lists.
On Sat, Feb 19, 2022 at 12:32 PM Bob Ewart jinnicky@bobsown.net wrote:
I'm working on a set of functions to pretty print arrays.
For example:
include <BOSL2/std.scad> echo(xrot(45));
comes out looking like:
[[1, 0, 0, 0], [0, 0.707107, -0.707107, 0], [0, 0.707107, 0.707107, 0], [0, 0, 0, 1]]
which is hard to read. I have functions to make it look like:
[ [ 1.000000, 0.000000, 0.000000, 0.000000],
[ 0.000000, 0.707107, -1.292893, 0.000000],
[ 0.000000, 0.707107, 0.707107, 0.000000],
[ 0.000000, 0.000000, 0.000000, 1.000000]
which is the way I would format a matrix in code.
I have functions which will display a vector, 2D matrix or 3D matrix and specify the number of decimal places (f=12.6 above).
I would like to have a function to determine the dimensions of an array: 1=vector, 2=2D matrix and 3 = 3D matrix.
I figured I would drill down with len(array[0]) , len(array[0][0]), len(array[0][0][0]) until I got "undef"
The user manual says:
a=6; len_a=len(a); echo(a,len_a);
should return:
ECHO: 6, undef
It does NOT, it throws an error
WARNING: len() parameter could not be converted in file...
Is there any other way to determine if the variable is a vector, 2d or 3d array?
There was a request back in 2016 for a way to determine the type of a variable. I guess that it was never implemented.
--
Bob
Sometimes the heart sees what is invisible to the eye.
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
Since you're using BOSL2 I suggest first that you take a look at
echo_matrix() and see how close it comes to meeting your needs.
With default options it produces this:
ECHO: "――――――――――"
ECHO: " 1 0 0 0"
ECHO: " 0 0.7071 ‒0.7071 0"
ECHO: " 0 0.7071 0.7071 0"
ECHO: " 0 0 0 1"
ECHO: "――――――――――"
It only handles numeric 2D lists. Note that it is impossible to handle
non-numeric data because there's no way to align it. Getting numeric
data to align was pretty tricky, and I think might be slightly
imperfect. (Maybe it depends on the local font behavior. If there
was a way to force a monospaced font this would be so much easier.)
I think maybe len(3) used to be valid and this changed a few versions
ago. In BOSL2 you can use list_shape() to get the dimensions of
multidimensional arrays. Truly determining if something is a
multidimensional array is complex, because you have to recursively
check all the sublists to see if everything is of a consistent length.
There are some type checking functions like is_list() that you can use
to avoid running len() on non-lists.
On Sat, Feb 19, 2022 at 12:32 PM Bob Ewart <jinnicky@bobsown.net> wrote:
>
> I'm working on a set of functions to pretty print arrays.
>
> For example:
>
> include <BOSL2/std.scad> echo(xrot(45));
>
> comes out looking like:
>
> [[1, 0, 0, 0], [0, 0.707107, -0.707107, 0], [0, 0.707107, 0.707107, 0], [0, 0, 0, 1]]
>
> which is hard to read. I have functions to make it look like:
>
> [ [ 1.000000, 0.000000, 0.000000, 0.000000],
> [ 0.000000, 0.707107, -1.292893, 0.000000],
> [ 0.000000, 0.707107, 0.707107, 0.000000],
> [ 0.000000, 0.000000, 0.000000, 1.000000]
>
> which is the way I would format a matrix in code.
>
> I have functions which will display a vector, 2D matrix or 3D matrix and specify the number of decimal places (f=12.6 above).
>
> I would like to have a function to determine the dimensions of an array: 1=vector, 2=2D matrix and 3 = 3D matrix.
>
> I figured I would drill down with len(array[0]) , len(array[0][0]), len(array[0][0][0]) until I got "undef"
>
> The user manual says:
>
> a=6; len_a=len(a); echo(a,len_a);
>
> should return:
>
> ECHO: 6, undef
>
> It does NOT, it throws an error
>
> WARNING: len() parameter could not be converted in file...
>
> Is there any other way to determine if the variable is a vector, 2d or 3d array?
>
> There was a request back in 2016 for a way to determine the type of a variable. I guess that it was never implemented.
>
> --
> Bob
>
> Sometimes the heart sees what is invisible to the eye.
> - H. Jackson Brown, Jr.
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
BE
Bob Ewart
Sat, Feb 19, 2022 6:33 PM
Thank you Adrian and Nop Head for your quick responses
"is_list()" solves my current problem
Adrian, I will probably be using BOSL2 a lot, especially for creating
pipe stems. But I wanted a way to display arrays without any other
dependencies.
echo_matrix does the job, but I couldn't copy the output and paste it
into a source file without changes.
The big problem is documentation:
- Where is "is_list()" documented? And are there any other functions
like that?
- if len(6) is going to throw an error, the manual needs to be
changed. I would prefer that the code is changed to reflect the
documentation.
--
Bob
On 2/19/22 12:54, Adrian Mariano wrote:
Since you're using BOSL2 I suggest first that you take a look at
echo_matrix() and see how close it comes to meeting your needs.
With default options it produces this:
ECHO: "――――――――――"
ECHO: " 1 0 0 0"
ECHO: " 0 0.7071 ‒0.7071 0"
ECHO: " 0 0.7071 0.7071 0"
ECHO: " 0 0 0 1"
ECHO: "――――――――――"
It only handles numeric 2D lists. Note that it is impossible to handle
non-numeric data because there's no way to align it. Getting numeric
data to align was pretty tricky, and I think might be slightly
imperfect. (Maybe it depends on the local font behavior. If there
was a way to force a monospaced font this would be so much easier.)
I think maybe len(3) used to be valid and this changed a few versions
ago. In BOSL2 you can use list_shape() to get the dimensions of
multidimensional arrays. Truly determining if something is a
multidimensional array is complex, because you have to recursively
check all the sublists to see if everything is of a consistent length.
There are some type checking functions like is_list() that you can use
to avoid running len() on non-lists.
On Sat, Feb 19, 2022 at 12:32 PM Bob Ewartjinnicky@bobsown.net wrote:
I'm working on a set of functions to pretty print arrays.
For example:
include <BOSL2/std.scad> echo(xrot(45));
comes out looking like:
[[1, 0, 0, 0], [0, 0.707107, -0.707107, 0], [0, 0.707107, 0.707107, 0], [0, 0, 0, 1]]
which is hard to read. I have functions to make it look like:
[ [ 1.000000, 0.000000, 0.000000, 0.000000],
[ 0.000000, 0.707107, -1.292893, 0.000000],
[ 0.000000, 0.707107, 0.707107, 0.000000],
[ 0.000000, 0.000000, 0.000000, 1.000000]
which is the way I would format a matrix in code.
I have functions which will display a vector, 2D matrix or 3D matrix and specify the number of decimal places (f=12.6 above).
I would like to have a function to determine the dimensions of an array: 1=vector, 2=2D matrix and 3 = 3D matrix.
I figured I would drill down with len(array[0]) , len(array[0][0]), len(array[0][0][0]) until I got "undef"
The user manual says:
a=6; len_a=len(a); echo(a,len_a);
should return:
ECHO: 6, undef
It does NOT, it throws an error
WARNING: len() parameter could not be converted in file...
Is there any other way to determine if the variable is a vector, 2d or 3d array?
There was a request back in 2016 for a way to determine the type of a variable. I guess that it was never implemented.
--
Bob
Sometimes the heart sees what is invisible to the eye.
OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org
Thank you Adrian and Nop Head for your quick responses
"is_list()" solves my current problem
Adrian, I will probably be using BOSL2 a lot, especially for creating
pipe stems. But I wanted a way to display arrays without any other
dependencies.
echo_matrix does the job, but I couldn't copy the output and paste it
into a source file without changes.
The big problem is documentation:
* Where is "is_list()" documented? And are there any other functions
like that?
* if len(6) is going to throw an error, the manual needs to be
changed. I would prefer that the code is changed to reflect the
documentation.
--
Bob
On 2/19/22 12:54, Adrian Mariano wrote:
> Since you're using BOSL2 I suggest first that you take a look at
> echo_matrix() and see how close it comes to meeting your needs.
>
> With default options it produces this:
>
> ECHO: "――――――――――"
> ECHO: " 1 0 0 0"
> ECHO: " 0 0.7071 ‒0.7071 0"
> ECHO: " 0 0.7071 0.7071 0"
> ECHO: " 0 0 0 1"
> ECHO: "――――――――――"
>
> It only handles numeric 2D lists. Note that it is impossible to handle
> non-numeric data because there's no way to align it. Getting numeric
> data to align was pretty tricky, and I think might be slightly
> imperfect. (Maybe it depends on the local font behavior. If there
> was a way to force a monospaced font this would be so much easier.)
>
> I think maybe len(3) used to be valid and this changed a few versions
> ago. In BOSL2 you can use list_shape() to get the dimensions of
> multidimensional arrays. Truly determining if something is a
> multidimensional array is complex, because you have to recursively
> check all the sublists to see if everything is of a consistent length.
> There are some type checking functions like is_list() that you can use
> to avoid running len() on non-lists.
>
> On Sat, Feb 19, 2022 at 12:32 PM Bob Ewart<jinnicky@bobsown.net> wrote:
>> I'm working on a set of functions to pretty print arrays.
>>
>> For example:
>>
>> include <BOSL2/std.scad> echo(xrot(45));
>>
>> comes out looking like:
>>
>> [[1, 0, 0, 0], [0, 0.707107, -0.707107, 0], [0, 0.707107, 0.707107, 0], [0, 0, 0, 1]]
>>
>> which is hard to read. I have functions to make it look like:
>>
>> [ [ 1.000000, 0.000000, 0.000000, 0.000000],
>> [ 0.000000, 0.707107, -1.292893, 0.000000],
>> [ 0.000000, 0.707107, 0.707107, 0.000000],
>> [ 0.000000, 0.000000, 0.000000, 1.000000]
>>
>> which is the way I would format a matrix in code.
>>
>> I have functions which will display a vector, 2D matrix or 3D matrix and specify the number of decimal places (f=12.6 above).
>>
>> I would like to have a function to determine the dimensions of an array: 1=vector, 2=2D matrix and 3 = 3D matrix.
>>
>> I figured I would drill down with len(array[0]) , len(array[0][0]), len(array[0][0][0]) until I got "undef"
>>
>> The user manual says:
>>
>> a=6; len_a=len(a); echo(a,len_a);
>>
>> should return:
>>
>> ECHO: 6, undef
>>
>> It does NOT, it throws an error
>>
>> WARNING: len() parameter could not be converted in file...
>>
>> Is there any other way to determine if the variable is a vector, 2d or 3d array?
>>
>> There was a request back in 2016 for a way to determine the type of a variable. I guess that it was never implemented.
>>
>> --
>> Bob
>>
>> Sometimes the heart sees what is invisible to the eye.
>> - H. Jackson Brown, Jr.
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> To unsubscribe send an email todiscuss-leave@lists.openscad.org
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email todiscuss-leave@lists.openscad.org
AM
Adrian Mariano
Sat, Feb 19, 2022 6:44 PM
The documentation is a Wiki that is public. You can fix it if you
find errors. Note that I think with the 2019 version a bunch of
changes were made where things that used to be quiet undef generated
warnings. This change is clearly not going to be reverted. I know
nophead hates it, but overall these changes make it harder to write
buggy code and about 100 times easier to debug code with bugs, because
it used to be that undef would appear where you had your error but
nothing would go visibly wrong until hundreds of lines later in your
program, possibly in a totally different file, and it was a very
painful process to backtrack to try to figure out where the first
invalid operation occurred, and hence where the bad code was located.
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Type_Test_Functions
On Sat, Feb 19, 2022 at 1:34 PM Bob Ewart jinnicky@bobsown.net wrote:
Thank you Adrian and Nop Head for your quick responses
"is_list()" solves my current problem
Adrian, I will probably be using BOSL2 a lot, especially for creating pipe stems. But I wanted a way to display arrays without any other dependencies.
echo_matrix does the job, but I couldn't copy the output and paste it into a source file without changes.
The big problem is documentation:
Where is "is_list()" documented? And are there any other functions like that?
if len(6) is going to throw an error, the manual needs to be changed. I would prefer that the code is changed to reflect the documentation.
--
Bob
On 2/19/22 12:54, Adrian Mariano wrote:
Since you're using BOSL2 I suggest first that you take a look at
echo_matrix() and see how close it comes to meeting your needs.
With default options it produces this:
ECHO: "――――――――――"
ECHO: " 1 0 0 0"
ECHO: " 0 0.7071 ‒0.7071 0"
ECHO: " 0 0.7071 0.7071 0"
ECHO: " 0 0 0 1"
ECHO: "――――――――――"
It only handles numeric 2D lists. Note that it is impossible to handle
non-numeric data because there's no way to align it. Getting numeric
data to align was pretty tricky, and I think might be slightly
imperfect. (Maybe it depends on the local font behavior. If there
was a way to force a monospaced font this would be so much easier.)
I think maybe len(3) used to be valid and this changed a few versions
ago. In BOSL2 you can use list_shape() to get the dimensions of
multidimensional arrays. Truly determining if something is a
multidimensional array is complex, because you have to recursively
check all the sublists to see if everything is of a consistent length.
There are some type checking functions like is_list() that you can use
to avoid running len() on non-lists.
On Sat, Feb 19, 2022 at 12:32 PM Bob Ewart jinnicky@bobsown.net wrote:
I'm working on a set of functions to pretty print arrays.
For example:
include <BOSL2/std.scad> echo(xrot(45));
comes out looking like:
[[1, 0, 0, 0], [0, 0.707107, -0.707107, 0], [0, 0.707107, 0.707107, 0], [0, 0, 0, 1]]
which is hard to read. I have functions to make it look like:
[ [ 1.000000, 0.000000, 0.000000, 0.000000],
[ 0.000000, 0.707107, -1.292893, 0.000000],
[ 0.000000, 0.707107, 0.707107, 0.000000],
[ 0.000000, 0.000000, 0.000000, 1.000000]
which is the way I would format a matrix in code.
I have functions which will display a vector, 2D matrix or 3D matrix and specify the number of decimal places (f=12.6 above).
I would like to have a function to determine the dimensions of an array: 1=vector, 2=2D matrix and 3 = 3D matrix.
I figured I would drill down with len(array[0]) , len(array[0][0]), len(array[0][0][0]) until I got "undef"
The user manual says:
a=6; len_a=len(a); echo(a,len_a);
should return:
ECHO: 6, undef
It does NOT, it throws an error
WARNING: len() parameter could not be converted in file...
Is there any other way to determine if the variable is a vector, 2d or 3d array?
There was a request back in 2016 for a way to determine the type of a variable. I guess that it was never implemented.
--
Bob
Sometimes the heart sees what is invisible to the eye.
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
The documentation is a Wiki that is public. You can fix it if you
find errors. Note that I think with the 2019 version a bunch of
changes were made where things that used to be quiet undef generated
warnings. This change is clearly not going to be reverted. I know
nophead hates it, but overall these changes make it harder to write
buggy code and about 100 times easier to debug code with bugs, because
it used to be that undef would appear where you had your error but
nothing would go visibly wrong until hundreds of lines later in your
program, possibly in a totally different file, and it was a very
painful process to backtrack to try to figure out where the first
invalid operation occurred, and hence where the bad code was located.
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Type_Test_Functions
On Sat, Feb 19, 2022 at 1:34 PM Bob Ewart <jinnicky@bobsown.net> wrote:
>
> Thank you Adrian and Nop Head for your quick responses
>
> "is_list()" solves my current problem
>
> Adrian, I will probably be using BOSL2 a lot, especially for creating pipe stems. But I wanted a way to display arrays without any other dependencies.
>
> echo_matrix does the job, but I couldn't copy the output and paste it into a source file without changes.
>
> The big problem is documentation:
>
> Where is "is_list()" documented? And are there any other functions like that?
> if len(6) is going to throw an error, the manual needs to be changed. I would prefer that the code is changed to reflect the documentation.
>
> --
> Bob
>
>
> On 2/19/22 12:54, Adrian Mariano wrote:
>
> Since you're using BOSL2 I suggest first that you take a look at
> echo_matrix() and see how close it comes to meeting your needs.
>
> With default options it produces this:
>
> ECHO: "――――――――――"
> ECHO: " 1 0 0 0"
> ECHO: " 0 0.7071 ‒0.7071 0"
> ECHO: " 0 0.7071 0.7071 0"
> ECHO: " 0 0 0 1"
> ECHO: "――――――――――"
>
> It only handles numeric 2D lists. Note that it is impossible to handle
> non-numeric data because there's no way to align it. Getting numeric
> data to align was pretty tricky, and I think might be slightly
> imperfect. (Maybe it depends on the local font behavior. If there
> was a way to force a monospaced font this would be so much easier.)
>
> I think maybe len(3) used to be valid and this changed a few versions
> ago. In BOSL2 you can use list_shape() to get the dimensions of
> multidimensional arrays. Truly determining if something is a
> multidimensional array is complex, because you have to recursively
> check all the sublists to see if everything is of a consistent length.
> There are some type checking functions like is_list() that you can use
> to avoid running len() on non-lists.
>
> On Sat, Feb 19, 2022 at 12:32 PM Bob Ewart <jinnicky@bobsown.net> wrote:
>
> I'm working on a set of functions to pretty print arrays.
>
> For example:
>
> include <BOSL2/std.scad> echo(xrot(45));
>
> comes out looking like:
>
> [[1, 0, 0, 0], [0, 0.707107, -0.707107, 0], [0, 0.707107, 0.707107, 0], [0, 0, 0, 1]]
>
> which is hard to read. I have functions to make it look like:
>
> [ [ 1.000000, 0.000000, 0.000000, 0.000000],
> [ 0.000000, 0.707107, -1.292893, 0.000000],
> [ 0.000000, 0.707107, 0.707107, 0.000000],
> [ 0.000000, 0.000000, 0.000000, 1.000000]
>
> which is the way I would format a matrix in code.
>
> I have functions which will display a vector, 2D matrix or 3D matrix and specify the number of decimal places (f=12.6 above).
>
> I would like to have a function to determine the dimensions of an array: 1=vector, 2=2D matrix and 3 = 3D matrix.
>
> I figured I would drill down with len(array[0]) , len(array[0][0]), len(array[0][0][0]) until I got "undef"
>
> The user manual says:
>
> a=6; len_a=len(a); echo(a,len_a);
>
> should return:
>
> ECHO: 6, undef
>
> It does NOT, it throws an error
>
> WARNING: len() parameter could not be converted in file...
>
> Is there any other way to determine if the variable is a vector, 2d or 3d array?
>
> There was a request back in 2016 for a way to determine the type of a variable. I guess that it was never implemented.
>
> --
> Bob
>
> Sometimes the heart sees what is invisible to the eye.
> - H. Jackson Brown, Jr.
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
BE
Bob Ewart
Sat, Feb 19, 2022 10:28 PM
I've been using the OpenSCAD User Manual/Print Version, which I just
discovered hasn't been updated since 2020.
I did make changes in OpenSCAD User Manual/Mathematical Functions and
OpenSCAD/General to show len(6) raises an error
Part of my problem is that there are 3 books on Wikibooks:
- OpenSCAD User Manual/Print version (last updated 13 April 2020)
- OpenSCAD User Manual/The OpenSCAD Language (last updated 18 August 2021)
- OpenSCAD User Manual which has The OpenSCAD Language Reference
section, the one I updated
The first two are outdated. Why are they still around? I'll stick with
the third which does have the type test functions and seems to be the
most current.
I understand the rationale behind making len(6) an error. I was
concerned that it didn't do what the documentation said. It was a kludge
because I didn't know about the type test functions.
Thanks for all your help.
--
Bob Ewart
On 2/19/22 13:44, Adrian Mariano wrote:
The documentation is a Wiki that is public. You can fix it if you
find errors. Note that I think with the 2019 version a bunch of
changes were made where things that used to be quiet undef generated
warnings. This change is clearly not going to be reverted. I know
nophead hates it, but overall these changes make it harder to write
buggy code and about 100 times easier to debug code with bugs, because
it used to be that undef would appear where you had your error but
nothing would go visibly wrong until hundreds of lines later in your
program, possibly in a totally different file, and it was a very
painful process to backtrack to try to figure out where the first
invalid operation occurred, and hence where the bad code was located.
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Type_Test_Functions
On Sat, Feb 19, 2022 at 1:34 PM Bob Ewartjinnicky@bobsown.net wrote:
Thank you Adrian and Nop Head for your quick responses
"is_list()" solves my current problem
Adrian, I will probably be using BOSL2 a lot, especially for creating pipe stems. But I wanted a way to display arrays without any other dependencies.
echo_matrix does the job, but I couldn't copy the output and paste it into a source file without changes.
The big problem is documentation:
Where is "is_list()" documented? And are there any other functions like that?
if len(6) is going to throw an error, the manual needs to be changed. I would prefer that the code is changed to reflect the documentation.
--
Bob
On 2/19/22 12:54, Adrian Mariano wrote:
Since you're using BOSL2 I suggest first that you take a look at
echo_matrix() and see how close it comes to meeting your needs.
With default options it produces this:
ECHO: "――――――――――"
ECHO: " 1 0 0 0"
ECHO: " 0 0.7071 ‒0.7071 0"
ECHO: " 0 0.7071 0.7071 0"
ECHO: " 0 0 0 1"
ECHO: "――――――――――"
It only handles numeric 2D lists. Note that it is impossible to handle
non-numeric data because there's no way to align it. Getting numeric
data to align was pretty tricky, and I think might be slightly
imperfect. (Maybe it depends on the local font behavior. If there
was a way to force a monospaced font this would be so much easier.)
I think maybe len(3) used to be valid and this changed a few versions
ago. In BOSL2 you can use list_shape() to get the dimensions of
multidimensional arrays. Truly determining if something is a
multidimensional array is complex, because you have to recursively
check all the sublists to see if everything is of a consistent length.
There are some type checking functions like is_list() that you can use
to avoid running len() on non-lists.
On Sat, Feb 19, 2022 at 12:32 PM Bob Ewartjinnicky@bobsown.net wrote:
I'm working on a set of functions to pretty print arrays.
For example:
include <BOSL2/std.scad> echo(xrot(45));
comes out looking like:
[[1, 0, 0, 0], [0, 0.707107, -0.707107, 0], [0, 0.707107, 0.707107, 0], [0, 0, 0, 1]]
which is hard to read. I have functions to make it look like:
[ [ 1.000000, 0.000000, 0.000000, 0.000000],
[ 0.000000, 0.707107, -1.292893, 0.000000],
[ 0.000000, 0.707107, 0.707107, 0.000000],
[ 0.000000, 0.000000, 0.000000, 1.000000]
which is the way I would format a matrix in code.
I have functions which will display a vector, 2D matrix or 3D matrix and specify the number of decimal places (f=12.6 above).
I would like to have a function to determine the dimensions of an array: 1=vector, 2=2D matrix and 3 = 3D matrix.
I figured I would drill down with len(array[0]) , len(array[0][0]), len(array[0][0][0]) until I got "undef"
The user manual says:
a=6; len_a=len(a); echo(a,len_a);
should return:
ECHO: 6, undef
It does NOT, it throws an error
WARNING: len() parameter could not be converted in file...
Is there any other way to determine if the variable is a vector, 2d or 3d array?
There was a request back in 2016 for a way to determine the type of a variable. I guess that it was never implemented.
--
Bob
Sometimes the heart sees what is invisible to the eye.
OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org
I've been using the OpenSCAD User Manual/Print Version, which I just
discovered hasn't been updated since 2020.
I did make changes in OpenSCAD User Manual/Mathematical Functions and
OpenSCAD/General to show len(6) raises an error
Part of my problem is that there are 3 books on Wikibooks:
* OpenSCAD User Manual/Print version (last updated 13 April 2020)
* OpenSCAD User Manual/The OpenSCAD Language (last updated 18 August 2021)
* OpenSCAD User Manual which has The OpenSCAD Language Reference
section, the one I updated
The first two are outdated. Why are they still around? I'll stick with
the third which does have the type test functions and seems to be the
most current.
I understand the rationale behind making len(6) an error. I was
concerned that it didn't do what the documentation said. It was a kludge
because I didn't know about the type test functions.
Thanks for all your help.
--
Bob Ewart
On 2/19/22 13:44, Adrian Mariano wrote:
> The documentation is a Wiki that is public. You can fix it if you
> find errors. Note that I think with the 2019 version a bunch of
> changes were made where things that used to be quiet undef generated
> warnings. This change is clearly not going to be reverted. I know
> nophead hates it, but overall these changes make it harder to write
> buggy code and about 100 times easier to debug code with bugs, because
> it used to be that undef would appear where you had your error but
> nothing would go visibly wrong until hundreds of lines later in your
> program, possibly in a totally different file, and it was a very
> painful process to backtrack to try to figure out where the first
> invalid operation occurred, and hence where the bad code was located.
>
> https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Type_Test_Functions
>
> On Sat, Feb 19, 2022 at 1:34 PM Bob Ewart<jinnicky@bobsown.net> wrote:
>> Thank you Adrian and Nop Head for your quick responses
>>
>> "is_list()" solves my current problem
>>
>> Adrian, I will probably be using BOSL2 a lot, especially for creating pipe stems. But I wanted a way to display arrays without any other dependencies.
>>
>> echo_matrix does the job, but I couldn't copy the output and paste it into a source file without changes.
>>
>> The big problem is documentation:
>>
>> Where is "is_list()" documented? And are there any other functions like that?
>> if len(6) is going to throw an error, the manual needs to be changed. I would prefer that the code is changed to reflect the documentation.
>>
>> --
>> Bob
>>
>>
>> On 2/19/22 12:54, Adrian Mariano wrote:
>>
>> Since you're using BOSL2 I suggest first that you take a look at
>> echo_matrix() and see how close it comes to meeting your needs.
>>
>> With default options it produces this:
>>
>> ECHO: "――――――――――"
>> ECHO: " 1 0 0 0"
>> ECHO: " 0 0.7071 ‒0.7071 0"
>> ECHO: " 0 0.7071 0.7071 0"
>> ECHO: " 0 0 0 1"
>> ECHO: "――――――――――"
>>
>> It only handles numeric 2D lists. Note that it is impossible to handle
>> non-numeric data because there's no way to align it. Getting numeric
>> data to align was pretty tricky, and I think might be slightly
>> imperfect. (Maybe it depends on the local font behavior. If there
>> was a way to force a monospaced font this would be so much easier.)
>>
>> I think maybe len(3) used to be valid and this changed a few versions
>> ago. In BOSL2 you can use list_shape() to get the dimensions of
>> multidimensional arrays. Truly determining if something is a
>> multidimensional array is complex, because you have to recursively
>> check all the sublists to see if everything is of a consistent length.
>> There are some type checking functions like is_list() that you can use
>> to avoid running len() on non-lists.
>>
>> On Sat, Feb 19, 2022 at 12:32 PM Bob Ewart<jinnicky@bobsown.net> wrote:
>>
>> I'm working on a set of functions to pretty print arrays.
>>
>> For example:
>>
>> include <BOSL2/std.scad> echo(xrot(45));
>>
>> comes out looking like:
>>
>> [[1, 0, 0, 0], [0, 0.707107, -0.707107, 0], [0, 0.707107, 0.707107, 0], [0, 0, 0, 1]]
>>
>> which is hard to read. I have functions to make it look like:
>>
>> [ [ 1.000000, 0.000000, 0.000000, 0.000000],
>> [ 0.000000, 0.707107, -1.292893, 0.000000],
>> [ 0.000000, 0.707107, 0.707107, 0.000000],
>> [ 0.000000, 0.000000, 0.000000, 1.000000]
>>
>> which is the way I would format a matrix in code.
>>
>> I have functions which will display a vector, 2D matrix or 3D matrix and specify the number of decimal places (f=12.6 above).
>>
>> I would like to have a function to determine the dimensions of an array: 1=vector, 2=2D matrix and 3 = 3D matrix.
>>
>> I figured I would drill down with len(array[0]) , len(array[0][0]), len(array[0][0][0]) until I got "undef"
>>
>> The user manual says:
>>
>> a=6; len_a=len(a); echo(a,len_a);
>>
>> should return:
>>
>> ECHO: 6, undef
>>
>> It does NOT, it throws an error
>>
>> WARNING: len() parameter could not be converted in file...
>>
>> Is there any other way to determine if the variable is a vector, 2d or 3d array?
>>
>> There was a request back in 2016 for a way to determine the type of a variable. I guess that it was never implemented.
>>
>> --
>> Bob
>>
>> Sometimes the heart sees what is invisible to the eye.
>> - H. Jackson Brown, Jr.
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> To unsubscribe send an email todiscuss-leave@lists.openscad.org
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> To unsubscribe send an email todiscuss-leave@lists.openscad.org
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> To unsubscribe send an email todiscuss-leave@lists.openscad.org
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email todiscuss-leave@lists.openscad.org
M
MichaelAtOz
Sun, Feb 20, 2022 1:56 AM
-----Original Message-----
From: Adrian Mariano [mailto:avm4@cornell.edu]
If there
was a way to force a monospaced font this would be so much easier.)
You can do that in Development snapshots preferences.
--
This email has been checked for viruses by AVG.
https://www.avg.com
> -----Original Message-----
> From: Adrian Mariano [mailto:avm4@cornell.edu]
> If there
> was a way to force a monospaced font this would be so much easier.)
>
You can do that in Development snapshots preferences.
--
This email has been checked for viruses by AVG.
https://www.avg.com
AM
Adrian Mariano
Sun, Feb 20, 2022 3:17 AM
Doing it in the preferences means that the library's echo_matrix
routine would fail for everybody until they changed their preferences.
For it to actually work I need a way to force the specific matrix
output to be printed monospaced---using code in openscad---and then
you can go back to whatever the default font is.
On Sat, Feb 19, 2022 at 8:57 PM MichaelAtOz oz.at.michael@gmail.com wrote:
-----Original Message-----
From: Adrian Mariano [mailto:avm4@cornell.edu]
If there
was a way to force a monospaced font this would be so much easier.)
You can do that in Development snapshots preferences.
--
This email has been checked for viruses by AVG.
https://www.avg.com
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
Doing it in the preferences means that the library's echo_matrix
routine would fail for everybody until they changed their preferences.
For it to actually work I need a way to force the specific matrix
output to be printed monospaced---using code in openscad---and then
you can go back to whatever the default font is.
On Sat, Feb 19, 2022 at 8:57 PM MichaelAtOz <oz.at.michael@gmail.com> wrote:
>
> > -----Original Message-----
> > From: Adrian Mariano [mailto:avm4@cornell.edu]
> > If there
> > was a way to force a monospaced font this would be so much easier.)
> >
>
> You can do that in Development snapshots preferences.
>
>
>
> --
> This email has been checked for viruses by AVG.
> https://www.avg.com
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
JB
Jordan Brown
Mon, Feb 21, 2022 3:37 AM
Do be aware that OpenSCAD does not have 2D arrays or 3D arrays.
It has lists, and each list element may be different. Yes, if you have
a list of N elements, each of which is a list of M elements, that's a
lot like an NxM array.
But this is equally legal:
[
1,
[2, 3],
[
[4,5,6],
[7,8,9]
]
]
along with other combinations that are arbitrarily more complex.
If you know that your list and its elements form a simple rectangular
array then you can answer questions about dimensions and dimensionality,
but in the general case it's hard to figure out what the questions even
mean.
Do be aware that OpenSCAD does not have 2D arrays or 3D arrays.
It has lists, and each list element may be different. Yes, if you have
a list of N elements, each of which is a list of M elements, that's a
lot like an NxM array.
But this is equally legal:
[
1,
[2, 3],
[
[4,5,6],
[7,8,9]
]
]
along with other combinations that are arbitrarily more complex.
If you know that your list and its elements form a simple rectangular
array then you can answer questions about dimensions and dimensionality,
but in the general case it's hard to figure out what the questions even
mean.
AM
Adrian Mariano
Mon, Feb 21, 2022 4:05 AM
I think the BOSL2 list_shape() function is reasonably robust at giving
information on arbitrary lists. If the list actually looks like an
n-dimensional array it will give you a list of its dimensions. If it
looks sort of like an n-dimensional array you'll get a list of
dimensions with undefs for the ones that were inconsistent. The thing
above gives you [3,undef,undef] because it had three entries at the
top level, but the other levels were inconsistent. So you can read
off the total depth of the structure (3), and that's about it.
However, that list_shape() function is pretty slow since it has to
search the entire array to check the size of every element.
So for example, run on the list below gives [3,undef,2] because there
are 3 items at level 0, the length of items at level 1 is
inconsistent, and items at level 2 all have length 2.
[
[[3,4],[4,5]],
[[4,5]],
[[9,8],[3,2],[4,4],[5,5]]
];
On Sun, Feb 20, 2022 at 10:38 PM Jordan Brown
openscad@jordan.maileater.net wrote:
Do be aware that OpenSCAD does not have 2D arrays or 3D arrays.
It has lists, and each list element may be different. Yes, if you have a list of N elements, each of which is a list of M elements, that's a lot like an NxM array.
But this is equally legal:
[
1,
[2, 3],
[
[4,5,6],
[7,8,9]
]
]
along with other combinations that are arbitrarily more complex.
If you know that your list and its elements form a simple rectangular array then you can answer questions about dimensions and dimensionality, but in the general case it's hard to figure out what the questions even mean.
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
I think the BOSL2 list_shape() function is reasonably robust at giving
information on arbitrary lists. If the list actually looks like an
n-dimensional array it will give you a list of its dimensions. If it
looks sort of like an n-dimensional array you'll get a list of
dimensions with undefs for the ones that were inconsistent. The thing
above gives you [3,undef,undef] because it had three entries at the
top level, but the other levels were inconsistent. So you can read
off the total depth of the structure (3), and that's about it.
However, that list_shape() function is pretty slow since it has to
search the entire array to check the size of every element.
So for example, run on the list below gives [3,undef,2] because there
are 3 items at level 0, the length of items at level 1 is
inconsistent, and items at level 2 all have length 2.
[
[[3,4],[4,5]],
[[4,5]],
[[9,8],[3,2],[4,4],[5,5]]
];
On Sun, Feb 20, 2022 at 10:38 PM Jordan Brown
<openscad@jordan.maileater.net> wrote:
>
> Do be aware that OpenSCAD does not have 2D arrays or 3D arrays.
>
> It has lists, and each list element may be different. Yes, if you have a list of N elements, each of which is a list of M elements, that's a lot like an NxM array.
>
> But this is equally legal:
>
> [
> 1,
> [2, 3],
> [
> [4,5,6],
> [7,8,9]
> ]
> ]
>
> along with other combinations that are arbitrarily more complex.
>
> If you know that your list and its elements form a simple rectangular array then you can answer questions about dimensions and dimensionality, but in the general case it's hard to figure out what the questions even mean.
>
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org