discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Incrementing a variable doesn't work as expected.

N
nigeljohnson73
Wed, Apr 1, 2015 7:14 AM

I'm trying to do some morse code, but I'm struggling to work out the start
position of the 'dit' and the 'dah'... I think first, the code...

id=1;wt=1; // for a ring, don't worry about these
lu = 1; // letter unit. a dit is 1 unit wide, a dah is 3, and the gap
between them is 1.
module drawChar(s) {
echo("char: ", s);
pos = 0;
for(i = [0:len(s)-1]) {
inc = 0;
if(s[i] == ".") {
echo(s[i], "dit ",pos," ", inc);
translate([pos+lu/2,0,0]) cylinder(r=lu/2, h = (id+wt+2)/2);
inc = (1 + 1)lu;
} else if(s[i] == "-") {
echo(s[i], "dah ",pos," ", inc);
translate([pos,-lu/2,0]) cube([3
lu,lu,(id+wt+2)/2]);
inc = (3+1)*lu;
}
pos = pos + inc; // the inc seems to have gone out of scope
}
}
drawChar("--.-"); // this is a 'q'

This is the output:

ECHO: "char: ", "--.-"
ECHO: "-", "dah ", 0, " ", 4
ECHO: "-", "dah ", 0, " ", 4
ECHO: ".", "dit ", 0, " ", 2
ECHO: "-", "dah ", 0, " ", 4

I have tried many ways to calculate 'pos' - the starting point of the
dit/dah. So the bit that's getting me is the way assignments seem to work -
basically pos always stays zero. Also at the point of echoing inc, I'm
expecting it to still be zero.

2 questions I suppose, a learning point for me, what's going on? and second,
how do I make it do what I want it to do?

I was thinking of some way to count the occurances of '.' and '-' in the
array as a function multiplying accordingly, but my brain melted a little -
it is early.

Any help much appreciated
Nigel

--
View this message in context: http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I'm trying to do some morse code, but I'm struggling to work out the start position of the 'dit' and the 'dah'... I think first, the code... id=1;wt=1; // for a ring, don't worry about these lu = 1; // letter unit. a dit is 1 unit wide, a dah is 3, and the gap between them is 1. module drawChar(s) { echo("char: ", s); pos = 0; for(i = [0:len(s)-1]) { inc = 0; if(s[i] == ".") { echo(s[i], "dit ",pos," ", inc); translate([pos+lu/2,0,0]) cylinder(r=lu/2, h = (id+wt+2)/2); inc = (1 + 1)*lu; } else if(s[i] == "-") { echo(s[i], "dah ",pos," ", inc); translate([pos,-lu/2,0]) cube([3*lu,lu,(id+wt+2)/2]); inc = (3+1)*lu; } pos = pos + inc; // the inc seems to have gone out of scope } } drawChar("--.-"); // this is a 'q' This is the output: ECHO: "char: ", "--.-" ECHO: "-", "dah ", 0, " ", 4 ECHO: "-", "dah ", 0, " ", 4 ECHO: ".", "dit ", 0, " ", 2 ECHO: "-", "dah ", 0, " ", 4 I have tried many ways to calculate 'pos' - the starting point of the dit/dah. So the bit that's getting me is the way assignments seem to work - basically pos always stays zero. Also at the point of echoing inc, I'm expecting it to still be zero. 2 questions I suppose, a learning point for me, what's going on? and second, how do I make it do what I want it to do? I was thinking of some way to count the occurances of '.' and '-' in the array as a function multiplying accordingly, but my brain melted a little - it is early. Any help much appreciated Nigel -- View this message in context: http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271.html Sent from the OpenSCAD mailing list archive at Nabble.com.
N
nigeljohnson73
Wed, Apr 1, 2015 7:44 AM

For info, here is my recursive position counter that fails:

function cpos(s, n) = cpos(s,n-1) + (n == -1) ? (0) : ( (s[n]==".") ? 2 :
4);

when I use it instead of pos in the x coordinate for example in the dit:

translate([cpos(s,i)+lu/2,0,0]) cylinder(r=lu/2, h = (id+wt+2)/2);

it says recursion detected. It's not lying  but the manual says I can do
recursion with the trigraph stuff.

--
View this message in context: http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12272.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

For info, here is my recursive position counter that fails: function cpos(s, n) = cpos(s,n-1) + (n == -1) ? (0) : ( (s[n]==".") ? 2 : 4); when I use it instead of pos in the x coordinate for example in the dit: translate([cpos(s,i)+lu/2,0,0]) cylinder(r=lu/2, h = (id+wt+2)/2); it says recursion detected. It's not lying but the manual says I can do recursion with the trigraph stuff. -- View this message in context: http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12272.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Wed, Apr 1, 2015 8:32 AM

