fanoush
Posts: 508
Joined: Mon Feb 27, 2012 2:37 pm

Re: ScriptBasic

Sun Apr 14, 2019 5:55 pm

hippy wrote:
Sun Apr 14, 2019 8:41 am

Code: Select all

  running = running - 1
I wonder how safe is this without any locks.With right timing all threads may finish and yet the running value can be 2.

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Sun Apr 14, 2019 5:58 pm

You're in luck as the MT extension module provides both R/W lock functions with shared variables among threads.

It also provides in memory session support but that is normally used with the ScriptBasic HTTPD application server.

hippy
Posts: 6862
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: ScriptBasic

Sun Apr 14, 2019 6:57 pm

fanoush wrote:
Sun Apr 14, 2019 5:55 pm
hippy wrote:
Sun Apr 14, 2019 8:41 am

Code: Select all

  running = running - 1
I wonder how safe is this without any locks.With right timing all threads may finish and yet the running value can be 2.
AIUI that's what the GIL ( Global Interpreter Lock ) is for. That's a part of most Python interpreters, working under the hood to keeps things like that safe, allowing Python programmers to not worry over such things, and one of the things which can be argued to make Python better or easier to use than other languages.

Of course; there's also some criticism of Python having a GIL.

fanoush
Posts: 508
Joined: Mon Feb 27, 2012 2:37 pm

Re: ScriptBasic

Sun Apr 14, 2019 7:26 pm

hippy wrote:
Sun Apr 14, 2019 6:57 pm
AIUI that's what the GIL ( Global Interpreter Lock ) is for.
I am not sure. So what is unit of execution in python when this lock is held?
I would expect such lock would solve atomicity of assignment, i.e. if you do
x=1, x=256 from two threads then x would hold one value or another and not e.g 257. However x=x+1 is not atomic, it is assignment and expression, all three threads can compute expression and then all could do assignment resulting in computing and assigning same value of 2 (each having x locked when reading or writing it).
EDIT:
This seems to confirm my opinion
https://docs.python.org/2/faq/library.h ... hread-safe
i=i+1
see also http://blog.qqrs.us/blog/2016/05/01/whi ... re-atomic/ which explains that unit of execution is one bytecode, not e.g. whole expression or line

hippy
Posts: 6862
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: ScriptBasic

Sun Apr 14, 2019 8:08 pm

fanoush wrote:
Sun Apr 14, 2019 7:26 pm
hippy wrote:
Sun Apr 14, 2019 6:57 pm
AIUI that's what the GIL ( Global Interpreter Lock ) is for.
I am not sure.
You could well be right. I just threw that together. I'd do it properly if I ever needed to do something like that in production code, check each thread had ended, but couldn't be bothered looking up the documentation :D

hippy
Posts: 6862
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: ScriptBasic

Sun Apr 14, 2019 8:09 pm

Finally figured how to make 'wget' get the right .deb files for download and installation on the Pi. Works for me but E&OE -

Code: Select all

cd ~
wget -o scriptbasic-2.1-linux-armhf.deb "https://www.scriptbasic.org/forum/index.php?action=dlattach;topic=359.0;attach=421"
sudo apt install ./scriptbasic-2.1-linux-armhf.deb

Code: Select all

cd ~
wget -o scriptbasic-rpi-zero.deb "https://www.scriptbasic.org/forum/index.php?action=dlattach;topic=359.0;attach=435"
sudo apt install ./scriptbasic-rpi-zero.deb

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Sun Apr 14, 2019 8:15 pm

Good point!

Not all RPi users are using the desktop and some users are headless running ssh.

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Sun Apr 14, 2019 8:23 pm

hippy wrote:
Sun Apr 14, 2019 8:08 pm
fanoush wrote:
Sun Apr 14, 2019 7:26 pm
hippy wrote:
Sun Apr 14, 2019 6:57 pm
AIUI that's what the GIL ( Global Interpreter Lock ) is for.
I am not sure.
You could well be right. I just threw that together. I'd do it properly if I ever needed to do something like that in production code, check each thread had ended, but couldn't be bothered looking up the documentation :D
Each ScriptBasic thread is it's own session of scriba and basic.conf.This goes beyond the module isolation within a thread.

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Sun Apr 14, 2019 10:59 pm

