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

Richey

  • Full Member
  • ***
  • Posts: 144
    • View Profile
Re: DJPeter Math Solver in o2
« Reply #15 on: 26. July 2017, 23:28:29 »
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  :)

John

  • Sr. Member
  • ****
  • Posts: 362
    • View Profile
Re: DJPeter Math Solver in o2
« Reply #16 on: 27. July 2017, 07:39:04 »
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: 27. July 2017, 09:42:48 by John »

B+

  • Sr. Member
  • ****
  • Posts: 436
    • View Profile
Re: DJPeter Math Solver in o2
« Reply #17 on: 27. July 2017, 15:57:18 »
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: 27. July 2017, 16:31:35 by B+ »

Richey

  • Full Member
  • ***
  • Posts: 144
    • View Profile
Re: DJPeter Math Solver in o2
« Reply #18 on: 28. July 2017, 09:24:43 »
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

  • Newcomer
  • *
  • Posts: 27
    • View Profile
Re: DJPeter Math Solver in o2
« Reply #19 on: 28. July 2017, 17:26:44 »
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+

  • Sr. Member
  • ****
  • Posts: 436
    • View Profile
Re: DJPeter Math Solver in o2
« Reply #20 on: 28. July 2017, 18:43:48 »
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: 28. July 2017, 18:57:45 by B+ »

jbk

  • Newcomer
  • *
  • Posts: 27
    • View Profile
Re: DJPeter Math Solver in o2
« Reply #21 on: 28. July 2017, 19:32:06 »
thank yo B+  :)