Author Topic: MY-BASIC  (Read 32442 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 1643
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #195 on: March 14, 2016, 01:41:47 AM »
It's a bug in Script BASIC I need to fix.

I have known about it for years.  ???

Offline wangrenxin

  • BASIC Developer
  • Posts: 88
Re: MY-BASIC
« Reply #196 on: March 17, 2016, 04:16:23 AM »
Hi,

I found a way to simulate SELECT CASE in MY-BASIC without adding new keywords. Implemented as a select function as follow, which accepts a variable argument list with a boolean expression, a lambda expression, another boolean expression, and another lambda... The advantage is it accepts not only one constant equivalence case condition, but also a boolean expression with more sub conditions for one case; the disadvantage is it requires a very ugly single line code calling the select function. Maybe it's necessary to add multi-line code linking to MB now, just like what the underline _ does in VB.

Code: MyBASIC
  1. default = true ' For the default case
  2. def select(...)
  3.         l = len(...)
  4.         if l mod 2 <> 0 then
  5.                 print "Parameters not matched.";
  6.                 return
  7.         endif
  8.         for i = 0 to l - 1 step 2
  9.                 if ... then ' Evaluates a condition
  10.                         _ = ... ' Gets a lambda and executes it
  11.                         _()
  12.                         return
  13.                 else
  14.                         _ = ... ' Ignores a lambda argument
  15.                 endif
  16.         next
  17. enddef
  18. a = 85
  19. select(a >= 85, lambda () (print "A";), a >= 75, lambda () (print "B";), a >= 60, lambda () (print "C";), default, lambda () (print "D";))
  20.  

Offline John

  • Forum Support / SB Dev
  • Posts: 1643
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #197 on: March 17, 2016, 09:11:19 PM »
Script BASIC doesn't have a SELECT/CASE structure either. It does have a flexible IF that works just as well. Actually better as it doesn't have the traditional CASE compare / range / type restrictions.

Code: Script BASIC
  1. a = 85
  2. IF a >= 85 THEN
  3.   PRINT "A\n"
  4. ELSE IF a >= 75 THEN
  5.   PRINT "B\n"
  6. ELSE IF a >= 60 THEN
  7.   PRINT "C\n"
  8. ELSE
  9.   PRINT "D\n"
  10. END IF
  11.  


jrs@laptop:~/sb/sb22/test$ scriba simcase.sb
A
jrs@laptop:~/sb/sb22/test$


Code: Script BASIC
  1. DECLARE SUB mb_init ALIAS "mbas_init" LIB "mb"
  2. DECLARE SUB mb_dispose ALIAS "mbas_dispose" LIB "mb"
  3. DECLARE SUB mb_open ALIAS "mbas_open" LIB "mb"
  4. DECLARE SUB mb_close ALIAS "mbas_close" LIB "mb"
  5. DECLARE SUB mb_load_str ALIAS "mbas_load_str" LIB "mb"
  6. DECLARE SUB mb_run ALIAS "mbas_run" LIB "mb"
  7.  
  8. mb_code = """
  9.    default = true ' For the default case
  10.    def select(...)
  11.            l = len(...)
  12.            if l mod 2 <> 0 then
  13.                    print "Parameters not matched.";
  14.                    return
  15.            endif
  16.            for i = 0 to l - 1 step 2
  17.                    if ... then ' Evaluates a condition
  18.                            _ = ... ' Gets a lambda and executes it
  19.                            _()
  20.                            return
  21.                    else
  22.                            _ = ... ' Ignores a lambda argument
  23.                    endif
  24.            next
  25.    enddef
  26.    a = 85
  27.    select(a >= 85, lambda () (print "A";), a >= 75, lambda () (print "B";), a >= 60, lambda () (print "C";), default, lambda () (print "D";))
  28. """
  29. mb_init()
  30. mb_open()
  31. mb_load_str(mb_code)
  32. mb_run()
  33. mb_close()
  34. mb_dispose()
  35.  


jrs@laptop:~/sb/sb22/mybasic$ scriba mbcase.sb
A
jrs@laptop:~/sb/sb22/mybasic$


« Last Edit: March 17, 2016, 11:35:04 PM by John »

Offline wangrenxin

  • BASIC Developer
  • Posts: 88
Re: MY-BASIC
« Reply #198 on: March 17, 2016, 11:49:22 PM »
It does have a flexible IF that works just as well. Actually better as it doesn't have the traditional CASE compare / range / type restrictions.

Yes, I can't agree more. IF has done it well.

John, does SB support separating a single statement into multi-lines? I'm a little bit refusing to add these features; but not quite sure.

Offline John

  • Forum Support / SB Dev
  • Posts: 1643
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #199 on: March 18, 2016, 12:45:33 AM »
Quote
does SB support separating a single statement into multi-lines?

Yes it does with the _ character.

Code: Script BASIC
  1. FUNCTION test (arg1, _
  2.                arg2, _
  3.                arg3)
  4.  

Offline wangrenxin

  • BASIC Developer
  • Posts: 88
Re: MY-BASIC
« Reply #200 on: April 22, 2016, 04:54:05 AM »
Finally, I added Unicode token support to MY-BASIC! For instance I can use Chinese variable now:

Code: MyBASIC
  1. &#21464;&#37327; = 22
  2. &#21478;&#19968;&#20010;&#21464;&#37327; = 7
  3. print &#21464;&#37327; / &#21478;&#19968;&#20010;&#21464;&#37327;;
  4.  

Offline wangrenxin

  • BASIC Developer
  • Posts: 88
Re: MY-BASIC
« Reply #201 on: April 22, 2016, 04:55:50 AM »
Finally, I added Unicode token support to MY-BASIC! For instance I can use Chinese variable now:

Code: MyBASIC
  1. &#21464;&#37327; = 22
  2. &#21478;&#19968;&#20010;&#21464;&#37327; = 7
  3. print &#21464;&#37327; / &#21478;&#19968;&#20010;&#21464;&#37327;;
  4.  

Well, I meant this:

Offline wangrenxin

  • BASIC Developer
  • Posts: 88
Re: MY-BASIC
« Reply #202 on: December 06, 2016, 07:28:57 AM »
Added an inline data sequence module, now it has a simple equivalent to retro DATA, READ, RESTORE statements :)

