Implementation of the game Blackjack (21) in CLIPS
Run this from the command line with ./clips -f2 program.bat
like so:
$ ./clips -f2 program.bat
; Based on https://markushimmel.de/blog/my-first-verified-imperative-program/ | |
(defrule sum-is-0 | |
(list $? ?first $? ?second $?) | |
(test (= 0 (+ ?first ?second))) | |
=> | |
(println TRUE)) | |
(defrule sum-is-not-0 | |
(not (and | |
(list $? ?first $? ?second $?) |
(deftemplate MAIN::meta-fact | |
(slot meta-fact) | |
(slot name)) | |
(defrule MAIN::loop | |
?nil-meta-fact <- (meta-fact (meta-fact nil)) | |
?announce-meta-fact <- (meta-fact (name ?name)) | |
(not (meta-fact (meta-fact ?announce-meta-fact))) | |
=> | |
(println "Meta-fact: " ?name) |
(deffunction say_hello (?name) do | |
(format t "Hello, %s!" ?name)) |
Syntax highlighting is so-so for .clp
files. vim, my favorite code editor,
detects these filetypes as jess, an unmaintained Rules Engine with a similar syntax to CLIPS.
Adding the jess.vim
file to ~/.vim/after/syntax/
and the default.vim
file
to ~/.vim/colors
in your Ubuntu system
will provide slightly better highlighting when editing CLIPS files
{ | |
"Name": "Turbo Baker 9001", | |
"ID": "TurboBaker9001", | |
"Author": "ryjo", | |
"Description": "A mod that lets you bake any amount of cookies on demand! I made this. ryjo.", | |
"ModVersion": 1, | |
"GameVersion": 2.052, | |
"Date": "04/01/2024", | |
"Dependencies": [], | |
"Disabled": 0, |
I used this process to compile a WASM file for CLIPS. This allows me to run CLIPS in the browser! I use this for the Tour of CLIPS I created.
#include "clips.h" | |
#include <hiredis.h> | |
#include <signal.h> | |
#include <stdbool.h> | |
#include <stdlib.h> | |
void INThandler(int sig); | |
/****************************************/ | |
/* main: Starts execution of the expert */ |