(no subject)

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

(no subject)

andy@kirbyand.co.uk
Hurro guys.

I am having a bit of bother doing math and variable assignments in the middle of a nested union,for,if  situation.

The parser complains that there is a syntax error.

Is this a language "feature or morfe likely is it something daft i am doing?

Cheers

andy kirby
--
Like a rolling stone


Reply | Threaded
Open this post in threaded view
|

Re: (no subject)

Steven Dick
On Sun, Sep 12, 2010 at 11:45 AM, Andy Kirby <[hidden email]> wrote:
Hurro guys.

I am having a bit of bother doing math and variable assignments in the middle of a nested union,for,if  situation.


OpenSCAD is kinda funny about stuff like that.  Variables are not real variables, more like constants that can be set at the beginning of a block.

Reply | Threaded
Open this post in threaded view
|

Missing operators

andy@kirbyand.co.uk
In reply to this post by andy@kirbyand.co.uk

guys

this probably is related to tother issues re variables etc.

There are a couple of operators missing. += -= ++ And lastly --

for variable incrementing.

Cheers

andy kirby

Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Giles Bathgate-2
The only supported assignment operation in OpenSCAD is the
assign() function

http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Conditional_and_Iterator_Functions#Assign_Statement

Its annoying because assignments can only be made to variables that are
accessed in sub trees, however I do think that REAL assignment operators
have been on the TODO list for some time now. I am not sure if there is
any technical reason why assignments can only be assigned to sub-tree
variables or if its just a limitation of the current designs syntax?

Either way, if possible It would be nice to see this fixed soon, as most
new users seem to get stuck with this problem.

Regards

Giles

On Sun, 2010-09-12 at 22:19 +0100, Andy Kirby wrote:

> guys
>
> this probably is related to tother issues re variables etc.
>
> There are a couple of operators missing. += -= ++ And lastly --
>
> for variable incrementing.
>
> Cheers
>
> andy kirby
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad



Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Steven Dick


On Sun, Sep 12, 2010 at 5:16 PM, Giles Bathgate <[hidden email]> wrote:
The only supported assignment operation in OpenSCAD is the
assign() function
 [...]
Its annoying because assignments can only be made to variables that are
accessed in sub trees


I have mixed feelings on this.  For programmers coming from other languages, this is confusing and annoying, and it does limit some things.

However, it also prevents any possibility of having side effects, which makes the code more readable.
Also, I'd like to see a more conventional GUI based cad system built on top of OpenSCAD, and allowing side effects and global changes of variables in the middle of code would make that difficult.

 
I would rather see more flexible access to array elements than a more flexible assignment.
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 Sun, 2010-09-12 at 17:29 -0400, Steven Dick wrote:
> I have mixed feelings on this.  For programmers coming from other
> languages, this is confusing and annoying, and it does limit some
> things.

I think OpenSCAD is targeted towards people who write scripts, or
programs.

(I always thought the S in the name was for "Script" as in: Open
Scripted Computer Aided Design.)

> However, it also prevents any possibility of having side effects,
> which makes the code more readable.
> Also, I'd like to see a more conventional GUI based cad system built
> on top of OpenSCAD, and allowing side effects and global changes of
> variables in the middle of code would make that difficult.

If you want a GUI based 3D CAD maybe look at

HeeksCAD http://code.google.com/p/heekscad/
or
FreeCAD
http://sourceforge.net/apps/mediawiki/free-cad/index.php?title=Main_Page


> I would rather see more flexible access to array elements than a more
> flexible assignment.

Yeah that would be good too.

Regards

Giles




Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Giles Bathgate-2
In reply to this post by Steven Dick
Hmm.. I don't think the idea is all that new. Nearly every commercial
CAD package I have used has a scripting language back end, and the
ability to edit modules in a parametric way....but anyway

here is a video of FreeCAD

http://blip.tv/file/get/Jpcasainho-FreeCAD_for_RepRapogv186.ogv

> I can see a GUI where you flip between editing OpenSCAD directly and
> using the GUI to move around pre-programed modules as black boxes with
> parameters.  This could potentially be a very powerful tool, rivaling
> even the power of Pro/Engineer or other commercial packages.

Now I am thinking you mean a GUI where you can just edit script
parameters using text boxes, that idea I like.

> http://tonybuser.com/cloudscad  is a step in the right direction.

Yeah I collaborate with the cloudscad team too.

Regards

Giles



Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

andy@kirbyand.co.uk
In reply to this post by Steven Dick
I sort of agree with some of what you are saying here.

If I was insitent on a GUI based limited parametric cad there is
Blender, Easy Cad, Heekscad. Or even commercial variants I have used
like Inventor, Pro/Desktop & Pro Engineer.....

