1. Matheval ... the next step (for me)

I know this should be a simple thing to accomplish, but I'm having trouble
wrapping my head around it.  All I want to do is take two Matheval variables and
add them in a block and then output them.

This works to put something into mySequence:

block(
(mySequence := "I know this works 3 times")
)

Which I can dig out in my Euphoria code without much difficulty.

What I'd like to do is this:

block(
x := 1,
y := 2,
(mySequence := "I know this works " & {STR,{ADD,x,y},{}} & " times")
)

Is what I want to do possible?

Thanks

Mike

new topic     » topic index » view message » categorize

2. Re: Matheval ... the next step (for me)

Mike777 wrote:
> 
> What I'd like to do is this:
> 
> block(
> x := 1,
> y := 2,
> (mySequence := "I know this works " & {STR,{ADD,x,y},{}} & " times")
> )
> 
> Is what I want to do possible?

That should work, but due to a bug in the parsing routine for STR, it
doesn't.  In texteval.e, change CStr to this:
function CStr( sequence expr, integer tok )
    if tok = length( expr ) or (not CheckCollapsed({expr[tok+1]}))  then
        return {{INVALID, "Missing argument for STR()", {}}}
    end if

    expr[tok][ARG1] = expr[tok+1]
    return expr[1..tok] & expr[tok+2..length(expr)] 
end function


Matt

new topic     » goto parent     » topic index » view message » categorize

3. Re: Matheval ... the next step (for me)

