Jump to content
IGNORED

LISP Programming (homebrew WIP)


Dave C

Recommended Posts

UPDATE 2023-07-16: Play the game on Javatari.org, and check out the latest code on GitHub!

I've been on a bit of a side quest with this WIP... This is the first public alpha, very interested in feedback. I have tested on Stella and Javatari - there are definitely graphical glitches...

This WIP is from an alternate reality.

  • where a computer language from 1960 
  • is hastily crammed onto a ROM cartridge in 1977
  • so you can learn to write programs of the type you find in the first chapter of a textbook published in 1984.

 

It is not a competitor to Basic Programming but I am definitely trying to think in terms of the feature set and capture the spirit of a "programming game".

 

Some screenshots...

lisp_NTSC_5.png.155176ca9224a4b48d0ce1ea2f820ed3.pnglisp_NTSC_20230714.png.790fbc7655fa6079bc5cbbbf3b6f3c0d.pnglisp_NTSC_2.png.fa34cdecc3c703888cb5f5c413a38f29.png
Some concept art courtesy of DALL-E mini because why not...

lisp-programming1.thumb.png.f95d25a26b4b3aa87967e329c76bc6c2.png
Instructions

 

Probably some explanations are needed.

 

The basics:

  • The main screen is the REPL (read-eval-print-loop). It is preloaded with an expression (+ 1 2) represented as a boxy array of cells.
  • Moving the joystick up to EVAL and pressing the fire button will evaluate the expression and you will see the result
  • Pressing the fire button on the +, 1, or 2 cells lets you change the function and the arguments being applied.
  • Pressing the fire button on the ∴ lets you extend the expression (note (+ 1 2 3) will *ignore* the 3 right now)
  • Pressing the fire button to select the +, -, *, / ... symbols will start a subexpression
    • Note when you create a subexpression (or make a list longer than 5 entries)  the display will shift to display the containing expression vertically
  • The 0...9 symbols can be used for small numbers, if you press the # symbol you can input any number up to 999
     