SCADS power lays in that I should be able to code up a lump of code that
describes an object. I should be able to code it in a clever way
(Smart-objects) that lets me change a few simple parameters and all the
rest of the design recalculates itself.

Imagine having a Bearing pillow block that you just tell the outer
diameter, outer races shoulder width and the holes size for the bolts
you will mount it with and it does the rest. Scaling the design using
coded ratios. A realy smart object.

A bit like Inkscapes clever gear designer.

Katerina did a bunch of stuff along similar lines with her wonderful gears.

As it stands at the moment SCAD is wonderfully and brilliantly 60% maybe
80% of the way there. How much closer would puker variables make it ?????

There are some realy excellent pieces of work on Thingiverse. There is
also a degree of redundancy created by having parts that are only
scaled, by virtue of creating a duplicate of the design. Had they been
fully ratio/parametric one part could be used in many more designs
without redesign, just change the main variables at the head of the
file. (I even comment mine so someone else can use it without needing to
understand how the rest of the code works)

Graphic CAD is great I love it. It hasn't got the above potential though.

You could probably add a GUI to SCAD as it stands and have what everyone
else has done.

Why settle for second best.




On 12/09/10 22:29, Steven Dick wrote:

> On Sun, Sep 12, 2010 at 5:16 PM, Giles Bathgate <[hidden email]>wrote:
>
>> The only supported assignment operation in OpenSCAD is the
>> assign() function
>
>  [...]
>
>> Its annoying because assignments can only be made to variables that are
>> accessed in sub trees
>>
>>
> I have mixed feelings on this.  For programmers coming from other languages,
> this is confusing and annoying, and it does limit some things.
>
> However, it also prevents any possibility of having side effects, which
> makes the code more readable.
> Also, I'd like to see a more conventional GUI based cad system built on top
> of OpenSCAD, and allowing side effects and global changes of variables in
> the middle of code would make that difficult.
>
>
> I would rather see more flexible access to array elements than a more
> flexible assignment.
>
>
>
>
> _______________________________________________
> 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
Yup I agree

On 12/09/10 22:41, Giles Bathgate wrote:

> On Sun, 2010-09-12 at 17:29 -0400, Steven Dick wrote:
>> I have mixed feelings on this.  For programmers coming from other
>> languages, this is confusing and annoying, and it does limit some
>> things.
>
> I think OpenSCAD is targeted towards people who write scripts, or
> programs.
>
> (I always thought the S in the name was for "Script" as in: Open
> Scripted Computer Aided Design.)
>
>> However, it also prevents any possibility of having side effects,
>> which makes the code more readable.
>> Also, I'd like to see a more conventional GUI based cad system built
>> on top of OpenSCAD, and allowing side effects and global changes of
>> variables in the middle of code would make that difficult.
>
> If you want a GUI based 3D CAD maybe look at
>
> HeeksCAD http://code.google.com/p/heekscad/
> or
> FreeCAD
> http://sourceforge.net/apps/mediawiki/free-cad/index.php?title=Main_Page
>
>
>> I would rather see more flexible access to array elements than a more
>> flexible assignment.
>
> Yeah that would be good too.
>
> Regards
>
> Giles
>
>
>
> _______________________________________________
> 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
I feel that there are openings for all of these options.

As a coder I would prefer to write an object, and as a disciplined coder
I usually look for the general case. Avoiding filling my code full of
magic numbers.

