(no subject)

classic Classic list List threaded Threaded
59 messages Options
123
Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

M.Rule
disclaimer : not having read the whole thread

The += -= *= /= ++ -- and other related operators seem out of place in OpenSCAD.

unsure about formal jargon but :

OpenSCAD should be a descriptive language. meaning, that the "program" is simply the definition of an object. This is consistent with strictly functional languages, like ML. I personally don't want side-effecting operators in their sullying my pure descriptive model. It is an asset to be able to look at OpenSCAD that just reads like "and this is how the thing looks" rather than some not quite straightforward procedure that generates some object. Of course, if you put the operators in there, I could just not use them, so, maybe its fine.


On Mon, Sep 13, 2010 at 7:47 AM, Giles Bathgate <[hidden email]> wrote:
Maybe this is a good example of how we should tokenise floats

http://www.lysator.liu.se/c/ANSI-C-grammar-l.html

Regards

Giles


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad

Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Giles Bathgate-2
On Mon, 2010-09-13 at 07:55 -0400, M.Rule wrote:

> OpenSCAD should be a descriptive language. meaning, that the "program"
> is simply the definition of an object. This is consistent with
> strictly functional languages, like ML. I personally don't want
> side-effecting operators in their sullying my pure descriptive model.
> It is an asset to be able to look at OpenSCAD that just reads like
> "and this is how the thing looks" rather than some not quite
> straightforward procedure that generates some object. Of course, if
> you put the operators in there, I could just not use them, so, maybe
> its fine.

I am not really sure I understand your distinction of "descriptive
language"

You can already do all of the operations in OpenSCAD

for example:

module plusequals()
{
        j=5;
        assign(j=j+3)
        {
                echo(j);
        }
}

module minusequals()
{
                j=5;
                assign(j=j-3)
                {
                        echo(j);
                }
}

module minusminus()
{
        j=2;
       
        assign(j=j-1)
        {
                echo(j);
        }
}

module main()
{
        plusequals();
        minusequals();
        minusminus();
        cube([1,1,1]);
}

main();


Can someone please explain to me why this syntax is so safe from
unwanted side effects?


Regards

Giles.


Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

M.Rule
yeah but that form of assignment is like the "let" operator.

nevermind, perhaps I drank too much of the ML koolaid in undergrad.

On Mon, Sep 13, 2010 at 8:23 AM, Giles Bathgate <[hidden email]> wrote:
On Mon, 2010-09-13 at 07:55 -0400, M.Rule wrote:

> OpenSCAD should be a descriptive language. meaning, that the "program"
> is simply the definition of an object. This is consistent with
> strictly functional languages, like ML. I personally don't want
> side-effecting operators in their sullying my pure descriptive model.
> It is an asset to be able to look at OpenSCAD that just reads like
> "and this is how the thing looks" rather than some not quite
> straightforward procedure that generates some object. Of course, if
> you put the operators in there, I could just not use them, so, maybe
> its fine.

I am not really sure I understand your distinction of "descriptive
language"

You can already do all of the operations in OpenSCAD

for example:

module plusequals()
{
       j=5;
       assign(j=j+3)
       {
               echo(j);
       }
}

module minusequals()
{
               j=5;
               assign(j=j-3)
               {
                       echo(j);
               }
}

module minusminus()
{
       j=2;

       assign(j=j-1)
       {
               echo(j);
       }
}

module main()
{
       plusequals();
       minusequals();
       minusminus();
       cube([1,1,1]);
}

main();


Can someone please explain to me why this syntax is so safe from
unwanted side effects?


Regards

Giles.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad

Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Giles Bathgate-2
In reply to this post by andy@kirbyand.co.uk
On Mon, 2010-09-13 at 08:33 -0400, M.Rule wrote:
> yeah but that form of assignment is like the "let" operator.

One way of interpreting the requirement is to have other operators in
the assign statement e.g:

assign(j+=3)
{

}

Another way would be to have REAL variables e.g:

module main()
{
       j=3;
       echo(j);
       j=4;
       echo(j);
}

