Commit Graph

528 Commits

Author SHA1 Message Date
sforman 6674fdffb6 Better exceptions. 2023-08-28 20:46:19 -07:00
sforman a107e1df6c Rebuilt C interpreter. 2023-08-21 09:53:24 -07:00
sforman 8dfcbca2a8 README for Chicken Scheme. 2023-08-20 10:24:29 -07:00
sforman 5edf0797b4 sort 2023-08-18 17:09:08 -07:00
sforman 20b517f083 Figlet headings. 2023-08-18 16:59:32 -07:00
sforman 307a421fab Add definition for xor. 2023-08-16 10:05:30 -07:00
sforman 60bddcc70e cleanup 2023-08-13 08:49:20 -07:00
sforman 9f78b6d8fd Messing around with type inference.
What if we insist that both branches of a branch have compatible types?

For one thing `[+] [* +] branch` leads to a circular term which, when
printed, goes into a loop: "int,int,int,...".  Hmm...
2023-08-12 16:45:59 -07:00
sforman 48e443c5c7 for-each 2023-08-12 14:09:44 -07:00
sforman 596a7a21eb A crude main loop.
I know there are better ways to do this, but I don't know what they are
yet.  Maybe a "do" loop?  Anyway, this works, although it doesn't catch
errors yet.
2023-08-12 13:03:42 -07:00
sforman 8bbbd2a4a4 Update defs.scm 2023-08-12 08:26:59 -07:00
sforman 00f4bfcacd Math ops, definitions for left- and right-shift. 2023-08-12 08:04:21 -07:00
sforman 99f01bec1f mul div mod add sub in Nim 2023-08-12 07:54:33 -07:00
sforman f45c739fad first rest 2023-08-11 23:02:46 -07:00
sforman 1a37a8e81c concat cons comparison 2023-08-11 22:48:25 -07:00
sforman 8df8634e39 loop 2023-08-11 21:27:41 -07:00
sforman 172407fef1 branch and refactor simple functions.
The refactor should be a macro but I don't know how to write those yet
(apparently there are different macros systems...  ooo la la!)
2023-08-11 21:15:26 -07:00
sforman 4d6d66e391 dip 2023-08-11 20:49:24 -07:00
sforman c3e6c1be90 i 2023-08-11 20:45:25 -07:00
sforman ae7d854330 swap 2023-08-11 20:38:01 -07:00
sforman 9fbb7c05c3 pop 2023-08-11 20:34:40 -07:00
sforman b921a9e3d2 stack, swaack 2023-08-11 11:11:51 -07:00
sforman 5f8e33ff8d Add copyleft notice. 2023-08-11 11:03:00 -07:00
sforman 3382d0a47e Load defs at compile time.
I don't really know the proper way to do this, but I managed to whump
something up.
2023-08-11 10:48:33 -07:00
sforman 8fab04b02e Evaluate definitions. 2023-08-11 10:31:53 -07:00
sforman 67b60be123 Convert defs.txt to defs.scm.
Gonna need a makefile.
2023-08-11 10:15:31 -07:00
sforman d014709a32 Load defs from defs.txt.
They are loaded at runtime though :(  shouldn't be too hard to fix that?
2023-08-11 08:50:00 -07:00
sforman b6c3c364d0 A start on dictionaries using srfi-69 hash tables. 2023-08-10 21:49:37 -07:00
sforman 19777a86ae Use '->' in names of functions that convert values. 2023-08-10 21:48:46 -07:00
sforman 1bad1508f1 dup 2023-08-10 21:47:54 -07:00
sforman a56a3939c1 minor edit 2023-08-10 21:46:56 -07:00
sforman a15ea2d355 It's more efficient to concat the empty list
than to concate a non-empty list onto the empty list.
2023-08-10 21:45:40 -07:00
sforman 7c9663594b A start on simple functions.
I'm sure there's a cooler way to do this, but it works.  (This is my
first Scheme code.)
2023-08-04 10:38:52 -07:00
sforman 8cc15a745f Parser emits errors; joy 2023-08-04 09:52:09 -07:00
sforman ea60a04d96 joy-expression-to-string 2023-08-04 08:14:45 -07:00
sforman 35ffe71482 text-to-expression 2023-08-04 07:47:12 -07:00
sforman dedbb0115f It's Joy.
Or will be soon.
2023-08-04 07:43:05 -07:00
sforman 0503dc2fbe Parser. 2023-08-04 00:33:11 -07:00
sforman 0122c4f249 Scheme, eh? 2023-08-03 11:28:46 -07:00
sforman 97602ade8d SWIProlog can't not emit '.'.
I would like the GNU Prolog and SWI Prolog versions to be compatible, if
possible.

SWI has bigints, GNU doesn't, so that's a wrinkle...
2023-08-02 22:38:04 -07:00
sforman ee4c3bc9b6 Thread the dict through the interaction loop.
Like a total newbie I put the call to the interpreter in the view
function instead of the update function!  I thought it was weird having
to specify the HTML twice, but I figured I was just doing it wrong.  I
was, but not in the way I suspected.

In any event, I like how this make it clear that errors can't affect the
dictionary.
2023-08-02 21:19:43 -07:00
sforman 2fe886afba Checked old defs.
I forgot `over`!
2023-08-02 19:37:36 -07:00
sforman 5585ae5d31 _isnt_bool _isnt_two_bools
These probably won't last?
2023-08-02 09:06:11 -07:00
sforman f15eef1c56 minor edits 2023-07-31 12:08:39 -07:00
sforman 45f00c8f2e Elm README.
And minor edits.
2023-07-31 11:30:12 -07:00
sforman 540bdd97bd Sort out the and/or/... ops. 2023-07-30 15:51:29 -07:00
sforman c0fa319c9c Crude type checking.
I forget why I was doing "not not" so I made it a little more clear.  In
practice this is regressive:  The built-in "isnt_bool" function should
be in the dictionary?  Or prohibit type checking and let the bugs flow?
Rely on inference to prevent bugs that would pass the non-checking
versions of the functions?  Hmm...
2023-07-30 15:42:55 -07:00
sforman 373666bf39 Name Boolean ops.
So they don't overshadow the defs for the short-circuiting combinators.
2023-07-30 15:41:58 -07:00
sforman 1089ab7c24 Error type (not just a string.)
This is mostly for fun, but I bet it comes in handy, eh?

At the very least, it's a nice catalog of the possible errors that the
basic Joy system might encounter.
2023-07-30 14:59:09 -07:00
sforman 850bc3a500 type alias JoyFunction 2023-07-30 14:27:27 -07:00
sforman 64d9bb75a4 Format. 2023-07-30 07:47:26 -07:00
sforman 9963a73322 inscribe, definitions. 2023-07-30 07:45:06 -07:00
sforman 200c390fd5 Initialize dict with defs.
Just sqr for now, but it shows that it works.

I would like to return Results from add_def but it makes using foldl
slightly tricky,  not a lot, just slightly, and my brainpower is low at
the mo'.
2023-07-29 17:10:45 -07:00
sforman edfd7c526f Look up words in the dictionary.
If they are not built-in, which means you can't "shadow" built-ins with
"inscribe", which may or may not turn out to be what we want?
2023-07-29 12:35:47 -07:00
sforman 4acdec71ed Thread the dictionary through the call stack. 2023-07-29 12:30:22 -07:00
sforman 4d6230e01d Empty string is not an unknown word. 2023-07-29 12:11:43 -07:00
sforman 9220361871 Gotta keep a Dict around. 2023-07-29 12:09:08 -07:00
sforman b1d4c3c5b8 Logical ops. 2023-07-29 11:37:07 -07:00
sforman 2c9d5cf4bf Left- and Right-shift. 2023-07-29 11:32:22 -07:00
sforman a69b988684 Comparison ops. 2023-07-29 11:07:50 -07:00
sforman 36dc5b619f loop 2023-07-29 10:44:51 -07:00
sforman 8fb48008cd branch 2023-07-29 10:38:12 -07:00
sforman ed8f8f9edf dip 2023-07-29 10:28:31 -07:00
sforman 9c381f0e8f i 2023-07-29 10:23:06 -07:00
sforman 99a5fd93b1 truthy
I have to check into this: the Python version has "bool" and no
"truthy".
2023-07-29 10:19:39 -07:00
sforman 7c9ea764ea swap 2023-07-29 10:09:40 -07:00
sforman fcdf916013 stack, swaack 2023-07-29 10:00:16 -07:00
sforman c50f2a7541 pop 2023-07-29 09:55:28 -07:00
sforman 4a0fce2492 first, rest 2023-07-29 09:53:00 -07:00
sforman b50be3b64b dup 2023-07-29 09:22:26 -07:00
sforman eb8b282bc2 cons 2023-07-29 09:17:27 -07:00
sforman 70c5223319 clear, concat 2023-07-29 09:06:14 -07:00
sforman af882e2be4 Minor cleanup. 2023-07-29 08:57:58 -07:00
sforman e9f971460f Type alias JList 2023-07-29 08:49:31 -07:00
sforman 9917a2cfba Refactor pop_int.
I don't like passing the stack through isnt_int but that let's you chain
with andThen.

There's probably a clever or idiomatic way to not do that and couple the
stack to the result without passing it through the type checker function
but I don't know what it is right now, and this works.
2023-07-29 07:51:31 -07:00
sforman b6b3acf350 Binary Math Ops 2023-07-29 07:32:56 -07:00
sforman dc065d1943 I don't think andThen helps here? 2023-07-29 07:19:08 -07:00
sforman 48f6e78196 I can add integers! 2023-07-29 06:54:15 -07:00
sforman 5315edbe83 Parsing working.
Modeled on the OCaml code.
2023-07-28 21:51:34 -07:00
sforman 9d57545533 A start on Joy types. 2023-07-28 15:04:35 -07:00
sforman 590a5b207c In Elm. 2023-07-28 14:18:12 -07:00
sforman 23504f6ede Use Python as SHELL in Makefile.
It's a simple task, but I'm not up on my CLI tools, so I went with
Python instead of sh.  The split command doesn't have '-p' switch on
Ubuntu.  (I'm using Ubuntu on this laptop because it can correctly
configure the WiFi and the laptop has no ethernet port.)
2023-07-27 10:32:45 -07:00
sforman 08262ac861 minor cleanup 2023-07-27 09:55:02 -07:00
sforman ef504aa1c4 Rename joy_to_ast to parser. 2023-07-27 09:19:12 -07:00
sforman 3f9f558ebb the BinInt zero vanished? 2023-07-25 22:01:55 -07:00
sforman ced691279a Working on README, put defs in joy.py
I'm on an Ubuntu system right now and the split command doesn't have the
'-p' switch.  :(   I wasn't happy with that janky solution anyway.
2023-07-25 21:13:35 -07:00
sforman 975924f632 minor edits 2023-07-25 20:03:11 -07:00
sforman 18b5d5b497 Minor edits. 2023-07-25 10:04:45 -07:00
sforman f2688e311f Messing around with GNU Prolog.
I have it broken up into three stages: a parser that reads a string from
stdin and emits (Prolog) AST to stdout; an interpreter of sorts that
reads AST from stdin, evaluates it, and then emits the AST of the stack
on stdout; and a printer that reads AST on stdin and prints Joy-ish code
to stdout.

I say Joy-ish because currently math is not evaluated and results of
math appear as expressions, not values.

This is because GNU Prolog doesn't have unbounded integers (it's numbers
are machine integers) so literals that are larger than the machine word
are converted into atoms!  To keep things simple, I made all ints into
atoms, but then you can't evaluate them: '1'+'2' is not '3' (it might be
'12' though.)