You can't modify variables, so not only is inc out of scope but you can't
change the value of pos.

Recursion is the right way to do it but you have infinite recursion because
you unconditionally call cpos(s,n-1).

On 1 April 2015 at 08:44, nigeljohnson73 nigel@nigeljohnson.net wrote:

For info, here is my recursive position counter that fails:

function cpos(s, n) = cpos(s,n-1) + (n == -1) ? (0) : ( (s[n]==".") ? 2 :
4);

when I use it instead of pos in the x coordinate for example in the dit:

translate([cpos(s,i)+lu/2,0,0]) cylinder(r=lu/2, h = (id+wt+2)/2);

it says recursion detected. It's not lying  but the manual says I can do
recursion with the trigraph stuff.

--
View this message in context:
http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12272.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

You can't modify variables, so not only is inc out of scope but you can't change the value of pos. Recursion is the right way to do it but you have infinite recursion because you unconditionally call cpos(s,n-1). On 1 April 2015 at 08:44, nigeljohnson73 <nigel@nigeljohnson.net> wrote: > For info, here is my recursive position counter that fails: > > function cpos(s, n) = cpos(s,n-1) + (n == -1) ? (0) : ( (s[n]==".") ? 2 : > 4); > > when I use it instead of pos in the x coordinate for example in the dit: > > translate([cpos(s,i)+lu/2,0,0]) cylinder(r=lu/2, h = (id+wt+2)/2); > > it says recursion detected. It's not lying but the manual says I can do > recursion with the trigraph stuff. > > > > > > -- > View this message in context: > http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12272.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
PF
Peter Falke
Wed, Apr 1, 2015 8:50 AM

Are ypu using a current version of OpenSCAD? The latest?

2015-04-01 9:44 GMT+02:00 nigeljohnson73 nigel@nigeljohnson.net:

For info, here is my recursive position counter that fails:

function cpos(s, n) = cpos(s,n-1) + (n == -1) ? (0) : ( (s[n]==".") ? 2 :
4);

when I use it instead of pos in the x coordinate for example in the dit:

translate([cpos(s,i)+lu/2,0,0]) cylinder(r=lu/2, h = (id+wt+2)/2);

it says recursion detected. It's not lying  but the manual says I can do
recursion with the trigraph stuff.

--
View this message in context:
http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12272.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
stempeldergeschichte@googlemail.com karsten@rohrbach.de

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu
schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!

Are ypu using a current version of OpenSCAD? The latest? 2015-04-01 9:44 GMT+02:00 nigeljohnson73 <nigel@nigeljohnson.net>: > For info, here is my recursive position counter that fails: > > function cpos(s, n) = cpos(s,n-1) + (n == -1) ? (0) : ( (s[n]==".") ? 2 : > 4); > > when I use it instead of pos in the x coordinate for example in the dit: > > translate([cpos(s,i)+lu/2,0,0]) cylinder(r=lu/2, h = (id+wt+2)/2); > > it says recursion detected. It's not lying but the manual says I can do > recursion with the trigraph stuff. > > > > > > -- > View this message in context: > http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12272.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > -- stempeldergeschichte@googlemail.com <karsten@rohrbach.de> P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben. Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen. P.S. In case my e-mail is shorter than you enjoy: I am currently trying short replies instead of no replies at all. Please let me know, if you like to read more. Enjoy!
N
nigeljohnson73
Wed, Apr 1, 2015 8:51 AM

Doh!!! yep.

I moved the conditional calling, but this is still not playing nicely:

function cpos(s, n) = (n == -1) ? (0) : ( cpos(s,n-1) + (s[n]==".") ? 2 : 4
);

echo ("--.-, 0: ", cpos("--.",0));
echo ("--.-, 1: ", cpos("--.",1));
echo ("--.-, 2: ", cpos("--.",2));
echo ("--.-, 3: ", cpos("--.",3));

ECHO: "--.-, 0: ", 4
ECHO: "--.-, 1: ", 4
ECHO: "--.-, 2: ", 4
ECHO: "--.-, 3: ", 4

I have also noticed a problem in that 0 should be 0 which I'll fix later,
but that aside, I would expect the following

ECHO: "--.-, 0: ", 4
ECHO: "--.-, 1: ", 8
ECHO: "--.-, 2: ", 10
ECHO: "--.-, 3: ", 14

