Author Topic: DJPeter Math Solver in o2  (Read 5358 times)

Richly

  • Guest
Re: DJPeter Math Solver in o2
« Reply #15 on: July 26, 2017, 09:28:29 PM »
I thought that most BASICs had some sort of EVAL function built in that can evaluate pretty much any expression you care to give it? I know Sinclair BASIC back in '82 (and possible as far back as '80) definitely had one.

Code: [Select]
5 REM Sinclair BASIC and SpecBAS
10 PRINT VAL ("1 + 2")
20 STOP

Yes, the old ones (and the re-imagined old ones  ;)) are the best  :)

ScriptBasic

  • Guest
Re: DJPeter Math Solver in o2
« Reply #16 on: July 27, 2017, 05:39:04 AM »
I cleaned up the Script BASIC EVAL function to make it more traditional.

Code: [Select]
IMPORT sbt.sbi

FUNCTION EVAL(expcode)
 sb = SB_New()
 SB_LoadStr(sb, "result = " & expcode)
 SB_Run(sb, "")
 EVAL = SB_GetVar(sb, "main::result")
 SB_Destroy(sb)
END FUNCTION

PRINT EVAL("2 ^ 4"),"\n"
PRINT EVAL("(10 + 6) / 4"),"\n"
PRINT FORMAT("%.3f",EVAL("SQR(3)")),"\n"
PRINT EVAL("""\"Hello " & "World\""""),"\n"

EVAL("""0
FOR x = 1 TO 5
   PRINT x,"\\n"
NEXT""")


jrs@jrs-laptop:~/sb/examples/test$ time scriba eval.sb
16
4
1.732
Hello World
1
2
3
4
5

real   0m0.009s
user   0m0.008s
sys   0m0.004s
jrs@jrs-laptop:~/sb/examples/test$




« Last Edit: July 27, 2017, 07:42:48 AM by John »

B+

  • Guest
Re: DJPeter Math Solver in o2
« Reply #17 on: July 27, 2017, 01:57:18 PM »
EVAL...It is in Liberty Basic and maybe the LB Booster (I think, if Richey is still looking in he might verify.)

I still check in now and again when I can find the time  :)

Yes, LBB does indeed have EVAL

Code: [Select]
PRINT EVAL ("1 + 2")
END

output = 3

Btw I'm not sure why people still use JB when LBB is also free to download and use and has the additional advantage of having all of the features of Liberty BASIC (which JB does not) but without the bugs  ::)

Hi Richey!

Hey you're still alive! You make a fine point about JB and I did forget about LB also!!!

I have recently downloaded it again but I have been distracted by FreeBasic and then QB64. Both have very active forums with experienced people and smart wits ta boot! I learn my ship through forums now that they don't write books for this stuff. People are more fun than books anyway, ... well... they can be. ;-))

PS It was the EVAL with () that Richard posted at JB forum that had me downloading LBB again. Alas, that post, that whole thread was deleted without explanation.  >:(
« Last Edit: July 27, 2017, 02:31:35 PM by B+ »

Richly

  • Guest
Re: DJPeter Math Solver in o2
« Reply #18 on: July 28, 2017, 07:24:43 AM »
Hey you're still alive! You make a fine point about JB and I did forget about LB also!!!...I learn my ship through forums now that they don't write books for this stuff. People are more fun than books anyway, ... well... they can be. ;-))

PS It was the EVAL with () that Richard posted at JB forum that had me downloading LBB again. Alas, that post, that whole thread was deleted without explanation.  >:(

Hi B+

 :)

You could always still visit the JB forum but have you thought about joining the LB Booster conforum as well? I see that Aurel is a member. I'm sure that Richard and the community would appreciate your code examples, which you could post under the 'Showcase' section.

Best wishes

Richey

jbk

  • Guest
Re: DJPeter Math Solver in o2
« Reply #19 on: July 28, 2017, 03:26:44 PM »
PS It was the EVAL with () that Richard posted at JB forum that had me downloading LBB again. Alas, that post, that whole thread was deleted without explanation.  >:(
hello B+, can you re-post Richard's eval? I am curious.

B+

  • Guest
Re: DJPeter Math Solver in o2
« Reply #20 on: July 28, 2017, 04:43:48 PM »
Hi jbk,

As close as I can get is here:
http://lbb.conforums.com/index.cgi?board=code&action=display&num=1500109758

The one with parenthesis posted at JB didn't seem any longer than that. Richard even asked if anyone could make a shorter one.

In fact, as I remember the one at JB, it seemed shorter!

The tricks of memory? Like the fish that got away keeps getting bigger and bigger with every retelling of the story. :)

PS (To continue my teaser from "Write a program..." thread in Discussion Board):
I have something very short and sweet. It totally by passes PCP worries and the use of parenthesis. But alas, it leaves allot more work to coder. I have found the bug that has plagued me for some time, just need to test more and write up a document (it needs some explaining because so short). Stay tuned...
« Last Edit: July 28, 2017, 04:57:45 PM by B+ »

jbk

  • Guest
Re: DJPeter Math Solver in o2
« Reply #21 on: July 28, 2017, 05:32:06 PM »
thank yo B+  :)