LoginLogin

🅱️ode 🅱️ritique

Root / General / [.]

📌
YolkaiCreated:
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.
@_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
not familiar with _ as a parameter name or how its treated at a compile time.. but shouldnt some of the lines be
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.

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.
@_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
not familiar with _ as a parameter name or how its treated at a compile time.. but shouldnt some of the lines be
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.
I'm guessing _ means a generic variable with any use and name and is shorter to type than "input"

it's just a legal identifier that happens to look funny calm down

yeah, how would you like it if everyone would not stop talking about your name just because it has too many underscores in it?

it's just a legal identifier that happens to look funny calm down
Yes, in SB _ is just a valid identifier that doesn't actually mean anything special.
VAR _ = 10
PRINT _ '10
It 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 mismatch
The 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.

please review my code why it dont work exec "prg1:lib" main = IO() signal(main, print("hello")) run(main, 9696195221+λ)

please review my code why it dont work exec "prg1:lib" main = IO() signal(main, print("hello")) run(main, 9696195221+λ)
There's a missing semicolon

Hey try to fix this one:
DEF FAC(V1)
 VAR RET
 FOR I=V1 TO 1 STEP -1
  RET=RET*I
 NEXT
 RETURN RET
END
It'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 480
This is obviously a joke

Hey try to fix this one It's supposed to be a factorial function but it always returns 0
DEF FACK(IN)
 IF IN > 2 THEN
  RETURN IN * FACK(IN-1)
 ELSEIF IN < -1 THEN
  RETURN IN * FACK(IN+1)
 ELSE
  RETURN IN
 ENDIF
END
edit:ok fine i make good-er

Hey try to fix this one:
DEF FAC(V1)
 VAR RET
 FOR I=V1 TO 1 STEP -1
  RET=RET*I
 NEXT
 RETURN RET
END
The problem is that it isn't fast enough:
DEF FAC(V1)
  VAR RET=MAX(V1,1)
  FOR I=V1-1 TO 2 STEP -1
    RET=RET*I
  NEXT
  RETURN RET
END
This 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
END
Behavior 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.

DEF FACT N OUT F
 F=479001600
 FOR N=N+1 TO 12
  F=F DIV N
 NEXT
END
Runs in O(12-n)

This should do the trick, returns -1 if N>12 so you can figure out a workaround with that value
DEF FAC(N)
 IF N>1 THEN
  RETURN (N*FAC(N-1))*(N<13)+(-1*(N>12))
 ELSEIF N>0 THEN
  RETURN 1
 ENDIF
RETURN 0
END

From "C Struct Interpreter" @ STRING.LIB:
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
END
should be
COMMON DEF ISDIGIT(C$)
  RETURN C$>="0" && C$<":"
  ': in case C$ really is string
END
likewise,
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
should be
COMMON DEF ISLETTER(C$)
  RETURN (C$>="A"&&C$<"[") || (C$>="a"&&C$<"{")
END
Noting 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$
END
Noting 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...

DEF UPPER(S$)
 RETURN DIALOG(S$,"")
END

This is the worst code I've ever wrote. (view it with code wrap enabled) [QRF4D3V3] (key because I dnot have 3.6.0 to screenshot)

This is the worst code I've ever wrote (view it with code wrap enabled) [QRF4D3V3] (key because I dnot have 3.6.0)
You should use ACLS instead of CLS, just in case

This is the worst code I've ever wrote (view it with code wrap enabled) [QRF4D3V3] (key because I dnot have 3.6.0)
You should use ACLS instead of CLS, just in case
You're right, thanks much.

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 WEND

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 WEND
Uhh 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.

SNIP
Uhh 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.
I just mixed C, JavaScript, Ruby, Lua, LISP and SmileBASIC in one, horribly looking snippet lol