Offline John

  • Forum Support / SB Dev
  • Posts: 1643
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #203 on: December 08, 2016, 05:45:08 PM »
Great to see you still plugging away at the project. This is a nice enhancement for retro style BASIC compatibility.

Thanks for keeping us in the loop here on All BASIC.

Offline wangrenxin

  • BASIC Developer
  • Posts: 88
Re: MY-BASIC
« Reply #204 on: December 08, 2016, 06:52:37 PM »
Yep, more stuff to add, although the procedure is very slow ;D
BTW. it also supports REM statement now for comment.

Offline John

  • Forum Support / SB Dev
  • Posts: 1643
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #205 on: July 23, 2017, 01:04:23 PM »
I recompiled the My-BASIC extension module for Script BASIC and all seems to have went well. The only thing I had to do is add the extra true argument to the mb_run() function wrapper.

Can you give us an update where things are with My-BASIC?


Offline wangrenxin

  • BASIC Developer
  • Posts: 88
Re: MY-BASIC
« Reply #206 on: July 24, 2017, 04:53:45 AM »
Sure.

There are some minor bugfix, and some other major improvements for MY-BASIC since my last updating here.

   * Added support for applying `ITERATOR/MOVE_NEXT` and `FOR x IN y/NEXT` for collections, class and referenced usertype. https://github.com/paladin-t/my_basic/wiki/Use-iterators
   * Added support for using a non-referenced usertype larger than `sizeof(void*)`. https://github.com/paladin-t/my_basic/wiki/Use-usertype-values#structure
   * Added interpreter forking functions.
   * Added a structured exception handling ability with interpreter forking. https://github.com/paladin-t/my_basic/wiki/Structured-exception-handling
   * Added a multiple condition branching, which is implemented in MY-BASIC code. https://github.com/paladin-t/my_basic/wiki/Multiple-condition
   * Added support for defining an alias for the `LAMBDA` keyword, which is helpful to write neat code. https://github.com/paladin-t/my_basic/wiki/Lambda-abstraction

Recently I'm working on an App powered by MY-BASIC, which will allow users to write game or application in an IDE with modern BASIC syntax. It's aimed to be similar as PICO-8. I'll initially release it for desktop (Windows), still WIP, yet details and releasing date are TBD.

There are also few API changes, which are easy to figure out.

BTW. don't forget to share your use cases with us via https://github.com/paladin-t/my_basic/issues/13.