The two features I LIKE most about ScriptBasic is its text processing and array (matrix) flexability. Not having to declare / DIM anything or specify type is a plus.

hippy
Posts: 6862
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: ScriptBasic

Mon Apr 15, 2019 5:38 pm

How do I identify what the error is in this program ... ?

Code: Select all

' based on https://www.nayuki.io/res/fast-fibonacci-algorithms/fastfibonacci.py

function Lhs_Fibonacci(n)
  if n <> 0 then
    a = Lhs_Fibonacci(n >> 1)
    b = Rhs_Fibonacci(n >> 1)
    if ( n & 1 ) <> 0 then
      Lhs_Fibonacci = a * a + b * b
    else
      Lhs_Fibonacci = a * (b + b - a)
    end if
  else
    Lhs_Fibonacci = 0
  end if
end function

function Rhs_Fibonacci(n)
  if n <> 0 then
    a = Lhs_Fibonacci(n >> 1)
    b = Rhs_Fibonacci(n >> 1)
    d = a * a + b * b
    if ( n & 1 ) <> 0 then
      Rhs_Fibonacci = a * (b + b - a) + d
    else
      Rhs_Fibonacci = d
    end if
  else
    Rhs_Fibonacci = 1
  end if
end function

function Fibonacci(n)
  Fibonacci = Lhs_Fibonacci(n)
end Function

print Fibonacci(24)

Code: Select all

[email protected]:~/dummy $ scriba fibo.sb
(0): error &H1c:Command is not implemented and no currently loaded extension module defined behaviour for it

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Mon Apr 15, 2019 11:34 pm

ScriptBasic is complaining about you using a reserved / unimplemented operator. >>

ScriptBasic doesn't support bit shifting natively. The & symbol is for concatenation not an AND bit shift like Python. Here is a function that might help get your version of Fibonacci going.

Code: Select all

function shifts(v,p,ar)
  local bp,ba,co,cq,bi,x,y,d
  bp=1
  x=0xffffffff and v
  for co=0 to 31
    ba[co]=0
  next
  for co=0 to 31
    bi=x and bp
    cq=co+p
    if (bi<>0) then
      if ((cq>=0)and(cq<32)) then
        ba[cq]=1
      end if
    end if
    bp = bp + bp
  next
  bp=1
  y=0
  '
  'SUPPORT FOR ARITHMETIC RIGHT SHIFTS
  '
  d=100
  if (ar) then
    if (x and 0x80000000) then 
      d=31+p
    end if
  end if
  '
  for co=0 to 31
   if ((ba[co]<>0)or(co>=d)) then
      y=y or bp
    end if
    bp = bp + bp
  next
  shifts=y
end function


PRINT shifts(0x80000000,2),"\n"
PRINT shifts(-32,-2,1),"\n"
PRINT shifts(8,-2),"\n"

Heater
Posts: 14775
Joined: Tue Jul 17, 2012 3:02 pm

Re: ScriptBasic

Tue Apr 16, 2019 12:10 am

Wouldn't a simple divide by 2 do for an arithmetic right shift :

Lhs_Fibonacci(n / 2)
Memory in C++ is a leaky abstraction .

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Tue Apr 16, 2019 1:08 am

hippy wrote:
Sun Apr 14, 2019 6:57 pm
fanoush wrote:
Sun Apr 14, 2019 5:55 pm
hippy wrote:
Sun Apr 14, 2019 8:41 am

Code: Select all

  running = running - 1
I wonder how safe is this without any locks.With right timing all threads may finish and yet the running value can be 2.
AIUI that's what the GIL ( Global Interpreter Lock ) is for. That's a part of most Python interpreters, working under the hood to keeps things like that safe, allowing Python programmers to not worry over such things, and one of the things which can be argued to make Python better or easier to use than other languages.

Of course; there's also some criticism of Python having a GIL.
Numba is an open-source NumPy-aware optimizing compiler for Python sponsored by Anaconda, Inc and a grant from the Gordon and Betty Moore Foundation. It uses the LLVM compiler infrastructure to compile Python to CPU and GPU machine code.
Is that the default run mode?