I perhaps got carried away with SCAD as it is very reminiscent of Perl
and C in its syntax. So I naturally assumed (docs didn't say it
couldn't) I could use variables etc just the same.

Maybe it is worth adding a rider in the language docs on the wiki that
says where the limitations are, where you can/can't use variables and math.

I can see though where for a non coder that wants a little bit more the
code via forms model would be desirable and I think there is an opening
there. Cloud SCAD looks like it is going that way and there is perhaps
benefit in it. As a way to make SCAD accesible to the non coder and
maybe lure them into the murky world of coding it is great.

Personally if that was what I was limited to I would stick with
graphical cad choosing maybe Heeks, Easy, Pro/Desktop or Pro/Engineer. I
would find it limiting and frustrating. It is personal I doubt that
anyone else would look at it this way.

Overall there is a valid argument for having a more capable scripting
engine, supplying capability to a GUI front end that limits the users
ability to make a mess of things. As a hacker I want the full raw power
in my hands, I want to be able to unleash the full capabilities of that
scripting engine. Just by lifting the bonnet and using the engine
directly. Being greedy I want the engine to be able to do more than the
car's basic controls would let me do.



On 12/09/10 23:05, Giles Bathgate wrote:

> Hmm.. I don't think the idea is all that new. Nearly every commercial
> CAD package I have used has a scripting language back end, and the
> ability to edit modules in a parametric way....but anyway
>
> here is a video of FreeCAD
>
> http://blip.tv/file/get/Jpcasainho-FreeCAD_for_RepRapogv186.ogv
>
>> I can see a GUI where you flip between editing OpenSCAD directly and
>> using the GUI to move around pre-programed modules as black boxes with
>> parameters.  This could potentially be a very powerful tool, rivaling
>> even the power of Pro/Engineer or other commercial packages.
>
> Now I am thinking you mean a GUI where you can just edit script
> parameters using text boxes, that idea I like.
>
>> http://tonybuser.com/cloudscad  is a step in the right direction.
>
> Yeah I collaborate with the cloudscad team too.
>
> Regards
>
> Giles
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
>

Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Steven Dick
Of course, if we wanted to take OpenSCAD even further from a conventional programming language,
we would make constants work the same way functions and modules do now...

By that, I mean that you could declare them in any order, and they keep that value forever.
To make this work, you'd have to reduce them to actual values only after the entire program was read in.

Right now, it works this way in that it is a syntax error to set a value, use it to set another value, and then change it.
What I'm suggesting is to fix this, not by allowing reassignment of the value, but by making order of assignment irrelevant.

While this has some very large advantages (again, this would be another thing that would make a GUI interface to the language even easier), this would be even more confusing to conventional programmers.
Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

andy@kirbyand.co.uk
The language is so close to C and or Perl that I would be surprised (and
probably will be) if the grammar wasn't borrowed and cut down. Or at
least heavily influenced by some such.

Standing on the shoulders of giants and all that. (most sensible)

yacc, lex, bison etc are fairly mature tools and so are the grammars for
Perl, C and a bunch of other scripting tools.

It could be a case of borrowing some more to make it happen. (Not
necessary trivial though) Even "set variable" "$variable" is well
understood and could be cribbed from Bash or another shell script.

Given that the math can be stuffed into variable parameters for modules
and that you can do this also at the top of the module (local variables)
and file (Global Variables) C style scoping seems to be functional. It
is therefore a big surprise that you cant use the same assignments and
math on their own in the midst of loops or compound blocks "{ }" which
also work exactly as I intuited they might as a C programmer.

In using SCAD with say CloudSCAD it realy isn't necessary to use all of
this functionality even if it was added in. The GUI could run quite
happily with a subset. Adding in the extra should not make CloudSCAD
less functional or more difficult for a new user.






On 13/09/10 00:21, Steven Dick wrote:

> Of course, if we wanted to take OpenSCAD even further from a conventional
> programming language,
> we would make constants work the same way functions and modules do now...
>
> By that, I mean that you could declare them in any order, and they keep that
> value forever.
> To make this work, you'd have to reduce them to actual values only after the
> entire program was read in.
>
> Right now, it works this way in that it is a syntax error to set a value,
> use it to set another value, and then change it.
> What I'm suggesting is to fix this, not by allowing reassignment of the
> value, but by making order of assignment irrelevant.
>
> While this has some very large advantages (again, this would be another
> thing that would make a GUI interface to the language even easier), this
> would be even more confusing to conventional programmers.
>
>
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad

Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Steven Dick


On Sun, Sep 12, 2010 at 7:52 PM, [hidden email] <[hidden email]> wrote:
The language is so close to C and or Perl that I would be surprised (and
probably will be) if the grammar wasn't borrowed and cut down. Or at
least heavily influenced by some such.


The grammar has too many inconsistencies for that.
For example,  .9 is not a number but 0.9 is, where both would be accepted in most other languages.
This is something else I've considered fixing.

On 13/09/10 00:21, Steven Dick wrote:
> Of course, if we wanted to take OpenSCAD even further from a conventional
> programming language,
[...]

My point is that we should eventually choose which way to go...

Either move to a purely declarative language with no side effects and no order of declaration (except perhaps when objects are created), or move more towards a conventional programming language with real variables that can actually vary.  :)


Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Giles Bathgate-2
On Sun, 2010-09-12 at 20:00 -0400, Steven Dick wrote:
> The grammar has too many inconsistencies for that.
> For example,  .9 is not a number but 0.9 is, where both would be
> accepted in most other languages.
> This is something else I've considered fixing.

Thats a one line fix! Here is a patch to allow .x as-well as 0.x to be
treated as numbers:

diff --git a/src/lexer.l b/src/lexer.l
index 48729c8..4e76280 100644
--- a/src/lexer.l
+++ b/src/lexer.l
@@ -138 +138 @@ use[ \t\r\n>]*"<"[^ \t\r\n>]+">" {
-[0-9][0-9.]* { parserlval.number = QString(yytext).toDouble(); return
TOK_NUMBER; }
+[0-9.]* { parserlval.number = QString(yytext).toDouble(); return
TOK_NUMBER; }

Tomorrow I will write a patch for an assignment operator, then while you
two waste your time deciding whether or not OpenSCAD should be
declarative or procedural, I will email the maintainer and let him
decide whether or not to include my patches!

Regards

Giles.



Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Giles Bathgate-2
Actually that fix wasn't ideal here is a better fix.

diff --git a/src/lexer.l b/src/lexer.l
index 48729c8..3550fe5 100644
--- a/src/lexer.l
+++ b/src/lexer.l
@@ -138 +138 @@ use[ \t\r\n>]*"<"[^ \t\r\n>]+">" {
-[0-9][0-9.]* { parserlval.number = QString(yytext).toDouble(); return
TOK_NUMBER; }
+"."?[0-9][0-9.]* { parserlval.number = QString(yytext).toDouble();
return TOK_NUMBER; }

My point though really was that its a trivial change.

Regards

Giles.

Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

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

Dont get me wrong I dont care so long as I can get it to do what I need it to do. Happy to go with the flow.

It is realy good.

Unfortunately the lack of ability to do math and work with variables in certain places is proving to be an obstacle.

I will post the segment later on.


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

> On Sun, 2010-09-12 at 20:00 -0400, Steven Dick wrote:
> > The grammar has too many inconsistencies for that.
> > For example,   .9 is not a number but 0.9 is, where both would be
> > accepted in most other languages.
> > This is something else I've considered fixing.
>
> Thats a one line fix! Here is a patch to allow .x as-well as 0.x to be
> treated as numbers:
>
> diff --git a/src/lexer.l b/src/lexer.l
> index 48729c8..4e76280 100644
> --- a/src/lexer.l
> +++ b/src/lexer.l
> @@ -138 +138 @@ use[ \t\r\n>]*"<"[^ \t\r\n>]+">" {
> -[0-9][0-9.]* { parserlval.number = QString(yytext).toDouble(); return
> TOK_NUMBER; }
> +[0-9.]* { parserlval.number = QString(yytext).toDouble(); return
> TOK_NUMBER; }
>
> Tomorrow I will write a patch for an assignment operator, then while you
> two waste your time deciding whether or not OpenSCAD should be
> declarative or procedural, I will email the maintainer and let him
> decide whether or not to include my patches!
>
> Regards
>
> Giles.
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad


Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Steven Dick
In reply to this post by Giles Bathgate-2


On Mon, Sep 13, 2010 at 4:54 AM, Giles Bathgate <[hidden email]> wrote:
Actually that fix wasn't ideal here is a better fix.

diff --git a/src/lexer.l b/src/lexer.l
index 48729c8..3550fe5 100644
--- a/src/lexer.l
+++ b/src/lexer.l
@@ -138 +138 @@ use[ \t\r\n>]*"<"[^ \t\r\n>]+">" {
-[0-9][0-9.]* { parserlval.number = QString(yytext).toDouble(); return
TOK_NUMBER; }
+"."?[0-9][0-9.]*

That fix was not better than the first.

Actually, a bigger complaint is 0.4.4  is a number when it should not be.

I think a better fix is something like

[0-9]+|[0-9]+.[0-9]*|[0-9]*.[0-9]+

I'd be tempted to pull the correct one out of the C BNF or C lex file.

Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Steven Dick
In reply to this post by andy@kirbyand.co.uk


On Mon, Sep 13, 2010 at 5:14 AM, Andy Kirby <[hidden email]> wrote:
> Tomorrow I will write a patch for an assignment operator, then while you
> two waste your time deciding whether or not OpenSCAD should be
> declarative or procedural, I will email the maintainer and let him
> decide whether or not to include my patches!


Unfortunately, it'll be a pretty big patch, I think.

I looked at this a while back, and its a lot more than just patching the yacc code, or I would have already posted it.

You'll have to totally rework the way variables are stored too.

Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Giles Bathgate-2
In reply to this post by Steven Dick


> Actually, a bigger complaint is 0.4.4  is a number when it should not
> be.

Of course I assumed that the current implementation didn't allow 0.4.4
but as you point out it does!

Taking the lex from a C parser would probably be the way to go

Regards

Giles



Reply | Threaded
Open this post in threaded view
|

Re: Missing operators

Giles Bathgate-2
In reply to this post by Steven Dick
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



123