Author Topic: Shorthand Basic  (Read 18431 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Shorthand Basic
« Reply #30 on: February 14, 2021, 01:46:19 pm »
Yeah I've seen your Lisp and checked it out some on Internet, who doesn't like simple systems!

My first foray into an Eval was so very Lisp like (at time I didn't know anything about Lisp nor Lambda Calculus, luv to banter those fancy names though right or wrong), my observation relearned again over weekend is that it is not easy to read what those coded lines are doing and it's a struggle to experiment with and debug, though probably learn decent thinking skills, try using verbs at the start of your sentences for awhile.

Now I forgot where I was going with this, man! almost 2PM time for lunch, that's where I am going...

Oh p$ the program string is sucked in thus:

(drag drop, Command$)
Open existingFilename.txt$ for Binary as #1
p$ = space$(lof(1))
get #1, p$
close #1

There's your input string.

What you do with that is your business. Or hey, in from _clipboard
p$ = _Clipboard$  ' notice the structure subject verb object there's your function name on one side and your formula on the other. =(p$, _clipboard$) not so easy to understand, perhaps I am another ruined coder from Basic experience.

IDE code
ReDim Shared NL$
NL$ = Chr$(10) ' you don't need the 13
p$ = "first program line"
[
p$ = p$ + NL$ + "Next line"
? Are we there yet.
i yeah
   x
f
]
. Ready to proceed with p$.

Out to lunch...
« Last Edit: February 14, 2021, 02:02:12 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Shorthand Basic
« Reply #31 on: February 15, 2021, 04:58:45 pm »
@STx

Oh piss!

I get it now, you not only want a p$ in but you want a p$ out, to where? well that's on a need to know basis, just get the stuff in string form and p?ss it on, maybe to a file, maybe to the _clipboard, maybe mail it to Liza, maybe to the Recycle Bin through a filter.

You don't care about any shows in-between?

Well there goes my, "Infinite Pong the Movie.txt" ;(


Yeah so that will be awhile, I like show business.

Plus I am finding errors and bugs and aggravations and vexations: right and left here and there, just in frick'n test 1 from previous Interpreter Test #3 for SB1.
Fix Trimming variable names
Fix special ' ' if want to not Ltrim spaces between arguments
Found, not, broken in Eval, such a simple what? Function? not exactly more a pain in the nut
Oh! I know how I can fix that now, just go to Poland again! that will work easy without messing with Eval.

To piss strings, that's nothing. LOL

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Shorthand Basic
« Reply #32 on: February 15, 2021, 05:13:26 pm »
I remember with my math evaluator, NOT Is a PITA to sort.  If we're talking order of operations, it's a conditional OOO symbol.  It processes FOREMOST on the priority list with anything to the left of it, but low to anything to the right of it, except other binary operators.

Best trick I remember finding was to wrap parentheses internally where NOT appeared.

3 + NOT 4 + 3

Now, where does that NOT process? 

If you add parentheses,it makes sense as:

3 + (NOT 4 + 3)



If that explanation helps any.  It's NOT the easiest operator to describe order of operations of.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Shorthand Basic
« Reply #33 on: February 15, 2021, 06:37:49 pm »
For descent or is it ascent or decent?

I have it the very last in order of processing, everything else must be done before it gets handled (on the level it's at inside parenthesis).

I want to treat it like a simple function NOT(X)
If X = 0 then NOT = -1 Else NOT = 0 ' > what could possibly go wrong?!

So simple, you would think. Just like at Doctor's today, trying to explain why we don't get BP's regularly for my mother. He thinks it's a simple thing. I thought it would be a simple thing but ... well no words describe the dynamic that goes on (I recently watched Young Sheldon's Thanksgiving vacation Episode.) Dynamic same word base as dynamite!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Shorthand Basic
« Reply #34 on: February 15, 2021, 07:19:23 pm »
Recalling my problem in Eval,  it was taking -1 and turning it to - 1 (subtraction) and wasn't finding anything to subtract 1 from, kind of a funny joke.

I thought I had all my problems with - sign resolved. No, one more when a string starts with a -number.
« Last Edit: February 15, 2021, 07:23:53 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Shorthand Basic
« Reply #35 on: February 15, 2021, 07:32:29 pm »
FUNCTION KNOT (X AS LONG)
    KNOT = - (X + 1)
END FUNCTION

There's a basic function for it, as long as it's integers.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Shorthand Basic
« Reply #36 on: February 15, 2021, 07:37:48 pm »
Ah that's interesting! Gotta try it.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Shorthand Basic
« Reply #37 on: February 15, 2021, 07:50:09 pm »
No I think I just have to sneak in a 0 to have something to subtract from.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Shorthand Basic
« Reply #38 on: February 16, 2021, 11:18:15 pm »
New jump command, if expression evaluates to true, jump out of the loop.
Before you could only exit a loop from inside an if block

i condition 'IF condition
   x 'exit
f 'end if

3 lines

now,
jump condition, exits to outside loop

Code: [Select]
' Test 3 new j for jump command for SB1.txt b+ 2021-02-16
LoopCount = 0
[
LoopCount = LoopCount + 1
j LoopCount > 14
k = 0
[
; *;
' oh dang this is bad i need i for indexes back to If for that command!
k = k + 1
' dang I cant use k = LoopCount but >= works!
j k >= LoopCount
]
.
]
.  And we are out of the loop and done with this test with 14 lines of stars?

 
Jump demo.PNG


Also realized it a mistake to use single letter commands specially i for IF

« Last Edit: February 16, 2021, 11:19:42 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Shorthand Basic
« Reply #39 on: February 18, 2021, 02:17:30 am »
Testing some cool new commands for SB1:
Code: [Select]
' Test 4 Arithmetics.txt b+ 2021-02-17
a = 1 
b = 2
c = 3
d = 4
e = 5
' yeah when I get to arrays...
f = e + a
g = e + b
h = e + c
i = e + d
j = e * 2

.  a = ;a;/  b = ;b;/  c = ;c;/  d = ;d;/  e = ;e;/ f = ;f;/  g = ;g;/  h = ;h;/  i = ;i;/  j = ;j
+ result;a;b;c;d;e;f;g;h;i;j
. a + b +... + j = ;result
* result;a;b;c;d;e;f;g;h;i;j
. a * b *... * j = ;result
& result;a;b;c;d;e;f;g;h;i;j
. a & b &... & j = ;result

a = 7
. a = ;a
+= a;3.3
. a += 3.3 is ;a
-= a;3.3
. a -= 3.3 is ;a
*= a;3.3
. a *= 3.3 is ;a
/= a;3.3
. a /= 3.3 is ;a

 
Test 4 some new Arith commands.PNG


Such commands might save on some typing.
a = a + 10
a += 10

a = 1 + 6 + 7 - 3
+ a;1;6;7;-3

& for String Concatenate.

Also am rid all single letter commands, here is a peak at the program shown earlier in this thread, 2 letter If Block commands:
Code: [Select]
'Test 6 the New ei command.txt b+ 2021-02-12 ei AKA ElseIf

' name change update If, It, Io, Ix
' may be read: If,  If True, If Otherwise, If eXit

.      Let's examine the common factors of some numbers:
[
? num; (Enter only will end Run) Please enter a number to test >
If num < 2
Exit
Io
If num % 2 = 0
. /   ;             num; is Even.
It num % 3 = 0
. /   ;num            ; is Triple.
It num % 5 = 0
. /   ; num; is Pentacle.
It num % 7 = 0
. /   ;   num  ; is Septacle.
Io
remaining = 1 - 1/2 - 1/6 - 1/30 - 1/210
. /   ;The probability of ; num; not having a First Factor of 2, 3, 4, 5 or 7 is ; remaining;.
Ix
.
Ix
]
.
.     Thanks for playing.

« Last Edit: February 18, 2021, 02:57:27 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Shorthand Basic
« Reply #40 on: February 22, 2021, 05:20:26 pm »
Update on test 3 with revisions to SB1:
Code: [Select]
' Test 3 new j for jump command for SB1.txt b+ 2021-02-16 mod 2-21
[
+= loopCount;1
Jmp loopCount > 14
k = 0
[
; *;
+= k;1
Jmp k = LoopCount
]
.
]
.  And we are out of the loop and done with this test with 14 lines of stars?


Here is Simple Prime Sieve using new Set and Get:
Code: [Select]
' Test ad Simple Prime Sieve.txt rev from SB.exe 2018-09-14 adopted from:
' Simple sieve 2.bas SmallBASIC 2015-04-29 found a faster sieve with BASIC 256
topN = 1000
limit = topN ^ .5
. Primes to ;topN
' take care of even numbers first
' prime the pump
[
+= i;1
Jmp i > topN
Set 0; i; composites
]
i = 4
[
Set 2; i; composites
+= i;2
Jmp i > topN
]
' now do odd numbers
i = 3
[
Get test; i; composites
If test = 0
If i < limit
j = 2 * i
[
Set i; j; composites
+= j;i
Jmp j > topN
]
Fi
Fi
i = i + 2
Jmp i > limit
]
i = 2
pCount = 0
[
Get test; i; composites
If test = 0
+= pCount;1
, i
Fi
+= i;1
Jmp i > topN
]
.
.
. / There are ;pCount;/ primes for the first ; topN;/ integers.


Here is one that was a tough nut to crack but found interesting problem with Execution Flow when a Loop ends ] just before an EI (ElseIF) or  EL (Else) when flow is supposed to jump to FI (End If AKA Final If line sB uses that, its IF in reverse, I thought clever)

The Monkey Problem a tough nut to crack:
Code: [Select]
' Test ab ...and 1 for the monkey.txt rev for SB.exe convert 2021-02-20
' from ... and 1 for the monkey problem.bas for JB 2.0 b 2018-02-11
' Completely rewritten 2021-02-21.

People = 5
nutStart = 100
[
. /          ... and one for the Monkey
.
. / There are 5 people and 1 monkey on an island.
. / Yesterday the amount of coconuts they collect is ; nutStart
' track nut inventory with:
nutsNow = nutStart
. / Last night, each person goes to the pile, takes a fith
. / gives 1 coconut to the monkey and hides the remaining.
. /  (No coconuts are cut into parts in this problem.)
.
p = 0
monkey = 0
nutsNow = nutStart
[
+= p;1
Jmp p > People
fith = Int( nutsNow / People )
If fith >= 1
-= nutsNow; fith
+= monkey; 1
-= fith;1
Fi
+= fith;0
set fith; p; piles
. / For person ;p;/ their pile is ; fith; coconut(s).
]
. / So the remaining coconuts after last night is ;nutsNow
. /                        ... and the monkey has ;monkey
.
. / This morning, they give the monkey a coconut and divide
. / the remaining pile by number of people, what is the size
. / of everyone's pile?
.
. / Coconuts starting today is ; nutsNow
If nutsNow > 0
monkey = monkey + 1
nutsNow = nutsNow -1
Fi
fith = int( nutsNow / People )
. / So each person gets ; fith;/ more coconuts.
p = 0
[
+= p;1
Jmp p > People
Get curr; p; piles
total = curr + fith
. / Person ;p; had hidden ;curr; and gets ;fith; so has ; total
-= nutsNow; fith
]
. / The monkey has ; monkey;/ coconuts.
. / There remains ; nutsNow; nuts for this author.
.
-= NutStart; 10
If nutStart > 0
loc 34; 5
. ZZZ... press any to see day with 10 less coconuts to start
Zzz
Cls
El
Exit
Fi
]
. /            Good bye!
End


So SB1 rewrite almost caught up to SB, better with ElseIf equaivalent but 200 lines more, programMap took about 100 so there is no searching for the place to go next while running and using split for everything so there is no running down a string over and over looking for delimiter #x, so overall should be faster performance.

Would like string function system added for this version to have significant update.
SB1 Prime Sieve.PNG
* SB1 Prime Sieve.PNG (Filesize: 22.24 KB, Dimensions: 1028x446, Views: 188)
SB1 Monkey Problem.PNG
* SB1 Monkey Problem.PNG (Filesize: 24.97 KB, Dimensions: 715x598, Views: 178)
« Last Edit: February 22, 2021, 05:28:47 pm by bplus »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Shorthand Basic
« Reply #41 on: February 22, 2021, 11:46:26 pm »
@bplus

Quote
a = a + 10
a += 10

what about a = 10 + a

a = 10 +  ??

The complier might think a variable is missing.
« Last Edit: February 22, 2021, 11:47:55 pm by NOVARSEG »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Shorthand Basic
« Reply #42 on: February 22, 2021, 11:56:57 pm »
If you are advising:

a += 10

looks better than

+= a;10

which is what I have working now in my Interpreter built from QB64.

I agree, I will put on my ToDo List to change.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Shorthand Basic
« Reply #43 on: February 23, 2021, 12:25:33 am »

a$ = a$ + z$ is not the same as  a$ = z$ + a$

but

a = a + b  is the same as a = b + a

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Shorthand Basic
« Reply #44 on: February 23, 2021, 12:47:41 am »
Ah! Now I see what you're getting at, the strings are converted to number with VAL() the instant they are to be used as number.

String Concatenation will use & symbol.