--
View this message in context: http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12275.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Doh!!! yep. I moved the conditional calling, but this is still not playing nicely: function cpos(s, n) = (n == -1) ? (0) : ( cpos(s,n-1) + (s[n]==".") ? 2 : 4 ); echo ("--.-, 0: ", cpos("--.",0)); echo ("--.-, 1: ", cpos("--.",1)); echo ("--.-, 2: ", cpos("--.",2)); echo ("--.-, 3: ", cpos("--.",3)); ECHO: "--.-, 0: ", 4 ECHO: "--.-, 1: ", 4 ECHO: "--.-, 2: ", 4 ECHO: "--.-, 3: ", 4 I have also noticed a problem in that 0 should be 0 which I'll fix later, but that aside, I would expect the following ECHO: "--.-, 0: ", 4 ECHO: "--.-, 1: ", 8 ECHO: "--.-, 2: ", 10 ECHO: "--.-, 3: ", 14 -- View this message in context: http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12275.html Sent from the OpenSCAD mailing list archive at Nabble.com.
N
nigeljohnson73
Wed, Apr 1, 2015 8:52 AM

Sorry, yep, I'm using the latest release 2015.03 on both mac and windows

--
View this message in context: http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12276.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Sorry, yep, I'm using the latest release 2015.03 on both mac and windows -- View this message in context: http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12276.html Sent from the OpenSCAD mailing list archive at Nabble.com.
PF
Peter Falke
Wed, Apr 1, 2015 8:54 AM

You can not reassign variables. Variables in OpenSCAD are constants.
Please have a look at the manual:
http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Variables

2015-04-01 10:50 GMT+02:00 Peter Falke stempeldergeschichte@googlemail.com
:

Are ypu using a current version of OpenSCAD? The latest?

2015-04-01 9:44 GMT+02:00 nigeljohnson73 nigel@nigeljohnson.net:

For info, here is my recursive position counter that fails:

function cpos(s, n) = cpos(s,n-1) + (n == -1) ? (0) : ( (s[n]==".") ? 2 :
4);

when I use it instead of pos in the x coordinate for example in the dit:

translate([cpos(s,i)+lu/2,0,0]) cylinder(r=lu/2, h = (id+wt+2)/2);

it says recursion detected. It's not lying  but the manual says I can do
recursion with the trigraph stuff.

--
View this message in context:
http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12272.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
stempeldergeschichte@googlemail.com karsten@rohrbach.de

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu
schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!

--
stempeldergeschichte@googlemail.com karsten@rohrbach.de

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu
schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!

You can not reassign variables. Variables in OpenSCAD are constants. Please have a look at the manual: http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Variables 2015-04-01 10:50 GMT+02:00 Peter Falke <stempeldergeschichte@googlemail.com> : > Are ypu using a current version of OpenSCAD? The latest? > > > 2015-04-01 9:44 GMT+02:00 nigeljohnson73 <nigel@nigeljohnson.net>: > >> For info, here is my recursive position counter that fails: >> >> function cpos(s, n) = cpos(s,n-1) + (n == -1) ? (0) : ( (s[n]==".") ? 2 : >> 4); >> >> when I use it instead of pos in the x coordinate for example in the dit: >> >> translate([cpos(s,i)+lu/2,0,0]) cylinder(r=lu/2, h = (id+wt+2)/2); >> >> it says recursion detected. It's not lying but the manual says I can do >> recursion with the trigraph stuff. >> >> >> >> >> >> -- >> View this message in context: >> http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12272.html >> Sent from the OpenSCAD mailing list archive at Nabble.com. >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> > > > > -- > stempeldergeschichte@googlemail.com <karsten@rohrbach.de> > > P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: > Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu > schreiben. > Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen. > > P.S. In case my e-mail is shorter than you enjoy: > I am currently trying short replies instead of no replies at all. > Please let me know, if you like to read more. > > Enjoy! > -- stempeldergeschichte@googlemail.com <karsten@rohrbach.de> P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben. Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen. P.S. In case my e-mail is shorter than you enjoy: I am currently trying short replies instead of no replies at all. Please let me know, if you like to read more. Enjoy!
N
nigeljohnson73
Wed, Apr 1, 2015 8:56 AM

Yep, I'm now using recursion to bypass that :) but it seems I'm a bit rusty
at that as well.

--
View this message in context: http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12278.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Yep, I'm now using recursion to bypass that :) but it seems I'm a bit rusty at that as well. -- View this message in context: http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12278.html Sent from the OpenSCAD mailing list archive at Nabble.com.
PF
Peter Falke
Wed, Apr 1, 2015 9:00 AM
           pos = pos + inc; // the inc seems to have gone out of scope

This is the problem: this is the last definition for pos, so only this one
is used (pos=0 will be ignored).
And it is undefined, as when the left side is assigned the right side has
no meaning,yet. Its a recursion.