Matt Lewis wrote:
> 
> Mike777 wrote:
> > 
> > What I'd like to do is this:
> > 
> > block(
> > x := 1,
> > y := 2,
> > (mySequence := "I know this works " & {STR,{ADD,x,y},{}} & " times")
> > )
> > 
> > Is what I want to do possible?
> 
> That should work, but due to a bug in the parsing routine for STR, it
> doesn't.  In texteval.e, change CStr to this:
> }}}
<eucode>
> function CStr( sequence expr, integer tok )
>     if tok = length( expr ) or (not CheckCollapsed({expr[tok+1]}))  then
>         return {{INVALID, "Missing argument for STR()", {}}}
>     end if
> 
>     expr[tok][ARG1] = expr[tok+1]
>     return expr[1..tok] & expr[tok+2..length(expr)] 
> end function
> </eucode>
{{{


Wow!  Are you sure this isn't IRC?

Well, the good news is that it now runs.  The bad news is that any line with the
STR function on it disappears.  I have tested the equivalent of:

BLOCK(
(mySeq := "Test"),
x := 1,
y := 2,
(mySeq := mySeq & {STR,{ADD,x,y},{}} ),
(mySeq := mySeq & mySeq)
)

I get "TestTest".  Nothing between the two tests.

Any suggestions at this point?

Thanks again.

Mike

new topic     » goto parent     » topic index » view message » categorize

4. Re: Matheval ... the next step (for me)

Mike777 wrote:
> 
> Matt Lewis wrote:
> > 
> > Mike777 wrote:
> > > 
> > > What I'd like to do is this:
> > > 
> > > block(
> > > x := 1,
> > > y := 2,
> > > (mySequence := "I know this works " & {STR,{ADD,x,y},{}} & " times")
> > > )
> > > 
> > > Is what I want to do possible?
> > 
> > That should work, but due to a bug in the parsing routine for STR, it
> > doesn't.  In texteval.e, change CStr to this:
> > }}}
<eucode>
> > function CStr( sequence expr, integer tok )
> >     if tok = length( expr ) or (not CheckCollapsed({expr[tok+1]}))  then
> >         return {{INVALID, "Missing argument for STR()", {}}}
> >     end if
> > 
> >     expr[tok][ARG1] = expr[tok+1]
> >     return expr[1..tok] & expr[tok+2..length(expr)] 
> > end function
> > </eucode>
{{{

> 
> Wow!  Are you sure this isn't IRC?
> 
> Well, the good news is that it now runs.  The bad news is that any line with
> the STR function on it disappears.  I have tested the equivalent of:
> 
> BLOCK(
> (mySeq := "Test"),
> x := 1,
> y := 2,
> (mySeq := mySeq & {STR,{ADD,x,y},{}} ),
> (mySeq := mySeq & mySeq)
> )
> 
> I get "TestTest".  Nothing between the two tests.
> 
> Any suggestions at this point?
> 
> Thanks again.

Further testing shows that the return from the CStr function is always the error
condition, which causes Matheval to discared the statement it is embedded in.  I
have tried many, many versions of the STR function (with quotes, without quotes,
with double quotes, without double quotes, with 1 argument filled in and the
second one empty, etc.).  All return the error condition (which I confirm with a
pretty print of all the matheval results, as per the documentation).

Mike

new topic     » goto parent     » topic index » view message » categorize

5. Re: Matheval ... the next step (for me)

Mike777 wrote:
> 
> > 
> > Well, the good news is that it now runs.  The bad news is that any line
> > with the STR function on it disappears.  I have tested the equivalent of:
> > 
> > BLOCK(
> > (mySeq := "Test"),
> > x := 1,
> > y := 2,
> > (mySeq := mySeq & {STR,{ADD,x,y},{}} ),
> > (mySeq := mySeq & mySeq)
> > )
> > 
> > I get "TestTest".  Nothing between the two tests.
> > 
> > Any suggestions at this point?
> > 
> > Thanks again.
> 
> Further testing shows that the return from the CStr function is always 
> the error condition, which causes Matheval to discared the statement it
> is embedded in.  I have tried many, many versions of the STR function
> (with quotes, without quotes, with double quotes, without double quotes,
> with 1 argument filled in and the second one empty, etc.).  All return
> the error condition (which I confirm with a pretty print of all the
> matheval results, as per the documentation).
> 

I added "include texteval.e" to mathdemo.exw and here's what I got:

Enter expression: "test" & str(1+4) & "foo"
    Result: {test5foo}
Simplified: {test5foo}

You say, "equivalent."  What exactly did you try?

Matt

new topic     » goto parent     » topic index » view message » categorize

6. Re: Matheval ... the next step (for me)

Matt Lewis wrote:
> 
> Mike777 wrote:
> > 
> > > 
> > > Well, the good news is that it now runs.  The bad news is that any line
> > > with the STR function on it disappears.  I have tested the equivalent of:
> > > 
> > > BLOCK(
> > > (mySeq := "Test"),
> > > x := 1,
> > > y := 2,
> > > (mySeq := mySeq & {STR,{ADD,x,y},{}} ),
> > > (mySeq := mySeq & mySeq)
> > > )
> > > 
> > > I get "TestTest".  Nothing between the two tests.
> > > 
> > > Any suggestions at this point?
> > > 
> > > Thanks again.
> > 
> > Further testing shows that the return from the CStr function is always 
> > the error condition, which causes Matheval to discared the statement it
> > is embedded in.  I have tried many, many versions of the STR function
> > (with quotes, without quotes, with double quotes, without double quotes,
> > with 1 argument filled in and the second one empty, etc.).  All return
> > the error condition (which I confirm with a pretty print of all the
> > matheval results, as per the documentation).
> > 
> 
> I added "include texteval.e" to mathdemo.exw and here's what I got:
> 
> Enter expression: "test" & str(1+4) & "foo"
>     Result: {test5foo}
> Simplified: {test5foo}

As do I.
 
> You say, "equivalent."  What exactly did you try?

I'm doing mine through the Block function, though.  So, I have a working Block
file (about 40 lines) and I have variable names which are not mySequence, x and
y, but they don't mean anything in the context of debugging.

So, other than drop off about 35 lines the Block is as indicated.  In other
words, it works fine, but the return from CStr is always an error indicator when
called from the Block.

Let me fiddle with the demo program for a minute or two and then I'll come back
and say more.

Mike

new topic     » goto parent     » topic index » view message » categorize

7. Re: Matheval ... the next step (for me)

Mike777 wrote:
> 
> Matt Lewis wrote:
> > 
> > Mike777 wrote:
> > > 
> > > > 
> > > > Well, the good news is that it now runs.  The bad news is that any line
> > > > with the STR function on it disappears.  I have tested the equivalent
> > > > of:
> > > > 
> > > > BLOCK(
> > > > (mySeq := "Test"),
> > > > x := 1,
> > > > y := 2,
> > > > (mySeq := mySeq & {STR,{ADD,x,y},{}} ),
> > > > (mySeq := mySeq & mySeq)
> > > > )
> > > > 
> > > > I get "TestTest".  Nothing between the two tests.
> > > > 
> > > > Any suggestions at this point?
> > > > 
> > > > Thanks again.
> > > 
> > > Further testing shows that the return from the CStr function is always 
> > > the error condition, which causes Matheval to discared the statement it
> > > is embedded in.  I have tried many, many versions of the STR function
> > > (with quotes, without quotes, with double quotes, without double quotes,
> > > with 1 argument filled in and the second one empty, etc.).  All return
> > > the error condition (which I confirm with a pretty print of all the
> > > matheval results, as per the documentation).
> > > 
> > 
> > I added "include texteval.e" to mathdemo.exw and here's what I got:
> > 
> > Enter expression: "test" & str(1+4) & "foo"
> >     Result: {test5foo}
> > Simplified: {test5foo}
> 
> As do I.
>  
> > You say, "equivalent."  What exactly did you try?
> 
> I'm doing mine through the Block function, though.  So, I have a working Block
> file (about 40 lines) and I have variable names which are not mySequence, x
> and y, but they don't mean anything in the context of debugging.
> 
> So, other than drop off about 35 lines the Block is as indicated.  In other
> words, it works fine, but the return from CStr is always an error indicator
> when called from the Block.
> 
> Let me fiddle with the demo program for a minute or two and then I'll come
> back
> and say more.

I had used the above syntax:

(mySeq := mySeq & {STR,{ADD,x,y},{}} ),

When I replace that with:

(mySeq := mySeq & STR(x+y) ),

It works a treat.

Thanks.

Now, one (hopefully final, but they never are, are they?) question.  I have a
string that I know is a number:

x := "1"

I want to convert it to a number for purposes of putting it into my sample line
of code:

(mySeq := mySeq & STR{x+y) ),

I've tried a few variations of VAL, but haven't hit the right combination, yet.
What should work?

Thanks

Mike

new topic     » goto parent     » topic index » view message » categorize

8. Re: Matheval ... the next step (for me)

Mike777 wrote:

> I had used the above syntax:
> 
> (mySeq := mySeq & {STR,{ADD,x,y},{}} ),
> 
> When I replace that with:
> 
> (mySeq := mySeq & STR(x+y) ),
> 
> It works a treat.
> 
> Thanks.
> 
> Now, one (hopefully final, but they never are, are they?) question.  I have
> a string that I know is a number:
> 
> x := "1"
> 
> I want to convert it to a number for purposes of putting it into my sample
> line
> of code:
> 
> (mySeq := mySeq & STR{x+y) ),
> 
> I've tried a few variations of VAL, but haven't hit the right combination,
> yet.
> What should work?

OK, my problem was that I was using the internal formatting, which is
{OP,VAR1,VAR2} where VAR1 = {DATA or CONSTANT, ARG1, ARG2} syntax.  The correct
syntax is the simple, it should work that way but somehow I didn't think it did,
way, which is:

VAL(x).

I think this calls for a.......

DUH!

Thanks

Mike

new topic     » goto parent     » topic index » view message » categorize

9. Re: Matheval ... the next step (for me)

Mike777 wrote:
> 
> OK, my problem was that I was using the internal formatting, which is
> {OP,VAR1,VAR2}
> where VAR1 = {DATA or CONSTANT, ARG1, ARG2} syntax.  The correct syntax is the
> simple, it should work that way but somehow I didn't think it did, way, which
> is:
> 
> VAL(x).

Yeah, the {OP,VAR1,VAR2} syntax is for creating matheval sequences in code.
Anything you pass to the parser should be simpler and easier to read, and
generally read like you'd expect an equation or whatever to look like.

Matt

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu