Code: Select all
' BBC BASIC Fern - RPi
IMPORT bbc.bas
BBC::OPEN "ScriptBasic BBC fern - Raspberry Pi"
t1 = BBC::TIME()
BBC::MODE 31
BBC::ORIGIN 200, 100
BBC::OFF
BBC::GCOL 0, 10
x = 0
y = 0
FOR i = 1 TO 80000
r = BBC::RND(1)
IF r <= 0.1 THEN
a = 0
b = 0
c = 0
d = 0.16
e = 0
f = 0
END IF
IF r > 0.1 AND r <= 0.86 THEN
a = .85
b = .04
c = -.04
d = .85
e = 0
f = 1.6
END IF
IF r > 0.86 AND r <= 0.93 THEN
a = .2
b = -.26
c = .23
d = .22
e = 0
f = 1.6
END IF
IF r > 0.93 THEN
a = -.15
b = .28
c = .26
d = .24
e = 0
f = .44
END IF
newx = a * x + b * y + e
newy = c * x + d * y + f
x = newx
y = newy
BBC::MOVE 600 + 96 * x, 32 + 96 * y
BBC::DRAW 600 + 96 * x, 32 + 96 * y
NEXT i
t2 = BBC::TIME()
t3 = (t2-t1)/1000
BBC::VDUSTR "Time: " & FORMAT("%.4f",t3) & " seconds"
BBC::WAITKEY
BBC::CLOSE
There is no script for the included external libs, I did that manually.
BTW, to eliminate the requirement that the esd.pm module be installed (which requires root), edit setup.pl.
After the #!/usr/bin/perl add the following:Then at line 177 change:Code: Select all
use Cwd qw(cwd);
toCode: Select all
$esdlocation = undef;
This tells the setup.pl file to use the esd.pm that is in the current (sb-dev if using the source from git) folder.Code: Select all
$esdlocation = cwd;
AIR.
A bit unfair there, your Python program first calculates each Fibonacci number from 0 to n-1 individually and them finally calculates and prints Fibonacci(n) whilst your ScriptBasic just calculates and prints Fibonacci(n). Also your Basic prints Fibonacci(24) whilst you had Python print Fibonacci(25).ScriptBasic wrote: ↑Sun Apr 07, 2019 3:38 amHere is the Fibonacci recursive benchmark for Python and ScriptBasic.
Python (Parcially Recursive)Code: Select all
def recur_fibo(n): if n <= 1: return n else: return(recur_fibo(n-1) + recur_fibo(n-2)) nterms = 25 if nterms <= 0: print("Plese enter a positive integer") else: for i in range(nterms): recur_fibo(i) print(recur_fibo(i))
[email protected]:~/sbrpi/examples $ time python fibonacci.py
46368
real 0m0.764s
user 0m0.726s
sys 0m0.030s
[email protected]:~/sbrpi/examples $
ScriptBasic (true recursive function)[email protected]:~/sbrpi/examples $ time scriba fibonacci.sbCode: Select all
FUNCTION Fibonacci(n) IF n <= 2 THEN Fibonacci = 1 ELSE Fibonacci = Fibonacci(n - 1) + Fibonacci(n - 2) END IF END FUNCTION PRINT Fibonacci(24),"\n"
46368
real 0m0.863s
user 0m0.858s
sys 0m0.001s
[email protected]:~/sbrpi/examples $
Code: Select all
def recur_fibo(n):
if n <= 1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))
print(recur_fibo(24))
Where is the timing information? Have you gotten ScriptBasic to run on your Pi yet?scruss wrote: ↑Sun Apr 07, 2019 1:31 pmRe the ScriptBASIC Fern code, BBC BASIC for SDL ran the same demo on a 3B+ in about 4 seconds. Sure, a 3B+ is a little faster than a 3B, but your (compiled?) ScriptBASIC demo was much slower.
Richard's BBC BASIC isn't open source and is a BASIC compiler. The BBC graphics extension module is a fork of Brandy's SDL BBC code.scruss wrote: ↑Sun Apr 07, 2019 1:31 pmRe the ScriptBASIC Fern code, BBC BASIC for SDL ran the same demo on a 3B+ in about 4 seconds. Sure, a 3B+ is a little faster than a 3B, but your (compiled?) ScriptBASIC demo was much slower.
Have you got anything to back that up?ScriptBasic wrote: ↑Sun Apr 07, 2019 5:13 pmBottom line is BASIC is easier to learn than Python and for the most part beginners is our audience.
Since about a year Richard's BBC Basic has been open source. The repository is here.ScriptBasic wrote: ↑Sun Apr 07, 2019 5:41 pmRichard's BBC BASIC isn't open source and is a BASIC compiler. The BBC graphics extension module is a fork of Brandy's SDL BBC code.scruss wrote: ↑Sun Apr 07, 2019 1:31 pmRe the ScriptBASIC Fern code, BBC BASIC for SDL ran the same demo on a 3B+ in about 4 seconds. Sure, a 3B+ is a little faster than a 3B, but your (compiled?) ScriptBASIC demo was much slower.
Good to know. I purchased his Windows version a few years ago.Since about a year Richard's BBC Basic has been open source.
This webpage appears to be a well thought out introduction-to-computing class for ages 12 to 13 years old. As part of the course description the teacherrpdom wrote: ↑Sun Apr 07, 2019 5:56 pmHave you got anything to back that up?ScriptBasic wrote: ↑Sun Apr 07, 2019 5:13 pmBottom line is BASIC is easier to learn than Python and for the most part beginners is our audience.
I teach kids to code. Some of them use Python. They pick it up fairly quickly. I suspect they would have more trouble picking up (yet another version of) BASIC.
The only thing that takes a little getting used to on Python (especially if you are used to other languages) is that crazy indentation thing.
Therefore, some people think Basic makes a better introduction than even Scratch.Craig Whitmore wrote:We will begin with basic programming, using an application called Chipmunk Basic.... We will continue on to a more modern visual programming language, Scratch.
ScriptBasic can run Dartmouth BASIC code untouched. (except for the DATA statement which I use SPLIT for) I've ported many QuickBasic programs as well. The COM extension module works with VB6. What other BASIC has that kind of syntax flexability?I teach kids to code. Some of them use Python. They pick it up fairly quickly. I suspect they would have more trouble picking up (yet another version of) BASIC.
Indeed, there are lots of useful packages that you can use to help you do useful things in Python....ScriptBasic wrote: ↑Sun Apr 07, 2019 7:20 pmPython may only be 9 MB to load but start including packages to get it to do anything useful and the truth unfolds.
Couldn't agree more.Heater wrote: ↑Sun Apr 07, 2019 7:46 pmPerhaps we should not devolve into a language war here. That is a non-productive dead end.
All programming languages are terrible. Too slow, too big, too simple, too complex, terrible syntax and semantics, no standards, non-portable, etc, etc. (Delete item where appropriate for whatever language)
Let's focus on whatever good features a programming language may have to offer and where using them might be appropriate.
I now have ScriptBasic running on a Raspberry Pi Zero W. Here is the result computing the 24th Fibonacci number from the program posted earlier:
Code: Select all
$ time scriba sb.bas
46368
real 0m2.072s
user 0m2.018s
sys 0m0.000s
$ cat sb.bas
FUNCTION Fibonacci(n)
IF n <= 2 THEN
Fibonacci = 1
ELSE
Fibonacci = Fibonacci(n - 1) + Fibonacci(n - 2)
END IF
END FUNCTION
PRINT Fibonacci(24),"\n"
How do I run Visual Basic code?ScriptBasic wrote: ↑Sun Apr 07, 2019 7:29 pmThe COM extension module works with VB6. What other BASIC has that kind of syntax flexability?
THANK YOU!I now have ScriptBasic running on a Raspberry Pi Zero W. Here is the result computing the 24th Fibonacci number from the program posted earlier:
The ScriptBasic COM extension module is a CallByName OLE automation interface. The ScriptBasic IDE/Debugger is a VB6 app using the ScriptBasic embedded API and debugging pre-processor. I'm using the ext. module to interface with OCX forms I create in VB6 which calls back to ScriptBasic subs / functions. Check out the AllBasic.info forum for examples.ejolson wrote: ↑Sun Apr 07, 2019 9:32 pmHow do I run Visual Basic code?ScriptBasic wrote: ↑Sun Apr 07, 2019 7:29 pmThe COM extension module works with VB6. What other BASIC has that kind of syntax flexability?
No, the Fern post shows a time of 11.32 seconds.