2015-04-01 10:54 GMT+02:00 Peter Falke stempeldergeschichte@googlemail.com
:

You can not reassign variables. Variables in OpenSCAD are constants.
Please have a look at the manual:

http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Variables

2015-04-01 10:50 GMT+02:00 Peter Falke <
stempeldergeschichte@googlemail.com>:

Are ypu using a current version of OpenSCAD? The latest?

2015-04-01 9:44 GMT+02:00 nigeljohnson73 nigel@nigeljohnson.net:

For info, here is my recursive position counter that fails:

function cpos(s, n) = cpos(s,n-1) + (n == -1) ? (0) : ( (s[n]==".") ? 2 :
4);

when I use it instead of pos in the x coordinate for example in the dit:

translate([cpos(s,i)+lu/2,0,0]) cylinder(r=lu/2, h = (id+wt+2)/2);

it says recursion detected. It's not lying  but the manual says I can do
recursion with the trigraph stuff.

--
View this message in context:
http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12272.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
stempeldergeschichte@googlemail.com karsten@rohrbach.de

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu
schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!

--
stempeldergeschichte@googlemail.com karsten@rohrbach.de

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu
schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!

--
stempeldergeschichte@googlemail.com karsten@rohrbach.de

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu
schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!

pos = pos + inc; // the inc seems to have gone out of scope This is the problem: this is the last definition for pos, so only this one is used (pos=0 will be ignored). And it is undefined, as when the left side is assigned the right side has no meaning,yet. Its a recursion. 2015-04-01 10:54 GMT+02:00 Peter Falke <stempeldergeschichte@googlemail.com> : > You can not reassign variables. Variables in OpenSCAD are constants. > Please have a look at the manual: > > http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Variables > > 2015-04-01 10:50 GMT+02:00 Peter Falke < > stempeldergeschichte@googlemail.com>: > >> Are ypu using a current version of OpenSCAD? The latest? >> >> >> 2015-04-01 9:44 GMT+02:00 nigeljohnson73 <nigel@nigeljohnson.net>: >> >>> For info, here is my recursive position counter that fails: >>> >>> function cpos(s, n) = cpos(s,n-1) + (n == -1) ? (0) : ( (s[n]==".") ? 2 : >>> 4); >>> >>> when I use it instead of pos in the x coordinate for example in the dit: >>> >>> translate([cpos(s,i)+lu/2,0,0]) cylinder(r=lu/2, h = (id+wt+2)/2); >>> >>> it says recursion detected. It's not lying but the manual says I can do >>> recursion with the trigraph stuff. >>> >>> >>> >>> >>> >>> -- >>> View this message in context: >>> http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12272.html >>> Sent from the OpenSCAD mailing list archive at Nabble.com. >>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> Discuss@lists.openscad.org >>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>> >> >> >> >> -- >> stempeldergeschichte@googlemail.com <karsten@rohrbach.de> >> >> P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: >> Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu >> schreiben. >> Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen. >> >> P.S. In case my e-mail is shorter than you enjoy: >> I am currently trying short replies instead of no replies at all. >> Please let me know, if you like to read more. >> >> Enjoy! >> > > > > -- > stempeldergeschichte@googlemail.com <karsten@rohrbach.de> > > P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: > Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu > schreiben. > Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen. > > P.S. In case my e-mail is shorter than you enjoy: > I am currently trying short replies instead of no replies at all. > Please let me know, if you like to read more. > > Enjoy! > -- stempeldergeschichte@googlemail.com <karsten@rohrbach.de> P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben. Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen. P.S. In case my e-mail is shorter than you enjoy: I am currently trying short replies instead of no replies at all. Please let me know, if you like to read more. Enjoy!
N
nigeljohnson73
Wed, Apr 1, 2015 9:14 AM

Yeah I'm not doing that any more because it doesn't work. I've moved to
recursion. Possibly an email lag?

This is what is now not working:

function cpos(s, n) = (n == -1) ? (0) : ( cpos(s,n-1) + (s[n]==".") ? 2 : 4
);

cpos("--.-",3) returns 4, instead of 14.

--
View this message in context: http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12280.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Yeah I'm not doing that any more because it doesn't work. I've moved to recursion. Possibly an email lag? This is what is now not working: function cpos(s, n) = (n == -1) ? (0) : ( cpos(s,n-1) + (s[n]==".") ? 2 : 4 ); cpos("--.-",3) returns 4, instead of 14. -- View this message in context: http://forum.openscad.org/Incrementing-a-variable-doesn-t-work-as-expected-tp12271p12280.html Sent from the OpenSCAD mailing list archive at Nabble.com.