The fun (as in functional) part:

  • If you move up to "EVAL" and press right you will cycle through various function definitions that can be called from EVAL...
  • Functions can be named anything you want! As long as the name is one character long and is either a λ,Lamedh, or this funky looking f
    • I hope you get the picture: there are no strings and there are 3 bytes reserved for pointers to functions. You want more? Source code forthcoming, feel free...
  • Arguments to functions can be anything you want! As long as the first argument is a, the second is b...
  • For maximum fun I've loaded a few predefined functions 
    • λ: starts as (* a a) - if you EVAL (λ 5) you will get 25
    • Lamedh: takes one argument (a) and calls the funky f...
    • funky f: this is the fibonacci function, which is a recursively defined function f(n) = f(n-1) + f(n - 2)...
      • ... to be specific this is the tail recursive variant - and - if you've read this far and see where we're going - yes this LISP has some super simple tail recursion optimization (otherwise we'd blow up the stack very quickly)

 

Some known issues

  • since I preloaded a bunch of functions - there actually isn't a lot of room left for editing new programs unless you wipe the predefined functions
  • The REPL will attempt to stop you from blowing up the heap writing programs but I'm sure there are holes
  • The EVAL will attempt to detect stack overflow before you overwrite critical RAM, but it's not a flawless check
  • Really complex expressions can take too long to "parse" for display and that will mess with vblank...
  • Division function not implemented
    • thinking about it...
  • No lambda, cons... 
    • thinking about it...


Implementation TLDR:
 

Borrowing from PicoLisp, the only data structure is a 2 byte cell that represents either a pair or a number. Evaluator based heavily on Chez Scheme, and I'm looking at uLisp and Basic Programming for ideas for sample programs and games...

 

lisp_NTSC_20230714.bin lisp_PAL60_20230714.bin

  • Like 17
  • Thanks 1
Link to comment
Share on other sites

Thanks for checking it out!
 

5 hours ago, JetSetIlly said:

what is the correct form if I want to use the result of "+ 1 2" to multiply by 3?

So the steps to get there look something like this:

lisp_NTSC_9.png.361a914c1c977a1f488ba5ddb89be529.png  -> lisp_NTSC_10.png.c34280a4a8b61a6906bf436ffb642417.png ->lisp_NTSC_11.png.d8606cd2e88e749144e65709f7d00a3f.png -> lisp_NTSC_12.png.9a8dc18ff2975234e6203a2a06c3b7bd.png -> lisp_NTSC_13.png.a500cf4fc1ee3a614782cea0a7bb4392.png
Basically, in prefix notation this would look like (* 3 (+ 1 2)) but the editor has no way to say "insert (* 3 in front of (+ 1 2)" - so instead you have to rewrite everything by changing the + to *, the 1 to a 3, the 2 to + ... at which point the editor starts a subexpression and starts a new line.. and so eventually you can get there.

 

  • Like 1
Link to comment
Share on other sites

2 hours ago, utz said:

This is completely and utterly insane. I love it.

That is exactly the reaction I was hoping to elicit.

Evaluation is radically simplified by not having closures, lambda breaks that assumption. Looking for a good target program for cons. I'd really like some kind of search. It just has to be able to stay inside the 32 cell heap limit...

Before I can move forward on any of that I probably have to reorganize the display and editing kernels. I feel obliged to stay inside 4K, and they take tons of space and are overall ridiculously hairy.

  • Like 1
Link to comment
Share on other sites

14 hours ago, waynel said:

 

I envision some awesome overlays for the BASIC Programming keypads. 

 

So important question:is it disappointing if I don’t plan to have keyboard support? the code currently is hard wired for joystick only -  I thought it would be more accessible for users that are used to joystick / don’t have them (myself included). But not sure it’s feasible to evolve it to the point where you can just pick up and play without some reading, and maybe the keyboard would be just as easy to use?

Link to comment
Share on other sites

7 hours ago, Mr SQL said:

 

How much RAM is available for the tiny LISP program?

You can have a program of up to 32 cells - each cell is 2 bytes and is either a number (3 digit BCD) or a pair (aka a cons cell). It's just enough to express the fibonacci program with a little to spare.

For comparison,

  • the IBM 704 (where LISP was first implemented) apparently had 18kb of magnetic core memory (4096 36-bit words) and 36kb of magnetic drum. And cost something like $2MM dollars and required maintenance every 8 hours.
  • I've recently become aware of SectorLisp, which implements LISP in 436 bytes of an IBM PC boot sector. So depending on how the 8088 instruction set compares to the 6502 I might have some opportunities to do better on ROM - if you take away display, the evaluator + basic functionality part of VCS Lisp code clocks in at 640 bytes (348 bytes for the evaluator, 292 for math functions, etc).


I'm thinking about a few mini games to try and round things out:

  •  towers of hanoi 
  •  tweetmaze
  • Mastermind?
  • some way to create graphics (since BASIC programming had a way to program a primitive paddle game feel like I should check the box on that)
  • something with sound (since BASIC programming let you play notes). The current version does have a "note" function that will play a sound.

 


 

  • Like 2
Link to comment
Share on other sites

10 hours ago, Dave C said:

You can have a program of up to 32 cells - each cell is 2 bytes and is either a number (3 digit BCD) or a pair (aka a cons cell). It's just enough to express the fibonacci program with a little to spare.

For comparison,

  • the IBM 704 (where LISP was first implemented) apparently had 18kb of magnetic core memory (4096 36-bit words) and 36kb of magnetic drum. And cost something like $2MM dollars and required maintenance every 8 hours.
  • I've recently become aware of SectorLisp, which implements LISP in 436 bytes of an IBM PC boot sector. So depending on how the 8088 instruction set compares to the 6502 I might have some opportunities to do better on ROM - if you take away display, the evaluator + basic functionality part of VCS Lisp code clocks in at 640 bytes (348 bytes for the evaluator, 292 for math functions, etc).


I'm thinking about a few mini games to try and round things out:

  •  towers of hanoi 
  •  tweetmaze
  • Mastermind?
  • some way to create graphics (since BASIC programming had a way to program a primitive paddle game feel like I should check the box on that)
  • something with sound (since BASIC programming let you play notes). The current version does have a "note" function that will play a sound.

 


 

 

Very cool that's enough for interesting tiny programs, comparable to the 63 bytes of RAM available to BASIC Programming.

 

Check out this algorithm that became a ring tone.

 

LISP would be great for mathematical music, I wonder what the Fibonacci algorithm would sound like using the note function.

 

 

Link to comment
Share on other sites

  • 2 weeks later...
On 7/23/2023 at 2:44 PM, Dave C said:

So important question:is it disappointing if I don’t plan to have keyboard support? the code currently is hard wired for joystick only -  I thought it would be more accessible for users that are used to joystick / don’t have them (myself included). But not sure it’s feasible to evolve it to the point where you can just pick up and play without some reading, and maybe the keyboard would be just as easy to use?

It's not disappointing at all.  It's your project, you do what you want.  And while I believe you are correct in thinking that more people have joysticks than keypad controllers, I think that the people who would even know what LISP is would probably have some around somewhere.

 

I think you should continue on your current trajectory, and if in the future you feel like making a version with keypad support, that would be great.  It would be a fun challenge for someone like me to design appropriate overlays.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...