The article links that were posted on this topic were eye opening. What stuck out to me is that Python creates a VM and each thread runs one at a time, not ascychronously like ScriptBasic. My guess is ScriptBasic is using multiple cores to run its threads where Python is a contained (VM) process.
Last edited by John_Spikowski on Tue Apr 16, 2019 1:21 am, edited 1 time in total.

hippy
Posts: 6862
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: ScriptBasic

Tue Apr 16, 2019 1:17 am

ScriptBasic wrote:
Mon Apr 15, 2019 11:34 pm
ScriptBasic is complaining about you using a reserved / unimplemented operator. >>
I know. I found it by commenting every line out and iteratively adding lines back in. That wouldn't have worked though on anything more substantial.

My point is, if I'd written however many thousands of lines of ScriptBasic code, run it and had got that error, how would I know where I'd accidentally fallen into a Pythonic idiom which compiled but didn't work in ScriptBasic ?

I could search those however many thousands of lines of code and probably not be able to see where I'd used a construct which I thought was right but wasn't.

Reporting what is no better than "didn't work" doesn't help solve the problem. It's like searching for something in a haystack without even knowing what one's looking for.

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Tue Apr 16, 2019 1:26 am

My default debugger once the script passes syntax validation is ...

Code: Select all

PRINT "Got Here\n"
The ScriptBasic User Guide would have told you what are the valid operators for the language. Much easier than searching through the developer documentation or the source.

RTFM

ejolson
Posts: 4506
Joined: Tue Mar 18, 2014 11:47 am

Re: ScriptBasic

Tue Apr 16, 2019 2:56 am

hippy wrote:
Mon Apr 15, 2019 5:38 pm

Code: Select all

[email protected]:~/dummy $ scriba fibo.sb
(0): error &H1c:Command is not implemented and no currently loaded extension module defined behaviour for it
Would it be possible for the parser to report on what line it encountered the error?

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Tue Apr 16, 2019 3:19 am

It's hit and miss if a line number is returned. :|'

I'm not sure why.

It seems really bad syntax errors don't deserve a line number where they live.

Try leaving off a quote from a string or a closing parenthese and a line number will be.returned with the error message.
Last edited by John_Spikowski on Tue Apr 16, 2019 4:28 am, edited 1 time in total.

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Tue Apr 16, 2019 4:12 am

With ScriptBasic you can enable reserved keywords via an extension module. The hint was in the error message you recieved.

User avatar
scruss
Posts: 2910
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: ScriptBasic

Tue Apr 16, 2019 1:56 pm

ScriptBasic wrote:
Tue Apr 16, 2019 1:26 am
My default debugger once the script passes syntax validation is ...

Code: Select all

PRINT "Got Here\n"
Oh dear — shotgun debugging is pretty much a last resort. While I'm not really a fan of Python's fulsome error verbiage, it never leaves you in any doubt what went wrong and (roughly) where.
The ScriptBasic User Guide would have told you what are the valid operators for the language. Much easier than searching through the developer documentation or the source.

RTFM
Umm, maybe don't attack people who want to learn your language? Getting all fighty over an error might not be the best way to grow your language's popularity — think MINASWAN instead. It would have been as easy to put in a link to your manual (easier still if you used a browser extension such as Format Link) as kvetch about it.

Regarding the user guide, which one is it?
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Heater
Posts: 14775
Joined: Tue Jul 17, 2012 3:02 pm

Re: ScriptBasic

Tue Apr 16, 2019 2:25 pm

scruss,

I had never heard of MINASWAN before. Nice.

I'm into POLA. Princple of Least Astonishment: https://en.wikipedia.org/wiki/Principle ... tonishment

POLA is usually used wrt user interfaces. But programming languages are the user interface between a programmer and the computer. Ergo, try not to surprise them. Operators should do what they normally do in mathematics, logic and common programming languages, there is no need for them to be different. Using a common syntax helps, even if your language semantics has uncommon features.

When it comes to POLA, error messages seem to be the hardest part of a language/compiler/runtime system. I'm not sure if anyone has that right yet...

As for RTFM. Good luck with that. I have spent some hours recently trying to become familiar with Smalltalk, the documentation is no help what so ever.
Memory in C++ is a leaky abstraction .

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Tue Apr 16, 2019 2:54 pm

