Post Reply 
Sharp PC-G850VS
07-06-2022, 08:07 PM
Post: #168
RE: Sharp PC-G850VS
So for fun I've managed to write a Lisp interpreter in C for the Sharp PC-G850(V)(S).

[Image: lisp850.jpg]

The screen displays the "curry" function definition in Lisp, which applies one argument to a function to return a new function that takes the remaining arguments:

  > (define curry (lambda (f x) (lambda args (f x . args))))
  > ((curry + 1) 3)
  4


The interpreter compiles and runs on the PC-850(V)(S) itself, so the C source just needs to be copied to the machine via BLOAD then C(Text<-Basic) or via serial RS232.

The Lisp interpreter is only 87 lines long. An additional 44 lines of C implement 22 classic Lisp functions, specials and double precision arithmetic: eval, quote, cons, car, cdr, +, -, *, /, int, <, eq?, assoc, env, or, and, not, if, cond, let, lambda, define.

This Lisp interpreter supports lambda-closures with static scoping and global static scoping of defined functions to make recursion easy (like Scheme). This means that advanced Lisp examples work fine (perhaps with some tweaks). Like the Y combinator to apply anonymous recursive lambdas e.g. to compute factorial of 5 on the fly:

  > (define Y (lambda (f) (lambda args ((f (Y f)) . args))))
  > ((Y (lambda (f) (lambda (k) (if (< 0 k) (* k (f (- k 1))) 1)))) 5)
  120


The interpreter allocates 1024 cells of 8 bytes each to store pairs (cons), which is shared with a heap to store atom names. Cells are 8 bytes to store floating point values. This allocation should be big enough to run some practical Lisp code that does not need a lot of memory. Garbage collection is performed before the prompt returns to remove all temp lists of the last computation. The prompt shows the remaining number of free cells, e.g. 920 initially, since the 22 built-in functions take up some space.

I've done some hacking of the internals of floats to tag them as ATOM, PRIM, CONS, CLOS, and NIL so I can easily pass these Lisp expressions (as if they are floats) to the C functions of the interpreter for evaluation of atoms, primitives (such as lambda), lists and closures.

For one thing, it might prove that the PC-850(V)(S) C compiler is pretty capable. The C runtime is sufficiently robust, even when there is a lot of pointer stuff going on in the Lisp interpreter. And along the way I found some undocumented features in the C compiler/runtime of my PC-G850VS.

- Rob