So I print them out at expressions:

    $ echo "1 2 3 4 [+ sub /] i" | ./joy_to_ast | ./thun | ./printer

    (1 div (2-(4+3)))

You could almost feed that to, say, Python to evaluate, eh? Or dc with
proper formatting?  (man dc; "Desk Calculator".)

Anyway, it's a start.  The Prolog interpreter is more for things like
type checking and inference, optimizing, compiling, etc.  Symbolic stuff
that's a PITA to express in other languages.  (The old type inference
code in Python was pages long, in Prolog it's just the thun/3 & thun/4
predicates themselves.  At least so far.  There are things we will want
to do eventually that might be a PITA to express in Prolog, eh?
2023-07-25 08:51:27 -07:00
sforman a34a2b1aab Compile on Ubuntu. 2023-07-24 11:29:39 -07:00
sforman 0fa617766f Make it compatible with Xerblin. 2023-07-24 11:29:06 -07:00
sforman 7cd5943d89 Minor edits. 2023-07-24 11:28:45 -07:00
Simon Forman f844dbab6c Minor cleanup. 2023-03-22 14:45:54 -07:00
Simon Forman 23d6fe727e i combinator.
On a lark I implemented it in recursive style, but I'm not going to keep
it that way.  I have to implement next_term() first and then I'll
uncomment i_joy_combinator().
2023-03-22 11:54:17 -07:00
Simon Forman 34798b7f33 concat 2023-03-22 08:41:09 -07:00
Simon Forman e83745e6ec cons 2023-03-21 12:34:28 -07:00
Simon Forman f8016a84e3 minor cleanup 2023-03-21 09:38:50 -07:00
Simon Forman 2841e53d4d first 2023-03-21 09:33:20 -07:00
Simon Forman f2fe704ba6 rest 2023-03-21 09:27:00 -07:00
Simon Forman 8986b8c619 rest CANNOT_TAKE_REST_OF_EMPTY_LIST 2023-03-21 09:19:12 -07:00