I appreciate you taking a leadership role here on the forum with ScriptBasic. The wiki is the best documentation resource at the moment. The PDF User Guide is for convenience.

This is an open source project and not John's BASIC.

I'm sure that someone with your skill level will find getting up to speed with ScriptBasic intuitive.
Oh dear — shotgun debugging is pretty much a last resort.
The Windows version of ScriptBasic has a great GUI IDE / Debugger. If you get stuck on the RPi, use the Windows version to debug your code.

I can usually pull out of a 'tailspin' in 2 or less PRINT "Got Here\n"'s. 8-)

User avatar
RichardRussell
Posts: 620
Joined: Thu Jun 21, 2012 10:48 am

Re: ScriptBasic

Tue Apr 16, 2019 3:25 pm

ScriptBasic wrote:
Tue Apr 16, 2019 2:54 pm
The Windows version of ScriptBasic has a great GUI IDE / Debugger. If you get stuck on the RPi, use the Windows version to debug your code.
I don't know if this is a practical solution with ScriptBasic, but the BBC BASIC for SDL 2.0 IDE/debugger is itself written in BBC BASIC, ensuring that every (desktop) platform that can run the interpreter can run the IDE/debugger as well, with an identical look-and-feel in each case.

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Tue Apr 16, 2019 3:37 pm

ScriptBasic has a console interactive debugger. I will create a thread on the RaspberryBASIC.org forum showig how to use it. It also let's you remotely debug your web based SB scripts. (socket connection between the debugger and the Script being debugged)

hippy
Posts: 6862
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: ScriptBasic

Tue Apr 16, 2019 4:55 pm

ScriptBasic wrote:
Tue Apr 16, 2019 1:26 am
My default debugger once the script passes syntax validation is ...

Code: Select all

PRINT "Got Here\n"
Which seems a shame when it could have printed the line number and given more details of what the error was. Rather than "(0): error &H1c:Command is not implemented and no currently loaded extension module defined behaviour for it" what I would have expected was something like - "fibo.sb:5: No extension module included which supports '>>' operator".

Maybe I've been spoiled by languages which report in which lines run-time errors have occurred.
ScriptBasic wrote:
Tue Apr 16, 2019 1:26 am
The ScriptBasic User Guide would have told you what are the valid operators for the language. Much easier than searching through the developer documentation or the source.
But it is a valid operator - or it would not have compiled successfully. The actual problem is it's an operator which isn't natively implemented and I provided no implementation for it.
ScriptBasic wrote:
Tue Apr 16, 2019 1:26 am
RTFM
The problem is not so much having not read the manual or knowing what's valid or not, but having been careless in switching between languages. There's knowing the language and trying to find where one has subconsciously strayed from what it should have been. No amount of knowing a language can prevent that.

I did find a list of all the operators which aren't natively implemented, but I'll be buggered if I can find it now.

I fully accept that this was my error. The issue is how quickly and easily I can sort out my error, how well ScriptBasic aids me in doing. That affects where I think it sits against other languages and its appropriateness for use in particular roles or tasks.
ScriptBasic wrote:
Tue Apr 16, 2019 3:19 am
It's hit and miss if a line number is returned. :|'

I'm not sure why.
As far as I can tell it provides a line number for compilation errors but not for runtime errors.

The nodes which make up the object code don't seem to include any reference to source code file or line number, nor the operator it's trying to execute, so when something fails the execution engine cannot report anything much better than "something failed".
ScriptBasic wrote:
Tue Apr 16, 2019 2:54 pm
The Windows version of ScriptBasic has a great GUI IDE / Debugger. If you get stuck on the RPi, use the Windows version to debug your code.
I'm not sure that's a great advert for something you are hoping could become a widely used development tool for the Pi.

And I'm not sure it's that great anyway. It only identified where my >> error was when stepping through the code a line at a time. Let it run and it didn't help identify where the problem is any better than the Pi version.

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Tue Apr 16, 2019 5:13 pm

I posted an example of the remote console debugger on the https://RaspberryBASIC.org forum.

On a side note, BASIC has many variations to chose from. With Python it's one size fits all.
Last edited by John_Spikowski on Tue Apr 16, 2019 5:29 pm, edited 1 time in total.

Return to “Other programming languages”