I would have expected the above script to output:
ECHO: 3
ECHO: 4

Currently the output is
ECHO: 4
ECHO: 4

That seems pretty confusing to me, and apparently to others.
Finally there would be a full compliment of operators that could be
used to change those variables.

Regards

Giles

Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Steve Klabnik
I'd agree that keeping OpenSCAD as a functional language makes a lot of sense.

However, all of these comments feel like 'growing' pains to me. I
haven't been around here very long, but it seems like the scripting
language for OpenSCAD has kind of grown organically over time, and so
it feels lacking in that regard. Maybe the language itself needs an
overhaul, a cleanup, and a redo.

I, however, am not that person. At least not right now. But it'd seem
to me the project could benefit from a 'language guy' who's actually
into compilers. Or the existing ones stepping up a bit more. (this
would include me)

Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

andy@kirbyand.co.uk
OK Guys

The code segment I promised. The commented out bit in the middle is the
bit I need to arrange the objects so that they union into the right
shape. A cell is a haxagonal object think of it as a tube. An array is a
unioned diagonal array of cells starting lower right and growing up and
left by the number of items it is told to make.

The tile then is a union of arrays.

All in all easy enough to do with sufficient support from the scripting
language. It is made messy by the way that a hexagonal array doesn't
have a neat east equation that describes it and can fit into the
translate statement.

I think though that irregular matrices of objects is something that
OpenSCAD will need to support at some time, some way or other.

An explicit assign function would do for now.


/*
   module to create a haxagonal tile of hexagonal cells
   that can teselate to make a larger array of cells
   cells are h high and of characterisitc radius r
*/
module tile( h, r, w, m){

   arrx = m;
   arry = 0;
   arrsize = m;

  // if module size is only 1 just draw it at the origin
   if(m == 1) {
      // move to origin and draw one cell
      translate(v = [0,0,0]) {
         cell( h, r, w);
      }
   } else {
      //create a tesselating tile of module m units per side
      union( ) {
         // union together a bunch of arrays of single cells
         for( i = [0:hexdia] ){
            translate(v = [dispx * arrx,dispy * arry,0])  array( h, r,
w, arrsize);
/*
            if( arrx > 0 ){
               arrx =  arrx -1;
            }
            if( arry < m) (
               arry = arry + 1;
            } else {
               arry = arry + 2;
            }
*/
         }
      }
   }
}



Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

andy@kirbyand.co.uk
Ouch typed that wrong.

It is actually starting bottom left and growing up right by the number
of items it is told to make. (increasing X increasing Y)

/*
   module to create an array of n touching hex objects
   spacing is related to the radius of the circle used for their creation
   this is precalculated as dispx and dispy (displacment x & y)
*/
module array (h, r, w, n) {
   for ( i = [0:n - 1] ) {
      translate( v = [i *dispx, i * dispy, 0]) cell( h, r, w);
   }
}

Sorry guys

On 13/09/10 15:19, [hidden email] wrote:
> An array is a
> unioned diagonal array of cells starting lower right and growing up and
> left by the number of items it is told to make.

Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Giles Bathgate-2
In reply to this post by andy@kirbyand.co.uk
On Mon, 2010-09-13 at 15:19 +0100, [hidden email] wrote:

> for( i = [0:hexdia] ){
>             translate(v = [dispx * arrx,dispy * arry,0])  array( h, r,
> w, arrsize);
> /*
>             if( arrx > 0 ){
>                arrx =  arrx -1;
>             }
>             if( arry < m) (
>                arry = arry + 1;
>             } else {
>                arry = arry + 2;
>             }
> */

Would something like this work?:

for( i = [0:hexdia] ){
            if( arrx > 0 ){
               assign(arrx =  arrx -1)
                {
                translate(v = [dispx * arrx,dispy * arry,0])  array( h, r,w, arrsize);
                }
            if( arry < m) (
               assign(arry = arry + 1)
                {
                translate(v = [dispx * arrx,dispy * arry,0])  array( h, r,w, arrsize);
                }
            } else {
               assign(arry = arry + 2)
                {
                translate(v = [dispx * arrx,dispy * arry,0])  array( h, r,w, arrsize);
                }
            }



Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

andy@kirbyand.co.uk
I will try it tonight.

What value does for example arry take after the assign. Is it modified
by the assign permanently or is the modified value of arry only
available to the invocation in the  { } of the assign statment ??

Given that the arry + 1 is an incrementer ie equivalent to ++arry or
arry +=1

The next iteration of the for loop has to be presented with the
incremented value for arry to increment again so that the placing of the
objects progresses from last place to next.



On 13/09/10 15:35, Giles Bathgate wrote:

> On Mon, 2010-09-13 at 15:19 +0100, [hidden email] wrote:
>> for( i = [0:hexdia] ){
>>             translate(v = [dispx * arrx,dispy * arry,0])  array( h, r,
>> w, arrsize);
>> /*
>>             if( arrx > 0 ){
>>                arrx =  arrx -1;
>>             }
>>             if( arry < m) (
>>                arry = arry + 1;
>>             } else {
>>                arry = arry + 2;
>>             }
>> */
>
> Would something like this work?:
>
> for( i = [0:hexdia] ){
>             if( arrx > 0 ){
>                assign(arrx =  arrx -1)
> {
> translate(v = [dispx * arrx,dispy * arry,0])  array( h, r,w, arrsize);
> }
>             if( arry < m) (
>                assign(arry = arry + 1)
> {
> translate(v = [dispx * arrx,dispy * arry,0])  array( h, r,w, arrsize);
> }
>             } else {
>                assign(arry = arry + 2)
> {
> translate(v = [dispx * arrx,dispy * arry,0])  array( h, r,w, arrsize);
> }
>             }
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
>

Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Giles Bathgate-2
On Mon, 2010-09-13 at 15:44 +0100, [hidden email] wrote:

> I will try it tonight.
>
> What value does for example arry take after the assign. Is it modified
> by the assign permanently or is the modified value of arry only
> available to the invocation in the  { } of the assign statment ??
>
> Given that the arry + 1 is an incrementer ie equivalent to ++arry or
> arry +=1
>
> The next iteration of the for loop has to be presented with the
> incremented value for arry to increment again so that the placing of the
> objects progresses from last place to next.

No it wont work the example script illustrates this:

module main()
{
        j=0;
        for(i=[0:10])
        {
                assign(j=j+1)
                {
                        echo(j);
                }
        }
        cube([1,1,1]);
}

main();

output:

ECHO: 1
ECHO: 1
ECHO: 1
ECHO: 1
ECHO: 1
ECHO: 1
ECHO: 1
ECHO: 1
ECHO: 1
ECHO: 1
ECHO: 1

I am beginning to thing the assign statement is as good as useless.

Regards

Giles


Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

andy@kirbyand.co.uk
Sorry but I am going to have to agree.

Hell of a shame that, I over estimated OpenSCAD quite badly. (Certainly
not OpenSCAD's fault)

Unfortunately I don't know of something similar. It is almost begging
for some Perl library or other that could interface with the CSG
libraries that SCAD uses.

This is a route though I would rather not go.

I will layup the tile from a manually constructed array of X,Y vector
offsets for now. This is a job I am doing as a favor for someone else
and need to get them sorted soonest. Not very smart and a bit of a pain
but gets us out of a hole.

Long term I am gonna have to have a look around and see what there is
for making Smart-Parts.

Thanks guys you are all stars.

Cheers

Andy Kirby





On 13/09/10 16:15, Giles Bathgate wrote:

> On Mon, 2010-09-13 at 15:44 +0100, [hidden email] wrote:
>> I will try it tonight.
>>
>> What value does for example arry take after the assign. Is it modified
>> by the assign permanently or is the modified value of arry only
>> available to the invocation in the  { } of the assign statment ??
>>
>> Given that the arry + 1 is an incrementer ie equivalent to ++arry or
>> arry +=1
>>
>> The next iteration of the for loop has to be presented with the
>> incremented value for arry to increment again so that the placing of the
>> objects progresses from last place to next.
>
> No it wont work the example script illustrates this:
>
> module main()
> {
> j=0;
> for(i=[0:10])
> {
> assign(j=j+1)
> {
> echo(j);
> }
> }
> cube([1,1,1]);
> }
>
> main();
>
> output:
>
> ECHO: 1
> ECHO: 1
> ECHO: 1
> ECHO: 1
> ECHO: 1
> ECHO: 1
> ECHO: 1
> ECHO: 1
> ECHO: 1
> ECHO: 1
> ECHO: 1
>
> I am beginning to thing the assign statement is as good as useless.
>
> Regards
>
> Giles
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
>

Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

clothbot
Yeah, you can't do self-incrementing/decrementing of variables.  You have to do something like the following to get the same effect:

module main()
{
  for(i=[0:10]) assign(j=i+1)
    echo(j);
  cube([1,1,1]);
}
main();

Andrew.

On 2010-09-13, at 11:47 AM, [hidden email] wrote:

> Sorry but I am going to have to agree.
>
> Hell of a shame that, I over estimated OpenSCAD quite badly. (Certainly
> not OpenSCAD's fault)
>
> Unfortunately I don't know of something similar. It is almost begging
> for some Perl library or other that could interface with the CSG
> libraries that SCAD uses.
>
> This is a route though I would rather not go.
>
> I will layup the tile from a manually constructed array of X,Y vector
> offsets for now. This is a job I am doing as a favor for someone else
> and need to get them sorted soonest. Not very smart and a bit of a pain
> but gets us out of a hole.
>
> Long term I am gonna have to have a look around and see what there is
> for making Smart-Parts.
>
> Thanks guys you are all stars.
>
> Cheers
>
> Andy Kirby
>
>
>
>
>
> On 13/09/10 16:15, Giles Bathgate wrote:
>> On Mon, 2010-09-13 at 15:44 +0100, [hidden email] wrote:
>>> I will try it tonight.
>>>
>>> What value does for example arry take after the assign. Is it modified
>>> by the assign permanently or is the modified value of arry only
>>> available to the invocation in the  { } of the assign statment ??
>>>
>>> Given that the arry + 1 is an incrementer ie equivalent to ++arry or
>>> arry +=1
>>>
>>> The next iteration of the for loop has to be presented with the
>>> incremented value for arry to increment again so that the placing of the
>>> objects progresses from last place to next.
>>
>> No it wont work the example script illustrates this:
>>
>> module main()
>> {
>> j=0;
>> for(i=[0:10])
>> {
>> assign(j=j+1)
>> {
>> echo(j);
>> }
>> }
>> cube([1,1,1]);
>> }
>>
>> main();
>>
>> output:
>>
>> ECHO: 1
>> ECHO: 1
>> ECHO: 1
>> ECHO: 1
>> ECHO: 1
>> ECHO: 1
>> ECHO: 1
>> ECHO: 1
>> ECHO: 1
>> ECHO: 1
>> ECHO: 1
>>
>> I am beginning to thing the assign statement is as good as useless.
>>
>> Regards
>>
>> Giles
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> [hidden email]
>> http://rocklinux.net/mailman/listinfo/openscad
>>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad

--

"The future is already here.  It's just not very evenly distributed" -- William Gibson

Me: http://clothbot.com/wiki/




Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Giles Bathgate-2
On Mon, 2010-09-13 at 12:08 -0400, Andrew Plumb wrote:

> Yeah, you can't do self-incrementing/decrementing of variables.  You have to do something like the following to get the same effect:
>
> module main()
> {
>   for(i=[0:10]) assign(j=i+1)
>     echo(j);
>   cube([1,1,1]);
> }
> main();
>
> Andrew.

Sure, but this was just an example for andy to show that what he is
trying to do cannot be done. He is trying to do conditional
incrementation. Please read the rest of the thread.

Regards

Giles



Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

tbuser
In reply to this post by andy@kirbyand.co.uk
On Mon, Sep 13, 2010 at 11:47 AM, [hidden email]
<[hidden email]> wrote:
> Unfortunately I don't know of something similar. It is almost begging
> for some Perl library or other that could interface with the CSG
> libraries that SCAD uses.

I definitely feel proper variable assignments in OpenSCAD is sorely
needed to the point where I have dreamt of doing this on a number of
occasions, except I'd use ruby.  Unfortunately, I haven't figured out
yet how to get more than 24 hours in a day.

Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Giles Bathgate-2
In reply to this post by Steve Klabnik
It seems ridiculous to me that people write python scripts to generate
OpenSCAD scripts that generate STL.

This is surely a sign that the language is lacking necessary features.

I am all for your "declarative" way of doing things, but how do you
extend the power of assign to solve problems such as andy is having?

Its really up to the maintainer which direction the language goes, but
I personally think that an assignment operator is a step in the right
direction.

Regards

Giles.



Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Jim MacArthur
For what it's worth, I have written a perl script before to generate an OpenSCAD file, for a custom cam I needed. This was included by some other hand-written OpenSCAD to make a complete model. To me, this seemed like a natural and easy way to code it. I would prefer to use a 'real' programming language where necessary and keep the OpenSCAD language simple.

Jim

Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

M.Rule
I'd be really happy with a python module duplicating OpenSCAD functionality

On Mon, Sep 13, 2010 at 12:54 PM, Jim MacArthur <[hidden email]> wrote:
For what it's worth, I have written a perl script before to generate an OpenSCAD file, for a custom cam I needed. This was included by some other hand-written OpenSCAD to make a complete model. To me, this seemed like a natural and easy way to code it. I would prefer to use a 'real' programming language where necessary and keep the OpenSCAD language simple.

Jim


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

andy@kirbyand.co.uk
In reply to this post by Giles Bathgate-2
Yeah

I am going to have to agree with you.

For computer linguists using scripts to write scripts is tedious but doable.  What about the rest of the world though.

An application of occams razor shaves swiftly to the conclusion that what is needed is either scad extending to handle variables in some way. Or another scripting language that can extending to do csg and export .stl

personaly i would like to see scad being the dogs wotsists but would equaly settle for perl doing csg.

For perl substitute your prefered scripting language.....



 
--
Like a rolling stone
----- Original message -----

> It seems ridiculous to me that people write python scripts to generate
> OpenSCAD scripts that generate STL.
>
> This is surely a sign that the language is lacking necessary features.
>
> I am all for your "declarative" way of doing things, but how do you
> extend the power of assign to solve problems such as andy is having?
>
> Its really up to the maintainer which direction the language goes, but
> I personally think that an assignment operator is a step in the right
> direction.
>
> Regards
>
> Giles.
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad


Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

bobc
In reply to this post by andy@kirbyand.co.uk
Hello everyone,

I have been following this with interest but I am an only an
infrequent user of OpenSCAD. When I first found it I thought,  wow,
this is exactly what I was looking for. I made some parameterized
models for Thingiverse, but mainly as a programmer I find it easier to
design 3D models with code than any GUI I have tried.

I have dabbled with parsers and compilers, and I admit I also got a
bit confused with the paradigm in openscad. I did a scripting language
at work recently and after adding all the bells and whistles, I
realised that it probably took about the same effort as taking a
standard script language and adding an application specific library to
it. The same thought struck me with openscad. It's very nice to have a
self contained "IDE" and a descriptive language, but it would be also
nice to have all the power of a modern language. I have considered
writing a library for my favourite HLL which outputs openscad script,
which is doable but a bit clunky.

I don't want to make lots of suggestions without also volunteering
effort, but I have some time to spare. I think that openscad is a
great tool already, but I would welcome improvements in terms of
better programmability.

Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

tbuser
Has anyone seen this? http://pygts.sourceforge.net/ Would this + an
STL output function get us most of the way towards a Python OpenSCAD?

123