I'm guessing _ means a generic variable with any use and name and is shorter to type than "input"The constant death march toward modernization is a dangerous effort to optimize the future at the cost of our past. I propose a countermethod, instead adopting the styles of assembly; you can see there is a kind of beautiful clarity in the bones of the machine, in full view as the onion skins are pullled away.not familiar with _ as a parameter name or how its treated at a compile time.. but shouldnt some of the lines be@_ENTRY MOV SP$,@HELLO GOSUB @PUTSTR PUTCHR 10 'LINE ENDING END @PUTSTR POPB A IF EQU(A,0) THEN RETURN PUTCHR A GOTO @PUTSTR @HELLO DATA "Hello, world!",0 DEF MOV _,L RESTORE L READ SP$ SP$=SP$+CHR$(0) END DEF POPB _ A=ASC(SHIFT(SP$)) END DEF EQU(A,B) RETURN A==B END DEF PUTCHR V PRINT CHR$(V); ENDREAD _ _=_ + CHR$(0) ... _=ASC(SHIFT(SP$))POPB dedicated to popping from sp$...like stack pointer string pointer.. in that case mov doesnt need SP$ as a parameter. Wouldnt thT be more like loadsp or some flavor.
🅱️ode 🅱️ritique
The constant death march toward modernization is a dangerous effort to optimize the future at the cost of our past. I propose a countermethod, instead adopting the styles of assembly; you can see there is a kind of beautiful clarity in the bones of the machine, in full view as the onion skins are pullled away.not familiar with _ as a parameter name or how its treated at a compile time.. but shouldnt some of the lines be@_ENTRY MOV SP$,@HELLO GOSUB @PUTSTR PUTCHR 10 'LINE ENDING END @PUTSTR POPB A IF EQU(A,0) THEN RETURN PUTCHR A GOTO @PUTSTR @HELLO DATA "Hello, world!",0 DEF MOV _,L RESTORE L READ SP$ SP$=SP$+CHR$(0) END DEF POPB _ A=ASC(SHIFT(SP$)) END DEF EQU(A,B) RETURN A==B END DEF PUTCHR V PRINT CHR$(V); END
READ _ _=_ + CHR$(0) ... _=ASC(SHIFT(SP$))POPB dedicated to popping from sp$...like stack pointer string pointer.. in that case mov doesnt need SP$ as a parameter. Wouldnt thT be more like loadsp or some flavor.
it's just a legal identifier that happens to look funny calm downYes, in SB _ is just a valid identifier that doesn't actually mean anything special.
VAR _ = 10 PRINT _ '10It looks a bit weird in the given code, I suspect, because I'm passing a string to an identifier without a $ on it. But in SB, function params aren't typed until there's a value passed to them (or, params take the type of the value passed to them.)
DEF PLEN V PRINT LEN(V) END PLEN "ABC" '3 PLEN 123 'runtime type mismatchThe type mismatch error in this code doesn't come from the fact that we're calling PLEN with an int, it comes from the fact that PLEN tries to call LEN with an int. Now stop talking about it. Also please be aware that you are on a joke thread and the code posted was supposed to look like bad assembly.
Hey try to fix this one:
DEF FAC(V1) VAR RET FOR I=V1 TO 1 STEP -1 RET=RET*I NEXT RETURN RET ENDIt's supposed to be a factorial function but it always returns 0 I actually fixed this but in the chat people wanted me to put this here, so don't judge I also have a loading screen, but it doesn't seem to load anything.
CLS ?"Loading sprites" WAIT 480This is obviously a joke
Hey try to fix this one:The problem is that it isn't fast enough:DEF FAC(V1) VAR RET FOR I=V1 TO 1 STEP -1 RET=RET*I NEXT RETURN RET END
DEF FAC(V1) VAR RET=MAX(V1,1) FOR I=V1-1 TO 2 STEP -1 RET=RET*I NEXT RETURN RET ENDThis drops like, 2 redundant iterations. Except that the factorial of any inputs > 12 won't even fit in an int32 (and is defined only for nonnegative integers), so we can implement it as a lookup table with little space overhead instead.
@SEQ_FACT DATA 1,1,2,6,24,120,720,5040,40320,362880,3628800,479001600 DIM FACT_TBL[0] COPY FACT_TBL,@SEQ_FACT DEF FASTFACT(N) IF N>=0 && N<12 THEN RETURN FACT_TBL[N] RETURN 0 ENDBehavior for unsafe inputs isn't well defined, so you might want to STOP instead of returning -1 or 0 or something... FACT_TBL[n] can be indexed directly when you don't even need the safety check.
From "C Struct Interpreter" @ STRING.LIB:
should be
COMMON DEF ISDIGIT (A$) FOR I = 0 TO LEN(A$) - 1 IF ASC(A$[I]) >= 48 AND ASC(A$[I]) <= 57 THEN RETURN TRUE ELSE RETURN FALSE ENDIF NEXT I ENDshould be
COMMON DEF ISDIGIT(C$) RETURN C$>="0" && C$<":" ': in case C$ really is string ENDlikewise,
ISLETTER
COMMON DEF ISLETTER (A$) FOR I = 0 TO LEN(A$) - 1 IF ASC(A$[I]) >= 65 AND ASC(A$[I]) <= 90 THEN RETURN TRUE ELSEIF ASC(A$[I]) >= 97 AND ASC(A$[I]) <= 122 THEN RETURN TRUE ELSE RETURN FALSE ENDIF NEXT I END
COMMON DEF ISLETTER(C$) RETURN (C$>="A"&&C$<"[") || (C$>="a"&&C$<"{") ENDNoting that: 1) string comparisons are valid in SB 2) the FOR loops reek of copy/paste code smell, only first char will be checked 3) basic ASCII comparisons can benefit from boolean zen 4) AND/OR are bitwise operators; logical &&/|| versions are preferred here Another:
COMMON DEF UPPER (A$) T$ = "" FOR I = 0 TO LEN(A$) - 1 IF ASC(A$[I]) >= 97 AND ASC(A$[I]) <= 122 THEN N = ASC(A$[I]): N = N - 32 T$ = T$ + CHR$(N) ELSE T$ = T$ + A$[I] ENDIF NEXT I RETURN T$ END
COMMON DEF UPPER(A$) VAR T$=A$*1 'clone A$ VAR N FOR I=LEN(A$)-1 TO 0 STEP -1 'iterate backwards N=ASC(T$[I]) IF N>=97 && N<=122 THEN T$[I]=CHR$(N-32) NEXT RETURN T$ ENDNoting that: 1) every string concatenation may allocate a new string, which the IF/ELSE *guarantees* to risk for every character in A$. Allocating T$ with the correct length initially avoids this, but we can do better... 2) if we clone A$ (are we not allowed to edit destructively, anyway?) into T$ then we don't even need to modify characters outside of the lowercase range: they're already there 3) everything involving the comparison is so redundant... three guaranteed string subscript and ASC() calls every iteration, subtracting in another statement for no reason, doing the CHR$() in another operation...
AAA why me game dnot wor?k int PLAUYER% WHILE 1 { console.log(FORMAT$("%d",math.random(10))); SPVAR PLAUYER%,1 (SETQ A (+1 A)) puts A unless A%2 WENDUhh you kinda went WHILE 1{ WEND instead of WHILE 1{ } or WHILE 1 WEND I'm only judging this off of what I've seen people do in other languages, I don't actually know how the {} thing works.