"I count on old friends to remain rational"
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Sharp PC-G850VS - Zaphod - 04-16-2018, 08:49 AM
RE: Sharp PC-G850VS - grsbanks - 04-16-2018, 08:58 AM
RE: Sharp PC-G850VS - Zaphod - 04-16-2018, 10:26 AM
RE: Sharp PC-G850VS - andylithia - 04-16-2018, 12:26 PM
RE: Sharp PC-G850VS - mfleming - 04-16-2018, 02:16 PM
RE: Sharp PC-G850VS - Zaphod - 04-16-2018, 09:31 AM
RE: Sharp PC-G850VS - Helix - 04-16-2018, 02:33 PM
RE: Sharp PC-G850VS - mfleming - 04-16-2018, 06:39 PM
RE: Sharp PC-G850VS - Zaphod - 04-16-2018, 07:02 PM
RE: Sharp PC-G850VS - mfleming - 04-16-2018, 10:13 PM
RE: Sharp PC-G850VS - Zaphod - 04-23-2018, 09:57 PM
RE: Sharp PC-G850VS - mfleming - 04-24-2018, 03:37 AM
RE: Sharp PC-G850VS - Zaphod - 04-24-2018, 07:33 AM
RE: Sharp PC-G850VS - mfleming - 04-24-2018, 07:35 PM
RE: Sharp PC-G850VS - Zaphod - 04-24-2018, 07:54 PM
RE: Sharp PC-G850VS - Zaphod - 04-30-2018, 10:44 AM
RE: Sharp PC-G850VS - mfleming - 04-30-2018, 06:08 PM
RE: Sharp PC-G850VS - mfleming - 05-05-2018, 10:22 PM
RE: Sharp PC-G850VS - Zaphod - 05-02-2018, 10:48 AM
RE: Sharp PC-G850VS - mfleming - 05-02-2018, 03:46 PM
RE: Sharp PC-G850VS - Zaphod - 05-02-2018, 08:50 PM
RE: Sharp PC-G850VS - Helix - 05-02-2018, 10:44 PM
RE: Sharp PC-G850VS - Zaphod - 05-03-2018, 07:29 AM
RE: Sharp PC-G850VS - rprosperi - 05-03-2018, 12:56 PM
RE: Sharp PC-G850VS - Zaphod - 05-03-2018, 02:17 PM
RE: Sharp PC-G850VS - grsbanks - 05-03-2018, 02:19 PM
RE: Sharp PC-G850VS - Zaphod - 05-03-2018, 02:43 PM
RE: Sharp PC-G850VS - Zaphod - 05-03-2018, 04:14 PM
RE: Sharp PC-G850VS - Zaphod - 05-03-2018, 04:15 PM
RE: Sharp PC-G850VS - Zaphod - 05-03-2018, 04:17 PM
RE: Sharp PC-G850VS - Helix - 05-03-2018, 10:44 PM
RE: Sharp PC-G850VS - mfleming - 05-03-2018, 11:17 PM
RE: Sharp PC-G850VS - Helix - 05-04-2018, 12:49 AM
RE: Sharp PC-G850VS - rprosperi - 05-04-2018, 03:04 AM
RE: Sharp PC-G850VS - Zaphod - 05-04-2018, 05:31 AM
RE: Sharp PC-G850VS - Zaphod - 05-04-2018, 07:53 AM
RE: Sharp PC-G850VS - twdeckard - 05-06-2018, 08:18 PM
RE: Sharp PC-G850VS - mfleming - 05-06-2018, 08:49 PM
RE: Sharp PC-G850VS - jwhsu - 07-11-2018, 11:01 PM
RE: Sharp PC-G850VS - rprosperi - 07-11-2018, 11:17 PM
RE: Sharp PC-G850VS - foroplus - 07-12-2018, 09:17 AM
RE: Sharp PC-G850VS - toml_12953 - 08-19-2018, 12:53 AM
RE: Sharp PC-G850VS - smp - 08-19-2018, 01:28 AM
RE: Sharp PC-G850VS - toml_12953 - 08-20-2018, 03:23 AM
RE: Sharp PC-G850VS - Eddie W. Shore - 07-12-2018, 02:06 PM
RE: Sharp PC-G850VS - Helix - 07-12-2018, 02:44 PM
RE: Sharp PC-G850VS - jwhsu - 07-12-2018, 04:23 PM
RE: Sharp PC-G850VS - robve - 09-09-2020, 09:53 PM
RE: Sharp PC-G850VS - alainza - 08-05-2022, 08:41 PM
RE: Sharp PC-G850VS - mfleming - 07-12-2018, 01:51 AM
RE: Sharp PC-G850VS - jwhsu - 07-18-2018, 02:08 PM
RE: Sharp PC-G850VS - rprosperi - 07-19-2018, 01:35 AM
RE: Sharp PC-G850VS - jwhsu - 07-19-2018, 03:13 AM
RE: Sharp PC-G850VS - rprosperi - 07-19-2018, 03:24 AM
RE: Sharp PC-G850VS - SlideRule - 07-19-2018, 04:07 PM
RE: Sharp PC-G850VS - Zaphod - 07-20-2018, 08:36 AM
RE: Sharp PC-G850VS - Jlouis - 07-25-2018, 10:29 PM
RE: Sharp PC-G850VS - rprosperi - 07-25-2018, 10:36 PM
RE: Sharp PC-G850VS - Helix - 07-26-2018, 10:40 AM
RE: Sharp PC-G850VS - mfleming - 08-01-2018, 12:49 AM
RE: Sharp PC-G850VS - jwhsu - 08-01-2018, 09:42 PM
RE: Sharp PC-G850VS - jwhsu - 08-01-2018, 09:56 PM
RE: Sharp PC-G850VS - mfleming - 08-03-2018, 05:58 PM
RE: Sharp PC-G850VS - Zaphod - 08-05-2018, 08:33 PM
RE: Sharp PC-G850VS - jwhsu - 08-06-2018, 04:10 PM
RE: Sharp PC-G850VS - Jlouis - 08-06-2018, 11:55 PM
RE: Sharp PC-G850VS - Zaphod - 08-07-2018, 06:43 PM
RE: Sharp PC-G850VS - smp - 08-11-2018, 04:20 PM
RE: Sharp PC-G850VS - smp - 08-17-2018, 08:27 PM
RE: Sharp PC-G850VS - smp - 08-18-2018, 08:58 PM
RE: Sharp PC-G850VS - jwhsu - 08-20-2018, 12:21 PM
RE: Sharp PC-G850VS - rprosperi - 08-20-2018, 12:38 PM
RE: Sharp PC-G850VS - jwhsu - 08-20-2018, 12:52 PM
RE: Sharp PC-G850VS - rprosperi - 08-20-2018, 02:55 PM
RE: Sharp PC-G850VS - smp - 08-20-2018, 08:37 PM
RE: Sharp PC-G850VS - megarat - 08-24-2018, 10:12 PM
RE: Sharp PC-G850VS - toml_12953 - 09-05-2018, 12:56 PM
RE: Sharp PC-G850VS - xerxes - 09-06-2018, 09:47 AM
Sharp PC-G850VS STAT Mode - toml_12953 - 09-13-2018, 03:57 AM
RE: Sharp PC-G850VS - mfleming - 09-13-2018, 02:33 PM
RE: Sharp PC-G850VS - Zaphod - 09-13-2018, 04:34 PM
RE: Sharp PC-G850VS - rprosperi - 09-13-2018, 05:12 PM
RE: Sharp PC-G850VS - mfleming - 09-13-2018, 07:23 PM
RE: Sharp PC-G850VS - Zaphod - 09-13-2018, 08:36 PM
RE: Sharp PC-G850VS - brickviking - 09-13-2018, 09:59 PM
RE: Sharp PC-G850VS - Zaphod - 09-13-2018, 10:03 PM
RE: Sharp PC-G850VS - foroplus - 09-15-2018, 08:42 AM
RE: Sharp PC-G850VS - rprosperi - 09-15-2018, 12:59 PM
RE: Sharp PC-G850VS - foroplus - 09-15-2018, 01:10 PM
RE: Sharp PC-G850VS - jwhsu - 09-18-2018, 01:07 AM
RE: Sharp PC-G850VS - foroplus - 09-18-2018, 09:55 AM
RE: Sharp PC-G850VS - toml_12953 - 09-14-2018, 12:09 AM
RE: Sharp PC-G850VS - Zaphod - 09-14-2018, 10:44 AM
RE: Sharp PC-G850VS - jwhsu - 09-14-2018, 04:22 PM
RE: Sharp PC-G850VS - Zaphod - 09-14-2018, 05:26 PM
RE: Sharp PC-G850VS - toml_12953 - 09-21-2018, 05:18 PM
RE: Sharp PC-G850VS - jwhsu - 09-22-2018, 02:00 AM
RE: Sharp PC-G850VS - toml_12953 - 09-22-2018, 02:03 AM
RE: Sharp PC-G850VS - Zaphod - 09-13-2018, 08:47 PM
RE: Sharp PC-G850VS - Zaphod - 09-13-2018, 09:14 PM
RE: Sharp PC-G850VS - jwhsu - 09-18-2018, 10:58 PM
RE: Sharp PC-G850VS - rprosperi - 09-18-2018, 11:35 PM
RE: Sharp PC-G850VS - jwhsu - 09-18-2018, 11:42 PM
RE: Sharp PC-G850VS - mfleming - 09-19-2018, 01:02 AM
RE: Sharp PC-G850VS - jwhsu - 09-19-2018, 02:14 AM
RE: Sharp PC-G850VS - Zaphod - 09-21-2018, 05:34 PM
RE: Sharp PC-G850VS - Zaphod - 09-22-2018, 06:48 PM
RE: Sharp PC-G850VS - megarat - 10-01-2018, 02:25 AM
RE: Sharp PC-G850VS - Zaphod - 10-01-2018, 12:19 PM
RE: Sharp PC-G850VS - xerxes - 10-01-2018, 12:52 PM
RE: Sharp PC-G850VS - Jlouis - 10-24-2018, 07:40 PM
RE: Sharp PC-G850VS - koikoi - 08-21-2019, 11:38 PM
RE: Sharp PC-G850VS - Jlouis - 09-01-2019, 11:16 AM
RE: Sharp PC-G850VS - koikoi - 09-06-2019, 12:58 PM
RE: Sharp PC-G850VS - david16965 - 12-23-2019, 12:52 PM
RE: Sharp PC-G850VS - david16965 - 12-23-2019, 04:21 PM
RE: Sharp PC-G850VS - Luca Puntin - 03-07-2020, 03:38 AM
RE: Sharp PC-G850VS - mfleming - 03-07-2020, 03:58 PM
RE: Sharp PC-G850VS - Luca Puntin - 03-08-2020, 09:13 AM
RE: Sharp PC-G850VS - mfleming - 03-09-2020, 02:07 AM
PC G850 PIC programming - Luca Puntin - 03-09-2020, 01:59 PM
RE: Sharp PC-G850VS - thenozone - 03-19-2020, 12:24 AM
RE: Sharp PC-G850VS - Luca Puntin - 03-19-2020, 09:31 PM
RE: Sharp PC-G850VS - robve - 10-03-2020, 03:20 PM
RE: Sharp PC-G850VS - robve - 11-06-2020, 08:27 PM
RE: Sharp PC-G850VS - grsbanks - 12-09-2020, 07:03 PM
RE: Sharp PC-G850VS - grsbanks - 12-15-2020, 04:05 PM
RE: Sharp PC-G850VS - twdeckard - 12-16-2020, 02:03 AM
RE: Sharp PC-G850VS - grsbanks - 12-16-2020, 07:17 AM
RE: Sharp PC-G850VS - tommi60 - 12-16-2020, 08:23 AM
RE: Sharp PC-G850VS - toml_12953 - 12-17-2020, 04:32 AM
RE: Sharp PC-G850VS - Dave Britten - 12-17-2020, 06:23 PM
RE: Sharp PC-G850VS - twdeckard - 12-17-2020, 10:17 PM
RE: Sharp PC-G850VS - robve - 12-18-2020, 07:48 PM
RE: Sharp PC-G850VS - groskwik - 06-11-2021, 07:35 AM
RE: Sharp PC-G850VS - mfleming - 12-19-2020, 07:52 PM
RE: Sharp PC-G850VS - robve - 12-27-2020, 06:57 PM
RE: Sharp PC-G850VS - mfleming - 01-25-2021, 04:09 PM
RE: Sharp PC-G850VS - Eddie W. Shore - 02-22-2021, 12:26 AM
RE: Sharp PC-G850VS - robve - 02-22-2021, 02:17 AM
RE: Sharp PC-G850VS - robve - 02-22-2021, 09:28 PM
RE: Sharp PC-G850VS - rprosperi - 02-22-2021, 12:38 AM
RE: Sharp PC-G850VS - robve - 02-22-2021, 02:53 AM
RE: Sharp PC-G850VS - rprosperi - 02-22-2021, 10:29 PM
RE: Sharp PC-G850VS - robve - 02-23-2021, 04:03 AM
RE: Sharp PC-G850VS - silven - 06-03-2021, 05:30 PM
RE: Sharp PC-G850VS - robve - 06-06-2021, 07:45 PM
RE: Sharp PC-G850VS - silven - 06-07-2021, 05:00 PM
RE: Sharp PC-G850VS - robve - 06-07-2021, 09:30 PM
RE: Sharp PC-G850VS - silven - 06-16-2021, 11:26 PM
RE: Sharp PC-G850VS - Helix - 06-19-2021, 03:40 PM
RE: Sharp PC-G850VS - robve - 07-12-2021, 07:11 PM
RE: Sharp PC-G850VS - rprosperi - 06-08-2021, 12:37 PM
RE: Sharp PC-G850VS - robve - 06-08-2021, 05:18 PM
RE: Sharp PC-G850VS - rprosperi - 06-09-2021, 02:18 AM
RE: Sharp PC-G850VS - chrisherman - 02-01-2022, 01:37 PM
RE: Sharp PC-G850VS - robve - 02-02-2022, 02:00 AM
RE: Sharp PC-G850VS - Dave Britten - 02-02-2022, 03:01 AM
RE: Sharp PC-G850VS - chrisherman - 02-02-2022, 10:59 PM
RE: Sharp PC-G850VS - rprosperi - 02-02-2022, 01:22 PM
RE: Sharp PC-G850VS - OS1 - 04-11-2022, 08:32 PM
RE: Sharp PC-G850VS - robve - 04-12-2022, 02:07 AM
RE: Sharp PC-G850VS - OS1 - 04-12-2022, 07:34 PM
RE: Sharp PC-G850VS - robve - 04-12-2022, 08:09 PM
RE: Sharp PC-G850VS - toml_12953 - 04-14-2022, 04:47 AM
RE: Sharp PC-G850VS - rprosperi - 04-14-2022, 12:36 PM
RE: Sharp PC-G850VS - toml_12953 - 04-14-2022, 05:57 PM
RE: Sharp PC-G850VS - toml_12953 - 06-29-2022, 08:30 AM
RE: Sharp PC-G850VS - robve - 07-06-2022 08:07 PM
RE: Sharp PC-G850VS - EdS2 - 07-07-2022, 07:05 AM
RE: Sharp PC-G850VS - robve - 07-07-2022, 02:56 PM
RE: Sharp PC-G850VS - toml_12953 - 07-07-2022, 05:12 PM
RE: Sharp PC-G850VS - robve - 07-14-2022, 11:29 PM
RE: Sharp PC-G850VS - robve - 11-11-2022, 01:18 AM
RE: Sharp PC-G850VS - fleseriutiberiu - 01-25-2023, 03:18 PM
RE: Sharp PC-G850VS - robve - 02-14-2023, 02:42 AM
RE: Sharp PC-G850VS - Bushcat - 03-02-2023, 09:50 AM
RE: Sharp PC-G850VS - mfny - 05-03-2023, 04:19 PM
RE: Sharp PC-G850VS - Helix - 05-06-2023, 01:05 AM
RE: Sharp PC-G850VS - mfny - 05-08-2023, 01:05 PM
RE: Sharp PC-G850VS - Bushcat - 05-10-2023, 01:08 PM
RE: Sharp PC-G850VS - Helix - 05-09-2023, 05:35 PM
RE: Sharp PC-G850VS - toml_12953 - 05-10-2023, 03:30 AM
RE: Sharp PC-G850VS - Helix - 05-10-2023, 01:01 PM
RE: Sharp PC-G850VS - dmh - 01-23-2024, 05:16 AM
RE: Sharp PC-G850VS - DOBM - 07-27-2024, 07:31 PM
RE: Sharp PC-G850VS - RPNerd - 07-28-2024, 05:53 AM



User(s) browsing this thread: 9 Guest(s)